From ba4bef2beb72980c26b74acd15ebf4110ce641f8 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 22 Mar 2021 18:26:04 +0100 Subject: [PATCH] Reload when a drive is created in a different worker (driveless mode) --- www/common/cryptpad-common.js | 17 +++++++++++++++++ www/common/outer/async-store.js | 7 +++++++ www/common/outer/store-rpc.js | 1 + 3 files changed, 25 insertions(+) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 1d19089e3..7cc19a78c 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -2518,6 +2518,23 @@ define([ }; // XXX if you're in noDrive mode, check if an FS_hash is added and reload if that's the case // Listen for login/logout in other tabs + if (rdyCfg.noDrive && !localStorage[Constants.fileHashKey]) { + window.addEventListener('storage', function (e) { + if (e.key !== Constants.fileHashKey) { return; } + // New entry added to FS_hash: drive created in another tab, reload + var o = e.oldValue; + var n = e.newValue; + if (!o && n) { + postMessage('HAS_DRIVE', null, function(obj) { + // If we're still in noDrive mode, reload + if (!obj.state) { + LocalStore.loginReload(); + } + // Otherwise this worker is connected, nothing to do + }); + } + }); + } window.addEventListener('storage', function (e) { if (e.key !== Constants.userHashKey) { return; } var o = e.oldValue; diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 088c5fe29..83735de7e 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -2947,6 +2947,13 @@ define([ */ var initialized = false; + // Are we still in noDrive mode? + Store.hasDrive = function (clientId, data, cb) { + cb({ + state: Boolean(store.proxy) + }); + }; + // If we load CryptPad for the first time from an existing pad, don't create a // drive automatically. var onNoDrive = function (clientId, cb) { diff --git a/www/common/outer/store-rpc.js b/www/common/outer/store-rpc.js index e444f47f5..c4d1d1301 100644 --- a/www/common/outer/store-rpc.js +++ b/www/common/outer/store-rpc.js @@ -15,6 +15,7 @@ define([ MIGRATE_ANON_DRIVE: Store.migrateAnonDrive, PING: function (cId, data, cb) { cb(); }, CACHE_DISABLE: Store.disableCache, + HAS_DRIVE: Store.hasDrive, // RPC UPDATE_PIN_LIMIT: Store.updatePinLimit, GET_PIN_LIMIT: Store.getPinLimit,