mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-14 18:27:44 +02:00
Sync progress report
This commit is contained in:
parent
46cd64b08b
commit
a962f719a7
@ -328,12 +328,34 @@ commands.push({
|
|||||||
usage: 'sync',
|
usage: 'sync',
|
||||||
description: 'Synchronizes with remote storage.',
|
description: 'Synchronizes with remote storage.',
|
||||||
action: function(args, end) {
|
action: function(args, end) {
|
||||||
|
|
||||||
|
let redrawnCalled = false;
|
||||||
|
|
||||||
|
let options = {
|
||||||
|
onProgress: (report) => {
|
||||||
|
let line = [];
|
||||||
|
if (report.remotesToUpdate) line.push(_('Items to upload: %d/%d.', report.createRemote + report.updateRemote, report.remotesToUpdate));
|
||||||
|
if (report.remotesToDelete) line.push(_('Remote items to delete: %d/%d.', report.deleteRemote, report.remotesToDelete));
|
||||||
|
if (report.localsToUdpate) line.push(_('Items to download: %d/%d.', report.createLocal + report.updateLocal, report.localsToUdpate));
|
||||||
|
if (report.localsToDelete) line.push(_('Local items to delete: %d/%d.', report.deleteLocal, report.localsToDelete));
|
||||||
|
redrawnCalled = true;
|
||||||
|
vorpal.ui.redraw(line.join(' '));
|
||||||
|
},
|
||||||
|
onMessage: (msg) => {
|
||||||
|
if (redrawnCalled) vorpal.ui.redraw.done();
|
||||||
|
this.log(msg);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
this.log(_('Synchronization target: %s', Setting.value('sync.target')));
|
this.log(_('Synchronization target: %s', Setting.value('sync.target')));
|
||||||
synchronizer(Setting.value('sync.target')).then((s) => {
|
synchronizer(Setting.value('sync.target')).then((s) => {
|
||||||
return s.start();
|
this.log(_('Starting synchronization...'));
|
||||||
|
return s.start(options);
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.log(error);
|
this.log(error);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
if (redrawnCalled) vorpal.ui.redraw.done();
|
||||||
|
this.log(_('Done.'));
|
||||||
end();
|
end();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -77,7 +77,10 @@ class Synchronizer {
|
|||||||
return this.syncDirName_;
|
return this.syncDirName_;
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start(options = null) {
|
||||||
|
if (!options) options = {};
|
||||||
|
if (!options.onProgress) options.onProgress = function(o) {};
|
||||||
|
|
||||||
if (this.state() != 'idle') {
|
if (this.state() != 'idle') {
|
||||||
this.logger().warn('Synchronization is already in progress. State: ' + this.state());
|
this.logger().warn('Synchronization is already in progress. State: ' + this.state());
|
||||||
return;
|
return;
|
||||||
@ -94,6 +97,11 @@ class Synchronizer {
|
|||||||
this.state_ = 'started';
|
this.state_ = 'started';
|
||||||
|
|
||||||
let report = {
|
let report = {
|
||||||
|
remotesToUpdate: 0,
|
||||||
|
remotesToDelete: 0,
|
||||||
|
localsToUdpate: 0,
|
||||||
|
localsToDelete: 0,
|
||||||
|
|
||||||
createLocal: 0,
|
createLocal: 0,
|
||||||
updateLocal: 0,
|
updateLocal: 0,
|
||||||
deleteLocal: 0,
|
deleteLocal: 0,
|
||||||
@ -112,6 +120,9 @@ class Synchronizer {
|
|||||||
let result = await BaseItem.itemsThatNeedSync();
|
let result = await BaseItem.itemsThatNeedSync();
|
||||||
let locals = result.items;
|
let locals = result.items;
|
||||||
|
|
||||||
|
report.remotesToUpdate += locals.length;
|
||||||
|
options.onProgress(report);
|
||||||
|
|
||||||
for (let i = 0; i < locals.length; i++) {
|
for (let i = 0; i < locals.length; i++) {
|
||||||
let local = locals[i];
|
let local = locals[i];
|
||||||
let ItemClass = BaseItem.itemClass(local);
|
let ItemClass = BaseItem.itemClass(local);
|
||||||
@ -196,6 +207,8 @@ class Synchronizer {
|
|||||||
report[action]++;
|
report[action]++;
|
||||||
|
|
||||||
donePaths.push(path);
|
donePaths.push(path);
|
||||||
|
|
||||||
|
options.onProgress(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result.hasMore) break;
|
if (!result.hasMore) break;
|
||||||
@ -206,6 +219,8 @@ class Synchronizer {
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
let deletedItems = await BaseModel.deletedItems();
|
let deletedItems = await BaseModel.deletedItems();
|
||||||
|
report.remotesToDelete = deletedItems.length;
|
||||||
|
options.onProgress(report);
|
||||||
for (let i = 0; i < deletedItems.length; i++) {
|
for (let i = 0; i < deletedItems.length; i++) {
|
||||||
let item = deletedItems[i];
|
let item = deletedItems[i];
|
||||||
let path = BaseItem.systemPath(item.item_id)
|
let path = BaseItem.systemPath(item.item_id)
|
||||||
@ -214,6 +229,7 @@ class Synchronizer {
|
|||||||
await BaseModel.remoteDeletedItem(item.item_id);
|
await BaseModel.remoteDeletedItem(item.item_id);
|
||||||
|
|
||||||
report['deleteRemote']++;
|
report['deleteRemote']++;
|
||||||
|
options.onProgress(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
@ -252,6 +268,9 @@ class Synchronizer {
|
|||||||
|
|
||||||
if (!action) continue;
|
if (!action) continue;
|
||||||
|
|
||||||
|
report.localsToUdpate++;
|
||||||
|
options.onProgress(report);
|
||||||
|
|
||||||
if (action == 'createLocal' || action == 'updateLocal') {
|
if (action == 'createLocal' || action == 'updateLocal') {
|
||||||
let content = await this.api().get(path);
|
let content = await this.api().get(path);
|
||||||
if (content === null) {
|
if (content === null) {
|
||||||
@ -273,6 +292,8 @@ class Synchronizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
report[action]++;
|
report[action]++;
|
||||||
|
|
||||||
|
options.onProgress(report);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!listResult.hasMore) break;
|
if (!listResult.hasMore) break;
|
||||||
@ -288,9 +309,12 @@ class Synchronizer {
|
|||||||
for (let i = 0; i < noteIds.length; i++) {
|
for (let i = 0; i < noteIds.length; i++) {
|
||||||
let noteId = noteIds[i];
|
let noteId = noteIds[i];
|
||||||
if (remoteIds.indexOf(noteId) < 0) {
|
if (remoteIds.indexOf(noteId) < 0) {
|
||||||
|
report.localsToDelete++;
|
||||||
|
options.onProgress(report);
|
||||||
this.logSyncOperation('deleteLocal', { id: noteId }, null, 'remote has been deleted');
|
this.logSyncOperation('deleteLocal', { id: noteId }, null, 'remote has been deleted');
|
||||||
await Note.delete(noteId, { trackDeleted: false });
|
await Note.delete(noteId, { trackDeleted: false });
|
||||||
report['deleteLocal']++;
|
report['deleteLocal']++;
|
||||||
|
options.onProgress(report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -298,6 +322,8 @@ class Synchronizer {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.onProgress(report);
|
||||||
|
|
||||||
this.logger().info('Synchronization complete [' + synchronizationId + ']:');
|
this.logger().info('Synchronization complete [' + synchronizationId + ']:');
|
||||||
await this.logSyncSummary(report);
|
await this.logSyncSummary(report);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user