diff --git a/ReactNativeClient/lib/components/side-menu-content.js b/ReactNativeClient/lib/components/side-menu-content.js index 1fc78b93a..323fa85c4 100644 --- a/ReactNativeClient/lib/components/side-menu-content.js +++ b/ReactNativeClient/lib/components/side-menu-content.js @@ -218,12 +218,23 @@ class SideMenuContentComponent extends Component { } let lines = Synchronizer.reportToLines(this.props.syncReport); - while (lines.length < 10) lines.push(''); // Add blank lines so that height of report text is fixed and doesn't affect scrolling const syncReportText = lines.join("\n"); + let decryptionReportText = ''; + if (this.props.decryptionWorker && this.props.decryptionWorker.state !== 'idle' && this.props.decryptionWorker.itemCount) { + decryptionReportText = _('Decrypting items: %d/%d', this.props.decryptionWorker.itemIndex + 1, this.props.decryptionWorker.itemCount); + } + + let fullReport = []; + if (syncReportText) fullReport.push(syncReportText); + if (fullReport.length) fullReport.push(''); + if (decryptionReportText) fullReport.push(decryptionReportText); + + while (fullReport.length < 12) fullReport.push(''); // Add blank lines so that height of report text is fixed and doesn't affect scrolling + items.push(this.synchronizeButton(this.props.syncStarted ? 'cancel' : 'sync')); - items.push({syncReportText}); + items.push({fullReport.join('\n')}); items.push(); @@ -260,6 +271,7 @@ const SideMenuContent = connect( theme: state.settings.theme, opacity: state.sideMenuOpenPercent, collapsedFolderIds: state.collapsedFolderIds, + decryptionWorker: state.decryptionWorker, }; } )(SideMenuContentComponent) diff --git a/ReactNativeClient/lib/reducer.js b/ReactNativeClient/lib/reducer.js index e3c406790..8d44601b0 100644 --- a/ReactNativeClient/lib/reducer.js +++ b/ReactNativeClient/lib/reducer.js @@ -31,6 +31,11 @@ const defaultState = { startState: 'idle', port: null, }, + decryptionWorker: { + state: 'idle', + itemIndex: 0, + itemCount: 0, + }, }; const stateUtils = {}; @@ -538,7 +543,18 @@ const reducer = (state = defaultState, action) => { if ('startState' in action) clipperServer.startState = action.startState; if ('port' in action) clipperServer.port = action.port; newState.clipperServer = clipperServer; - break; + break; + + case 'DECRYPTION_WORKER_SET': + + newState = Object.assign({}, state); + const decryptionWorker = Object.assign({}, newState.decryptionWorker); + for (var n in action) { + if (!action.hasOwnProperty(n) || n === 'type') continue; + decryptionWorker[n] = action[n]; + } + newState.decryptionWorker = decryptionWorker; + break; } } catch (error) { diff --git a/ReactNativeClient/lib/services/DecryptionWorker.js b/ReactNativeClient/lib/services/DecryptionWorker.js index 2381a9152..6b2936b5f 100644 --- a/ReactNativeClient/lib/services/DecryptionWorker.js +++ b/ReactNativeClient/lib/services/DecryptionWorker.js @@ -48,6 +48,12 @@ class DecryptionWorker { }, 1000); } + dispatchReport(report) { + const action = Object.assign({}, report); + action.type = 'DECRYPTION_WORKER_SET'; + this.dispatch(action); + } + async start(options = null) { if (options === null) options = {}; if (!('materKeyNotLoadedHandler' in options)) options.materKeyNotLoadedHandler = 'throw'; @@ -63,6 +69,8 @@ class DecryptionWorker { let excludedIds = []; + this.dispatchReport({ state: 'started' }); + try { const notLoadedMasterKeyDisptaches = []; @@ -73,13 +81,12 @@ class DecryptionWorker { for (let i = 0; i < items.length; i++) { const item = items[i]; - // Temp hack - // if (['edf44b7a0e4f8cbf248e206cd8dfa800', '2ccb3c9af0b1adac2ec6b66a5961fbb1'].indexOf(item.id) >= 0) { - // excludedIds.push(item.id); - // continue; - // } - const ItemClass = BaseItem.itemClass(item); + + this.dispatchReport({ + itemIndex: i, + itemCount: items.length, + }); // Don't log in production as it results in many messages when importing many items // this.logger().info('DecryptionWorker: decrypting: ' + item.id + ' (' + ItemClass.tableName() + ')'); @@ -112,11 +119,14 @@ class DecryptionWorker { } catch (error) { this.logger().error('DecryptionWorker:', error); this.state_ = 'idle'; + this.dispatchReport({ state: 'idle' }); throw error; } this.logger().info('DecryptionWorker: completed decryption.'); + this.dispatchReport({ state: 'idle' }); + this.state_ = 'idle'; }