From 3858d68a0a95873865c012bb43d7884020ce5474 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 11 Mar 2021 13:27:06 +0100 Subject: [PATCH] Reload worker on new version --- www/common/cryptpad-common.js | 4 ++++ www/common/outer/async-store.js | 14 ++++++++++++++ www/common/outer/mailbox-handlers.js | 4 ++-- www/common/outer/sharedworker.js | 14 ++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 68e341562..0cc25b684 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2129,6 +2129,10 @@ define([ common.onNetworkReconnect.fire(data); }); }, + FORCE_RELOAD: function () { + // XXX not used + common.onNewVersionReconnect.fire(); + }, // OnlyOffice OO_EVENT: common.onlyoffice.onEvent.fire, // Mailbox diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index bc857be7f..27d9e1997 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2990,6 +2990,20 @@ define([ }); }; + Store.newVersionReload = function () { + broadcast([], "NETWORK_RECONNECT"); + + /* // XXX NETWORK_RECONNECT only works when a manual /api/config is used + // XXX The following code disconnect all tabs and asks for a page reload BUT + // if the urlArgs has not changed, new tabs will stay on the same DISCONNECTED worker + // XXX One solution is to change the FRESH mode token before sending the newVersion message + Store.disconnect(); + broadcast([], "FORCE_RELOAD"); + if (self.CP_closeWorker) { + setTimeout(self.CP_closeWorker, 200); + } + */ + }; Store.disconnect = function () { if (self.accountDeletion) { return; } if (!store.network) { return; } diff --git a/www/common/outer/mailbox-handlers.js b/www/common/outer/mailbox-handlers.js index f200ed387..6190e00e6 100644 --- a/www/common/outer/mailbox-handlers.js +++ b/www/common/outer/mailbox-handlers.js @@ -711,8 +711,8 @@ define([ } if (content.reload) { // We're going to force a disconnect, dismiss - // XXX - return void cb(true); + ctx.Store.newVersionReload(); + return; // This message will be removed when reloading the worker } var uid = msg.uid; broadcasts[uid] = { diff --git a/www/common/outer/sharedworker.js b/www/common/outer/sharedworker.js index 825deb383..21b80e1d5 100644 --- a/www/common/outer/sharedworker.js +++ b/www/common/outer/sharedworker.js @@ -9,6 +9,20 @@ localStorage = { self.tabs = {}; +// XXX Not used for now +self.CP_closeWorker = function () { + Object.keys(self.tabs).forEach(function (id) { + var obj = self.tabs[id]; + if (obj.port) { return; } + console.error(id); + try { + obj.port.close(); + } catch (e) { + console.error(e); + } + }); +}; + var postMsg = function (client, data) { client.port.postMessage(data); };