From 2a384cef7e29d6726cffc85d0ddda5fb85849e4a Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Mon, 26 Feb 2018 15:45:28 -0800 Subject: [PATCH] Two fixes for tricky import/register scenarios (#2072) * Clear data on finish of new install, unless re-link/light import * Don't show setup options in file menu in middle of light import * Naming changes to address feedback --- js/views/app_view.js | 13 +++++++++++-- js/views/install_view.js | 29 +++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/js/views/app_view.js b/js/views/app_view.js index 56527a49c9da..662e7539e494 100644 --- a/js/views/app_view.js +++ b/js/views/app_view.js @@ -54,7 +54,7 @@ }, finishLightImport: function() { var options = { - startStep: Whisper.InstallView.Steps.SCAN_QR_CODE, + hasExistingData: true }; this.openInstaller(options); }, @@ -65,7 +65,16 @@ } }, openInstaller: function(options) { - window.addSetupMenuItems(); + options = options || {}; + + // If we're in the middle of import, we don't want to show the menu options + // allowing the user to switch to other ways to set up the app. If they + // switched back and forth in the middle of a light import, they'd lose all + // that imported data. + if (!options.hasExistingData) { + window.addSetupMenuItems(); + } + this.resetViews(); var installView = this.installView = new Whisper.InstallView(options); this.openView(this.installView); diff --git a/js/views/install_view.js b/js/views/install_view.js index d619cf386b0c..330d0a5d390a 100644 --- a/js/views/install_view.js +++ b/js/views/install_view.js @@ -32,9 +32,8 @@ this.connect(); this.on('disconnected', this.reconnect); - if (Whisper.Registration.everDone() || options.startStep) { - this.selectStep(options.startStep || Steps.SCAN_QR_CODE); - } + // Keep data around if it's a re-link, or the middle of a light import + this.shouldRetainData = Whisper.Registration.everDone() || options.hasExistingData; }, render_attributes: function() { var errorMessage; @@ -162,11 +161,29 @@ } this.selectStep(Steps.PROGRESS_BAR); - resolve(name); + + var finish = function() { + resolve(name); + }; + + // Delete all data from database unless we're in the middle + // of a re-link, or we are finishing a light import. Without this, + // app restarts at certain times can cause weird things to happen, + // like data from a previous incomplete light import showing up + // after a new install. + if (this.shouldRetainData) { + return finish(); + } + + Whisper.Backup.clearDatabase().then(finish, function(error) { + console.log( + 'confirmNumber: error clearing database', + error && error.stack ? error.stack : error + ); + finish(); + }); }.bind(this)); }.bind(this)); }, }); - - Whisper.InstallView.Steps = Steps; })();