From 446cca0725452110db24d269b45292348c7cf075 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 3 Nov 2020 18:29:09 +0100 Subject: [PATCH] Use offline state per shared folder in the drive --- customize.dist/loading.js | 1 + www/common/drive-ui.js | 26 ++++++++++++++++++++++++-- www/common/outer/async-store.js | 5 ++++- www/common/proxy-manager.js | 8 ++++++++ www/drive/inner.js | 2 ++ www/teams/inner.js | 2 ++ 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/customize.dist/loading.js b/customize.dist/loading.js index 4f8b79125..733b3fff0 100644 --- a/customize.dist/loading.js +++ b/customize.dist/loading.js @@ -327,6 +327,7 @@ button.primary:hover{ if (!built) { return; } try { var node = document.querySelector('.cp-loading-progress'); + if (!node) { return; } if (node.parentNode) { node.parentNode.removeChild(node); } document.querySelector('.cp-loading-spinner-container').setAttribute('style', 'display:none;'); document.querySelector('#cp-loading-message').setAttribute('style', 'display:block;'); diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 53e496ef4..4886b213e 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -42,6 +42,7 @@ define([ var APP = window.APP = { editable: false, + online: true, mobile: function () { if (window.matchMedia) { return !window.matchMedia('(any-pointer:fine)').matches; } else { return $('body').width() <= 600; } @@ -267,13 +268,25 @@ define([ }; // Handle disconnect/reconnect - var setEditable = function (state, isHistory) { + // If isHistory and isSf are both false, update the "APP.online" flag + // If isHistory is true, update the "APP.history" flag + // isSf is used to detect offline shared folders: setEditable is called on displayDirectory + var setEditable = function (state, isHistory, isSf) { if (APP.closed || !APP.$content || !$.contains(document.documentElement, APP.$content[0])) { return; } + if (isHistory) { + APP.history = !state; + } else if (!isSf) { + APP.online = state; + } + state = APP.online && !APP.history && state; APP.editable = !APP.readOnly && state; + if (!state) { APP.$content.addClass('cp-app-drive-readonly'); - if (!isHistory) { + if (!APP.history || !APP.online) { $('#cp-app-drive-connection-state').show(); + } else { + $('#cp-app-drive-connection-state').hide(); } $('[draggable="true"]').attr('draggable', false); } @@ -3670,6 +3683,15 @@ define([ } var readOnlyFolder = false; + + // If the shared folder is offline, add the "DISCONNECTED" banner, otherwise + // use the normal "editable" behavior (based on drive offline or history mode) + if (sfId && manager.folders[sfId].offline) { + setEditable(false, false, true); + } else { + setEditable(true, false, true); + } + if (APP.readOnly) { // Read-only drive (team?) $content.prepend($readOnly.clone()); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 62e078050..76b92feab 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -120,10 +120,13 @@ define([ Store.getSharedFolder = function (clientId, data, cb) { var s = getStore(data.teamId); var id = data.id; + var proxy; if (!s || !s.manager) { return void cb({ error: 'ENOTFOUND' }); } if (s.manager.folders[id]) { + proxy = Util.clone(s.manager.folders[id].proxy); + proxy.offline = Boolean(s.manager.folders[id].offline); // If it is loaded, return the shared folder proxy - return void cb(s.manager.folders[id].proxy); + return void cb(proxy); } else { // Otherwise, check if we know this shared folder var shared = Util.find(s.proxy, ['drive', UserObject.SHARED_FOLDERS]) || {}; diff --git a/www/common/proxy-manager.js b/www/common/proxy-manager.js index 88f4a052b..74bfcd890 100644 --- a/www/common/proxy-manager.js +++ b/www/common/proxy-manager.js @@ -40,6 +40,14 @@ define([ userObject: userObject, leave: leave }; + if (proxy.on) { + proxy.on('disconnect', function () { + Env.folders[id].offline = true; + }); + proxy.on('reconnect', function () { + Env.folders[id].online = true; + }); + } return userObject; }; diff --git a/www/drive/inner.js b/www/drive/inner.js index f85819083..9aa080dc3 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -82,6 +82,8 @@ define([ var readOnly = !secret.keys.editKeyStr; if (!manager || !manager.folders[fId]) { return; } manager.folders[fId].userObject.setReadOnly(readOnly, secret.keys.secondaryKey); + + manager.folders[fId].offline = newObj.offline; })); }); // Remove from memory folders that have been deleted from the drive remotely diff --git a/www/teams/inner.js b/www/teams/inner.js index d49bf6209..c50dde5a1 100644 --- a/www/teams/inner.js +++ b/www/teams/inner.js @@ -93,6 +93,8 @@ define([ var readOnly = !secret.keys.editKeyStr; if (!manager || !manager.folders[fId]) { return; } manager.folders[fId].userObject.setReadOnly(readOnly, secret.keys.secondaryKey); + + manager.folders[fId].offline = newObj.offline; })); }); // Remove from memory folders that have been deleted from the drive remotely