feat: Automatic plaintext backup option in Preferences > Backups will backup your notes and tags into plaintext, unencrypted folders on your computer. In addition, automatic encrypted text backups preference management has moved from the top-level menu in the desktop app to Preferences > Backups. (#2322)

This commit is contained in:
Mo
2023-05-02 11:05:10 -05:00
committed by GitHub
parent 3df23cdb5c
commit 7e3db49322
76 changed files with 1526 additions and 1013 deletions

View File

@@ -1,6 +1,6 @@
import { BackupServiceInterface } from '@standardnotes/files'
import { Environment } from '@standardnotes/models'
import { DeviceInterface, InternalEventBusInterface, EncryptionService } from '@standardnotes/services'
import { SNSessionManager } from '../Services/Session/SessionManager'
import { ApplicationIdentifier } from '@standardnotes/common'
import { ItemManager } from '@Lib/Services/Items/ItemManager'
@@ -13,6 +13,7 @@ export type MigrationServices = {
storageService: DiskStorageService
challengeService: ChallengeService
sessionManager: SNSessionManager
backups?: BackupServiceInterface
itemManager: ItemManager
singletonManager: SNSingletonManager
featuresService: SNFeaturesService

View File

@@ -0,0 +1,51 @@
import {
ApplicationStage,
FileBackupsDirectoryName,
StorageKey,
TextBackupsDirectoryName,
isDesktopDevice,
} from '@standardnotes/services'
import { Migration } from '@Lib/Migrations/Migration'
export class Migration2_167_6 extends Migration {
static override version(): string {
return '2.167.6'
}
protected registerStageHandlers(): void {
this.registerStageHandler(ApplicationStage.Launched_10, async () => {
await this.migrateStorageKeysForDesktopBackups()
this.markDone()
})
}
private async migrateStorageKeysForDesktopBackups(): Promise<void> {
const device = this.services.deviceInterface
if (!isDesktopDevice(device) || !this.services.backups) {
return
}
const fileBackupsEnabled = await device.isLegacyFilesBackupsEnabled()
this.services.storageService.setValue(StorageKey.FileBackupsEnabled, fileBackupsEnabled)
if (fileBackupsEnabled) {
const legacyLocation = await device.getLegacyFilesBackupsLocation()
const newLocation = `${legacyLocation}/${this.services.backups.prependWorkspacePathForPath(
FileBackupsDirectoryName,
)}`
await device.migrateLegacyFileBackupsToNewStructure(newLocation)
this.services.storageService.setValue(StorageKey.FileBackupsLocation, newLocation)
}
const wasLegacyDisabled = await device.wasLegacyTextBackupsExplicitlyDisabled()
if (wasLegacyDisabled) {
this.services.storageService.setValue(StorageKey.TextBackupsEnabled, false)
} else {
const newTextBackupsLocation = `${await device.getLegacyTextBackupsLocation()}/${this.services.backups.prependWorkspacePathForPath(
TextBackupsDirectoryName,
)}`
this.services.storageService.setValue(StorageKey.TextBackupsLocation, newTextBackupsLocation)
this.services.storageService.setValue(StorageKey.TextBackupsEnabled, true)
}
}
}

View File

@@ -0,0 +1,5 @@
## To create a migration:
1. Create a new file inside versions specifiying the would-be version of SNJS that would result when publishing your migration. For example, if the current SNJS version is 1.0.0 in package.json, your migration version should be 1.0.1 to target users below this version.
2. **Important** Export your migration inside the index.ts file.

View File

@@ -3,7 +3,15 @@ import { Migration2_7_0 } from './2_7_0'
import { Migration2_20_0 } from './2_20_0'
import { Migration2_36_0 } from './2_36_0'
import { Migration2_42_0 } from './2_42_0'
import { Migration2_167_6 } from './2_167_6'
export const MigrationClasses = [Migration2_0_15, Migration2_7_0, Migration2_20_0, Migration2_36_0, Migration2_42_0]
export const MigrationClasses = [
Migration2_0_15,
Migration2_7_0,
Migration2_20_0,
Migration2_36_0,
Migration2_42_0,
Migration2_167_6,
]
export { Migration2_0_15, Migration2_7_0, Migration2_20_0, Migration2_36_0, Migration2_42_0 }
export { Migration2_0_15, Migration2_7_0, Migration2_20_0, Migration2_36_0, Migration2_42_0, Migration2_167_6 }