From fb4445cbd6b0ccade63c5c384e4d501976f4e523 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 22 Mar 2018 11:30:00 -0400 Subject: [PATCH 1/6] Run background script after DOM is parsed This allows us to leverage the existing loading screen for messaging without having to explicitly wait for DOM load event. --- background.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/background.html b/background.html index 091686fda..bbe333b59 100644 --- a/background.html +++ b/background.html @@ -951,7 +951,6 @@ -
@@ -965,5 +964,7 @@
Loading...
+ + From 1c4b7eb01c33dae312d5cd77711f1b4f456f9827 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 22 Mar 2018 11:51:47 -0400 Subject: [PATCH 2/6] Make namespace generation clearer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let’s make it clear that this is where we initialize our namespaces to avoid proliferation of various initialization points now that we support CommonJS. --- preload.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/preload.js b/preload.js index 3528fc75f..26aead31d 100644 --- a/preload.js +++ b/preload.js @@ -124,7 +124,7 @@ const { IdleDetector} = require('./js/modules/idle_detector'); - window.Signal = window.Signal || {}; + window.Signal = {}; window.Signal.Backup = require('./js/modules/backup'); window.Signal.Crypto = require('./js/modules/crypto'); window.Signal.Logs = require('./js/modules/logs'); @@ -134,7 +134,7 @@ window.Signal.Migrations.upgradeMessageSchema = upgradeMessageSchema; window.Signal.Migrations.V17 = require('./js/modules/migrations/17'); window.Signal.OS = require('./js/modules/os'); - window.Signal.Types = window.Signal.Types || {}; + window.Signal.Types = {}; window.Signal.Types.Attachment = Attachment; window.Signal.Types.Errors = require('./js/modules/types/errors'); window.Signal.Types.Message = Message; From add19aa73254be6285afff0e43f02b2e1db44d4d Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 22 Mar 2018 11:52:52 -0400 Subject: [PATCH 3/6] Add initialization view --- _locales/en/messages.json | 4 ++++ js/modules/views/initialization.js | 33 ++++++++++++++++++++++++++++++ preload.js | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 js/modules/views/initialization.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a8df96028..de3771b9c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -39,6 +39,10 @@ "message": "Loading...", "description": "Message shown on the loading screen before we've loaded any messages" }, + "optimizingApplication": { + "message": "Optimizing application...", + "description": "Message shown on the loading screen while we are doing application optimizations" + }, "chooseDirectory": { "message": "Choose folder", "description": "Button to allow the user to find a folder on disk" diff --git a/js/modules/views/initialization.js b/js/modules/views/initialization.js new file mode 100644 index 000000000..12bf334b5 --- /dev/null +++ b/js/modules/views/initialization.js @@ -0,0 +1,33 @@ +/* eslint-env browser */ + +/* global i18n: false */ + + +const OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD = 2000; // milliseconds + +// type Canceler = () => Eff Unit +// +// setMessage :: Unit -> Eff (dom :: DOM) Canceler +const setMessage = () => { + const message = document.querySelector('.app-loading-screen .message'); + if (!message) { + return () => {}; + } + message.innerText = i18n('loading'); + + const optimizingMessageTimeoutId = setTimeout(() => { + const innerMessage = document.querySelector('.app-loading-screen .message'); + if (!innerMessage) { + return; + } + innerMessage.innerText = i18n('optimizingApplication'); + }, OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD); + + return () => { + clearTimeout(optimizingMessageTimeoutId); + }; +}; + +module.exports = { + setMessage, +}; diff --git a/preload.js b/preload.js index 26aead31d..c10ed563a 100644 --- a/preload.js +++ b/preload.js @@ -140,6 +140,8 @@ window.Signal.Types.Message = Message; window.Signal.Types.MIME = require('./js/modules/types/mime'); window.Signal.Types.Settings = require('./js/modules/types/settings'); + window.Signal.Views = {}; + window.Signal.Views.Initialization = require('./js/modules/views/initialization'); window.Signal.Workflow = {}; window.Signal.Workflow.IdleDetector = IdleDetector; window.Signal.Workflow.MessageDataMigrator = From dede0f1e25bf1a9df964fc832e807817817e844e Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Thu, 22 Mar 2018 11:56:33 -0400 Subject: [PATCH 4/6] Improve user messaging during initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - We first show a localized loading message. - If initialization takes longer than a certain threshold, we show a different ‘optimization’ message. - If initialization is below the threshold the message change is canceled right before the regular loading screen. --- background.html | 2 +- js/background.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/background.html b/background.html index bbe333b59..b3a2517b4 100644 --- a/background.html +++ b/background.html @@ -961,7 +961,7 @@ -
Loading...
+
diff --git a/js/background.js b/js/background.js index 27018df5c..d72edc427 100644 --- a/js/background.js +++ b/js/background.js @@ -17,6 +17,7 @@ const { IdleDetector, MessageDataMigrator } = Signal.Workflow; const { Errors, Message } = window.Signal.Types; const { upgradeMessageSchema } = window.Signal.Migrations; + const { Views } = window.Signal; // Implicitly used in `indexeddb-backbonejs-adapter`: // https://github.com/signalapp/Signal-Desktop/blob/4033a9f8137e62ed286170ed5d4941982b1d3a64/components/indexeddb-backbonejs-adapter/backbone-indexeddb.js#L569 @@ -74,6 +75,8 @@ return accountManager; }; + const cancelInitializationMessage = Views.Initialization.setMessage(); + console.log('Start IndexedDB migrations'); storage.fetch(); @@ -163,6 +166,7 @@ connect(true); }); + cancelInitializationMessage(); var appView = window.owsDesktopApp.appView = new Whisper.AppView({el: $('body')}); Whisper.WallClockListener.init(Whisper.events); From 4c10fcfa17abd6c85ab5887aba506d424515f237 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 23 Mar 2018 09:42:15 -0400 Subject: [PATCH 5/6] Reduce threshold until optimization appears to 1s --- js/modules/views/initialization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/modules/views/initialization.js b/js/modules/views/initialization.js index 12bf334b5..549876968 100644 --- a/js/modules/views/initialization.js +++ b/js/modules/views/initialization.js @@ -3,7 +3,7 @@ /* global i18n: false */ -const OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD = 2000; // milliseconds +const OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD = 1000; // milliseconds // type Canceler = () => Eff Unit // From 90de9d85a38ff9ed137b200f165bb6abdbcb3d90 Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 23 Mar 2018 09:42:20 -0400 Subject: [PATCH 6/6] Remove type annotation --- js/modules/views/initialization.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/modules/views/initialization.js b/js/modules/views/initialization.js index 549876968..81ea45381 100644 --- a/js/modules/views/initialization.js +++ b/js/modules/views/initialization.js @@ -5,9 +5,6 @@ const OPTIMIZATION_MESSAGE_DISPLAY_THRESHOLD = 1000; // milliseconds -// type Canceler = () => Eff Unit -// -// setMessage :: Unit -> Eff (dom :: DOM) Canceler const setMessage = () => { const message = document.querySelector('.app-loading-screen .message'); if (!message) {