2018-07-07 00:48:14 +00:00
|
|
|
/* global Backbone, Whisper, storage, _, ConversationController, $ */
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2017-04-12 21:20:56 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2017-04-12 21:20:56 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.AppView = Backbone.View.extend({
|
2018-07-07 00:48:14 +00:00
|
|
|
initialize() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.inboxView = null;
|
|
|
|
this.installView = null;
|
New design for import/install, 'light' import (#2053)
- A new design for the import flow. It features:
- Icons at the top of every screen
- Gray background, blue buttons, thinner text
- Simpler copy
- A new design for the install flow. It features:
- Immediate entry into the QR code screen
- Animated dots to show that we're loading the QR code from the server
- Fewer screens: 1) QR 2) device name 3) sync-in-progress
- When not set up, the app opens directly into the install screen, which has been streamlined. The `--import` command-line argument will cause the app to open directly into the import flow.
- Support for two different flavors of builds - the normal build will open into the standard registration flow, and the import flavor will be exactly the same except during setup it will open directly into the import flow.
- A new design for the (dev-only) standalone registration view
- When these install sequences are active, the OS File menu has entries to allow you to switch the method of setup you'd like to use. These go away as soon as the first step is taken in any of these flows.
- The device name (chosen on initial setup) is now shown in the settings panel
- At the end of a light import, we hand off to the normal device link screen, starting at the QR code. On a full import, we remove the sensitive encryption information in the export to prevent conflicts on multiple imports.
- `Whisper.Backup.exportToDirectory()` takes an options object so you can tell it to do a light export.
- `Whisper.Backup.importFromDirectory()` takes an options object so you can force it to load only the light components found on disk. It also returns an object so you can tell whether a given import was a full import or light import.
- On start of import, we build a list of all the ids present in the messages, conversations, and groups stores in IndexedDB. This can take some time if a lot of data is in the database already, but it makes the subsequent deduplicated import very fast.
- Disappearing messages are now excluded when exporting
- Remove some TODOs in the tests
2018-02-22 18:40:32 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.applyTheme();
|
|
|
|
this.applyHideMenu();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'click .openInstaller': 'openInstaller', // NetworkStatusView has this button
|
|
|
|
openInbox: 'openInbox',
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
applyTheme() {
|
2018-10-09 22:56:14 +00:00
|
|
|
const iOS = storage.get('userAgent') === 'OWI';
|
2018-07-07 00:48:14 +00:00
|
|
|
const theme = storage.get('theme-setting') || 'light';
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$el
|
2018-06-25 23:57:06 +00:00
|
|
|
.removeClass('light-theme')
|
|
|
|
.removeClass('dark-theme')
|
|
|
|
.addClass(`${theme}-theme`);
|
2018-10-09 22:56:14 +00:00
|
|
|
|
|
|
|
if (iOS) {
|
|
|
|
this.$el.addClass('ios-theme');
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('ios-theme');
|
|
|
|
}
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
applyHideMenu() {
|
|
|
|
const hideMenuBar = storage.get('hide-menu-bar', false);
|
2018-04-27 21:25:04 +00:00
|
|
|
window.setAutoHideMenuBar(hideMenuBar);
|
|
|
|
window.setMenuBarVisibility(!hideMenuBar);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openView(view) {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.el.innerHTML = '';
|
|
|
|
this.el.append(view.el);
|
|
|
|
this.delegateEvents();
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openDebugLog() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.closeDebugLog();
|
|
|
|
this.debugLogView = new Whisper.DebugLogView();
|
|
|
|
this.debugLogView.$el.appendTo(this.el);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
closeDebugLog() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (this.debugLogView) {
|
|
|
|
this.debugLogView.remove();
|
|
|
|
this.debugLogView = null;
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openImporter() {
|
2018-04-27 21:25:04 +00:00
|
|
|
window.addSetupMenuItems();
|
|
|
|
this.resetViews();
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
const importView = new Whisper.ImportView();
|
|
|
|
this.importView = importView;
|
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.listenTo(
|
|
|
|
importView,
|
|
|
|
'light-import',
|
|
|
|
this.finishLightImport.bind(this)
|
|
|
|
);
|
|
|
|
this.openView(this.importView);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
finishLightImport() {
|
|
|
|
const options = {
|
2018-04-27 21:25:04 +00:00
|
|
|
hasExistingData: true,
|
|
|
|
};
|
|
|
|
this.openInstaller(options);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
closeImporter() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (this.importView) {
|
|
|
|
this.importView.remove();
|
|
|
|
this.importView = null;
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openInstaller(options = {}) {
|
2018-04-27 21:25:04 +00:00
|
|
|
// 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();
|
|
|
|
}
|
2018-02-26 23:45:28 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.resetViews();
|
2018-07-07 00:48:14 +00:00
|
|
|
const installView = new Whisper.InstallView(options);
|
|
|
|
this.installView = installView;
|
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.openView(this.installView);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
closeInstaller() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (this.installView) {
|
|
|
|
this.installView.remove();
|
|
|
|
this.installView = null;
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openStandalone() {
|
2018-06-02 00:55:35 +00:00
|
|
|
if (window.getEnvironment() !== 'production') {
|
2018-04-27 21:25:04 +00:00
|
|
|
window.addSetupMenuItems();
|
|
|
|
this.resetViews();
|
|
|
|
this.standaloneView = new Whisper.StandaloneRegistrationView();
|
|
|
|
this.openView(this.standaloneView);
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
closeStandalone() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (this.standaloneView) {
|
|
|
|
this.standaloneView.remove();
|
|
|
|
this.standaloneView = null;
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
resetViews() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.closeInstaller();
|
|
|
|
this.closeImporter();
|
|
|
|
this.closeStandalone();
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openInbox(options = {}) {
|
2018-04-27 21:25:04 +00:00
|
|
|
// The inbox can be created before the 'empty' event fires or afterwards. If
|
|
|
|
// before, it's straightforward: the onEmpty() handler below updates the
|
|
|
|
// view directly, and we're in good shape. If we create the inbox late, we
|
|
|
|
// need to be sure that the current value of initialLoadComplete is provided
|
|
|
|
// so its loading screen doesn't stick around forever.
|
2017-08-10 22:56:47 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
// Two primary techniques at play for this situation:
|
|
|
|
// - background.js has two openInbox() calls, and passes initalLoadComplete
|
|
|
|
// directly via the options parameter.
|
|
|
|
// - in other situations openInbox() will be called with no options. So this
|
|
|
|
// view keeps track of whether onEmpty() has ever been called with
|
|
|
|
// this.initialLoadComplete. An example of this: on a phone-pairing setup.
|
|
|
|
_.defaults(options, { initialLoadComplete: this.initialLoadComplete });
|
2017-04-12 21:20:56 +00:00
|
|
|
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.info('open inbox');
|
2018-04-27 21:25:04 +00:00
|
|
|
this.closeInstaller();
|
2017-04-12 21:20:56 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
if (!this.inboxView) {
|
|
|
|
// We create the inbox immediately so we don't miss an update to
|
|
|
|
// this.initialLoadComplete between the start of this method and the
|
|
|
|
// creation of inboxView.
|
|
|
|
this.inboxView = new Whisper.InboxView({
|
2018-07-07 00:48:14 +00:00
|
|
|
window,
|
2018-04-27 21:25:04 +00:00
|
|
|
initialLoadComplete: options.initialLoadComplete,
|
|
|
|
});
|
2018-07-07 00:48:14 +00:00
|
|
|
return ConversationController.loadPromise().then(() => {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.openView(this.inboxView);
|
2018-07-07 00:48:14 +00:00
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
}
|
2018-07-07 00:48:14 +00:00
|
|
|
if (!$.contains(this.el, this.inboxView.el)) {
|
|
|
|
this.openView(this.inboxView);
|
|
|
|
}
|
|
|
|
window.focus(); // FIXME
|
|
|
|
return Promise.resolve();
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
onEmpty() {
|
|
|
|
const view = this.inboxView;
|
2017-08-10 22:56:47 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.initialLoadComplete = true;
|
|
|
|
if (view) {
|
|
|
|
view.onEmpty();
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
onProgress(count) {
|
|
|
|
const view = this.inboxView;
|
2018-04-27 21:25:04 +00:00
|
|
|
if (view) {
|
|
|
|
view.onProgress(count);
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
openConversation(conversation) {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (conversation) {
|
2018-07-07 00:48:14 +00:00
|
|
|
this.openInbox().then(() => {
|
2018-07-18 16:38:42 +00:00
|
|
|
this.inboxView.openConversation(conversation);
|
2018-07-07 00:48:14 +00:00
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2017-04-12 21:20:56 +00:00
|
|
|
})();
|