1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Desktop: Fixes #4919: Make sure sync startup operations are cleared after startup

This commit is contained in:
Laurent Cozic 2021-05-09 18:12:47 +02:00
parent 4ea21e0c32
commit 4b26893b21
4 changed files with 35 additions and 15 deletions

View File

@ -1351,6 +1351,9 @@ packages/lib/services/synchronizer/migrations/2.js.map
packages/lib/services/synchronizer/tools.d.ts
packages/lib/services/synchronizer/tools.js
packages/lib/services/synchronizer/tools.js.map
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.d.ts
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js.map
packages/lib/services/synchronizer/utils/types.d.ts
packages/lib/services/synchronizer/utils/types.js
packages/lib/services/synchronizer/utils/types.js.map

3
.gitignore vendored
View File

@ -1338,6 +1338,9 @@ packages/lib/services/synchronizer/migrations/2.js.map
packages/lib/services/synchronizer/tools.d.ts
packages/lib/services/synchronizer/tools.js
packages/lib/services/synchronizer/tools.js.map
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.d.ts
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js
packages/lib/services/synchronizer/utils/handleSyncStartupOperation.js.map
packages/lib/services/synchronizer/utils/types.d.ts
packages/lib/services/synchronizer/utils/types.js
packages/lib/services/synchronizer/utils/types.js.map

View File

@ -1,4 +1,4 @@
import Setting, { SyncStartupOperation } from './models/Setting';
import Setting from './models/Setting';
import Logger, { TargetType, LoggerWrapper } from './Logger';
import shim from './shim';
import BaseService from './services/BaseService';
@ -44,7 +44,7 @@ import ResourceService from './services/ResourceService';
import DecryptionWorker from './services/DecryptionWorker';
const { loadKeychainServiceAndSettings } = require('./services/SettingUtils');
import MigrationService from './services/MigrationService';
import { clearLocalDataForRedownload, clearLocalSyncStateForReupload } from './services/synchronizer/tools';
import handleSyncStartupOperation from './services/synchronizer/utils/handleSyncStartupOperation';
const { toSystemSlashes } = require('./path-utils');
const { setAutoFreeze } = require('immer');
@ -651,18 +651,6 @@ export default class BaseApplication {
return toSystemSlashes(output, 'linux');
}
private async handleSyncToolActions() {
if (Setting.value('sync.startupOperation') === SyncStartupOperation.ClearLocalSyncState) {
await clearLocalSyncStateForReupload(reg.db());
} else if (Setting.value('sync.startupOperation') === SyncStartupOperation.ClearLocalData) {
await clearLocalDataForRedownload(reg.db());
} else if (Setting.value('sync.startupOperation') === SyncStartupOperation.None) {
// Nothing
} else {
throw new Error(`Invalid sync.startupOperation value: ${Setting.value('sync.startupOperation')}`);
}
}
async start(argv: string[]): Promise<any> {
const startFlags = await this.handleStartFlags_(argv);
@ -753,7 +741,7 @@ export default class BaseApplication {
BaseModel.setDb(this.database_);
await loadKeychainServiceAndSettings(KeychainServiceDriver);
await this.handleSyncToolActions();
await handleSyncStartupOperation();
appLogger.info(`Client ID: ${Setting.value('clientId')}`);

View File

@ -0,0 +1,26 @@
import Setting, { SyncStartupOperation } from '../../../models/Setting';
import { clearLocalDataForRedownload, clearLocalSyncStateForReupload } from '../tools';
import { reg } from '../../../registry';
import Logger from '../../../Logger';
const logger = Logger.create('handleSyncStartupOperation');
export default async function() {
logger.info('Processing operation:', Setting.value('sync.startupOperation'));
if (Setting.value('sync.startupOperation') === SyncStartupOperation.ClearLocalSyncState) {
await clearLocalSyncStateForReupload(reg.db());
Setting.setValue('sync.startupOperation', SyncStartupOperation.None);
} else if (Setting.value('sync.startupOperation') === SyncStartupOperation.ClearLocalData) {
await clearLocalDataForRedownload(reg.db());
Setting.setValue('sync.startupOperation', SyncStartupOperation.None);
} else if (Setting.value('sync.startupOperation') === SyncStartupOperation.None) {
// Nothing
} else {
throw new Error(`Invalid sync.startupOperation value: ${Setting.value('sync.startupOperation')}`);
}
}