signal-desktop/js/views/app_view.js

195 lines
5.6 KiB
JavaScript
Raw Normal View History

/* 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';
2018-04-27 21:25:04 +00:00
window.Whisper = window.Whisper || {};
2019-05-16 22:32:38 +00:00
function resolveTheme() {
const theme = storage.get('theme-setting') || 'light';
if (window.platform === 'darwin' && theme === 'system') {
return window.systemTheme;
}
return theme;
}
2018-04-27 21:25:04 +00:00
Whisper.AppView = Backbone.View.extend({
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();
2019-05-16 22:32:38 +00:00
window.subscribeToSystemThemeChange(() => {
this.applyTheme();
});
2018-04-27 21:25:04 +00:00
},
events: {
'click .openInstaller': 'openInstaller', // NetworkStatusView has this button
openInbox: 'openInbox',
},
applyTheme() {
2019-05-16 22:32:38 +00:00
const theme = resolveTheme();
const iOS = storage.get('userAgent') === 'OWI';
2018-04-27 21:25:04 +00:00
this.$el
.removeClass('light-theme')
.removeClass('dark-theme')
.addClass(`${theme}-theme`);
if (iOS) {
this.$el.addClass('ios-theme');
} else {
this.$el.removeClass('ios-theme');
}
2018-04-27 21:25:04 +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);
},
openView(view) {
2018-04-27 21:25:04 +00:00
this.el.innerHTML = '';
this.el.append(view.el);
this.delegateEvents();
},
openDebugLog() {
2018-04-27 21:25:04 +00:00
this.closeDebugLog();
this.debugLogView = new Whisper.DebugLogView();
this.debugLogView.$el.appendTo(this.el);
},
closeDebugLog() {
2018-04-27 21:25:04 +00:00
if (this.debugLogView) {
this.debugLogView.remove();
this.debugLogView = null;
}
},
openImporter() {
2018-04-27 21:25:04 +00:00
window.addSetupMenuItems();
this.resetViews();
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);
},
finishLightImport() {
const options = {
2018-04-27 21:25:04 +00:00
hasExistingData: true,
};
this.openInstaller(options);
},
closeImporter() {
2018-04-27 21:25:04 +00:00
if (this.importView) {
this.importView.remove();
this.importView = null;
}
},
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-04-27 21:25:04 +00:00
this.resetViews();
const installView = new Whisper.InstallView(options);
this.installView = installView;
2018-04-27 21:25:04 +00:00
this.openView(this.installView);
},
closeInstaller() {
2018-04-27 21:25:04 +00:00
if (this.installView) {
this.installView.remove();
this.installView = null;
}
},
openStandalone() {
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);
}
},
closeStandalone() {
2018-04-27 21:25:04 +00:00
if (this.standaloneView) {
this.standaloneView.remove();
this.standaloneView = null;
}
},
resetViews() {
2018-04-27 21:25:04 +00:00
this.closeInstaller();
this.closeImporter();
this.closeStandalone();
},
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.
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 });
window.log.info('open inbox');
2018-04-27 21:25:04 +00:00
this.closeInstaller();
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({
window,
2018-04-27 21:25:04 +00:00
initialLoadComplete: options.initialLoadComplete,
});
return ConversationController.loadPromise().then(() => {
2018-04-27 21:25:04 +00:00
this.openView(this.inboxView);
});
2018-04-27 21:25:04 +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
},
onEmpty() {
const view = this.inboxView;
2018-04-27 21:25:04 +00:00
this.initialLoadComplete = true;
if (view) {
view.onEmpty();
}
},
onProgress(count) {
const view = this.inboxView;
2018-04-27 21:25:04 +00:00
if (view) {
view.onProgress(count);
}
},
2019-01-14 21:49:58 +00:00
openConversation(id, messageId) {
if (id) {
this.openInbox().then(() => {
2019-01-14 21:49:58 +00:00
this.inboxView.openConversation(id, messageId);
});
2018-04-27 21:25:04 +00:00
}
},
});
})();