diff --git a/chrome/content/zotero/xpcom/storage/storageEngine.js b/chrome/content/zotero/xpcom/storage/storageEngine.js index 8c7b991971..db3909f4f3 100644 --- a/chrome/content/zotero/xpcom/storage/storageEngine.js +++ b/chrome/content/zotero/xpcom/storage/storageEngine.js @@ -34,6 +34,7 @@ if (!Zotero.Sync.Storage) { * @param {Object} options * @param {Integer} options.libraryID * @param {Object} options.controller - Storage controller instance (ZFS_Controller/WebDAV_Controller) + * @param {Function} [onProgress] - Function to run when a request finishes: f(progress, progressMax) * @param {Function} [onError] - Function to run on error * @param {Boolean} [stopOnError] */ @@ -52,11 +53,15 @@ Zotero.Sync.Storage.Engine = function (options) { this.library = Zotero.Libraries.get(options.libraryID); this.controller = options.controller; + this.numRequests = 0; + this.requestsRemaining = 0; + this.local = Zotero.Sync.Storage.Local; this.utils = Zotero.Sync.Storage.Utilities; this.setStatus = options.setStatus || function () {}; this.onError = options.onError || function (e) {}; + this.onProgress = options.onProgress || function (progress, progressMax) {}; this.stopOnError = options.stopOnError || false; this.queues = []; @@ -136,6 +141,7 @@ Zotero.Sync.Storage.Engine.prototype.start = Zotero.Promise.coroutine(function* } var filesEditable = Zotero.Libraries.get(libraryID).filesEditable; + this.requestsRemaining = 0; // Check for updated files to upload if (!filesEditable) { @@ -322,8 +328,13 @@ Zotero.Sync.Storage.Engine.prototype.queueItem = Zotero.Promise.coroutine(functi libraryID: this.libraryID, name: item.libraryKey, onStart: request => this.controller[fn](request), - onProgress: this.onProgress + onStop: () => { + this.requestsRemaining--; + this.onProgress(this.numRequests - this.requestsRemaining, this.numRequests); + } }); return request.start(); }); + this.numRequests++; + this.requestsRemaining++; }) diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index ed5d6e55f5..c93abcfa47 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -609,12 +609,27 @@ Zotero.Sync.Runner_Module = function (options = {}) { */ var _doFileSync = Zotero.Promise.coroutine(function* (libraries, options) { Zotero.debug("Starting file syncing"); - this.setSyncStatus(Zotero.getString('sync.status.syncingFiles')); var resyncLibraries = [] for (let libraryID of libraries) { _stopCheck(); + this.setSyncStatus( + Zotero.getString( + 'sync.status.syncingFilesInLibrary', Zotero.Libraries.get(libraryID).name + ) + ); try { - let opts = {}; + let opts = { + onProgress: (progress, progressMax) => { + var remaining = progressMax - progress; + this.setSyncStatus( + Zotero.getString( + 'sync.status.syncingFilesInLibraryWithRemaining', + [Zotero.Libraries.get(libraryID).name, remaining], + remaining + ) + ); + } + }; Object.assign(opts, options); opts.libraryID = libraryID; diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index af27d7518a..06cbdead19 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -967,6 +967,8 @@ sync.status.processingUpdatedData = Processing updated data from sync server sync.status.uploadingData = Uploading data to sync server sync.status.uploadAccepted = Upload accepted \u2014 waiting for sync server sync.status.syncingFiles = Syncing files +sync.status.syncingFilesInLibrary = Syncing files in %S +sync.status.syncingFilesInLibraryWithRemaining = Syncing files in %1$S (%2$S remaining);Syncing files in %1$S (%2$S remaining) sync.status.syncingFullText = Syncing full-text content sync.storage.mbRemaining = %SMB remaining