refactor: application dependency management (#2363)

This commit is contained in:
Mo
2023-07-23 15:54:31 -05:00
committed by GitHub
parent e698b1c990
commit a77535456c
299 changed files with 7415 additions and 4890 deletions

View File

@@ -1,20 +1,20 @@
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
import { PayloadManagerInterface } from './../Payloads/PayloadManagerInterface'
import { StorageServiceInterface } from './../Storage/StorageServiceInterface'
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
import { StatusServiceInterface } from './../Status/StatusServiceInterface'
import { FilesBackupService } from './BackupService'
import { EncryptionProviderInterface } from './../Encryption/EncryptionProviderInterface'
import { LegacyApiServiceInterface } from '../Api/LegacyApiServiceInterface'
import { HistoryServiceInterface } from '../History/HistoryServiceInterface'
import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { StorageServiceInterface } from '../Storage/StorageServiceInterface'
import { SessionsClientInterface } from '../Session/SessionsClientInterface'
import { StatusServiceInterface } from '../Status/StatusServiceInterface'
import { FilesBackupService } from './FilesBackupService'
import { PureCryptoInterface, StreamEncryptor } from '@standardnotes/sncrypto-common'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
import { InternalEventBusInterface } from '..'
import { AlertService } from '../Alert/AlertService'
import { ApiServiceInterface } from '../Api/ApiServiceInterface'
import { SyncServiceInterface } from '../Sync/SyncServiceInterface'
import { DirectoryManagerInterface, FileBackupsDevice } from '@standardnotes/files'
describe('backup service', () => {
let apiService: ApiServiceInterface
let apiService: LegacyApiServiceInterface
let itemManager: ItemManagerInterface
let syncService: SyncServiceInterface
let alertService: AlertService
@@ -30,7 +30,7 @@ describe('backup service', () => {
let history: HistoryServiceInterface
beforeEach(() => {
apiService = {} as jest.Mocked<ApiServiceInterface>
apiService = {} as jest.Mocked<LegacyApiServiceInterface>
apiService.addEventObserver = jest.fn()
apiService.createUserFileValetToken = jest.fn()
apiService.downloadFile = jest.fn()

View File

@@ -1,6 +1,9 @@
import { InternalEventInterface } from './../Internal/InternalEventInterface'
import { ApplicationStageChangedEventPayload } from '../Event/ApplicationStageChangedEventPayload'
import { ApplicationEvent } from '../Event/ApplicationEvent'
import { InternalEventHandlerInterface } from '../Internal/InternalEventHandlerInterface'
import { NoteType } from '@standardnotes/features'
import { ApplicationStage } from './../Application/ApplicationStage'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
import { ApplicationStage } from '../Application/ApplicationStage'
import {
PayloadEmitSource,
FileItem,
@@ -34,12 +37,16 @@ import { SessionsClientInterface } from '../Session/SessionsClientInterface'
import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { HistoryServiceInterface } from '../History/HistoryServiceInterface'
import { ContentType } from '@standardnotes/domain-core'
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
const PlaintextBackupsDirectoryName = 'Plaintext Backups'
export const TextBackupsDirectoryName = 'Text Backups'
export const FileBackupsDirectoryName = 'File Backups'
export class FilesBackupService extends AbstractService implements BackupServiceInterface {
export class FilesBackupService
extends AbstractService
implements BackupServiceInterface, InternalEventHandlerInterface
{
private filesObserverDisposer: () => void
private notesObserverDisposer: () => void
private tagsObserverDisposer: () => void
@@ -98,6 +105,15 @@ export class FilesBackupService extends AbstractService implements BackupService
})
}
async handleEvent(event: InternalEventInterface): Promise<void> {
if (event.type === ApplicationEvent.ApplicationStageChanged) {
const stage = (event.payload as ApplicationStageChangedEventPayload).stage
if (stage === ApplicationStage.Launched_10) {
void this.automaticallyEnableTextBackupsIfPreferenceNotSet()
}
}
}
setSuperConverter(converter: SuperConverterServiceInterface): void {
this.markdownConverter = converter
}
@@ -143,12 +159,6 @@ export class FilesBackupService extends AbstractService implements BackupService
;(this.session as unknown) = undefined
}
override async handleApplicationStage(stage: ApplicationStage): Promise<void> {
if (stage === ApplicationStage.Launched_10) {
void this.automaticallyEnableTextBackupsIfPreferenceNotSet()
}
}
private async automaticallyEnableTextBackupsIfPreferenceNotSet(): Promise<void> {
if (this.storage.getValue(StorageKey.TextBackupsEnabled) == undefined) {
this.storage.setValue(StorageKey.TextBackupsEnabled, true)