Remove more handlers when closing the drive

pull/1/head
yflory 5 years ago
parent a7c274e6ae
commit 9cf99a8b65

@ -254,6 +254,7 @@ define([
var setEditable = function (state) { var setEditable = function (state) {
APP.editable = state; APP.editable = state;
if (APP.closed || (APP.$content && !$.contains(document.documentElement, APP.$content[0]))) { return; }
if (!state) { if (!state) {
APP.$content.addClass('cp-app-drive-readonly'); APP.$content.addClass('cp-app-drive-readonly');
$('[draggable="true"]').attr('draggable', false); $('[draggable="true"]').attr('draggable', false);
@ -3175,6 +3176,8 @@ define([
// Display the selected directory into the content part (rightside) // Display the selected directory into the content part (rightside)
// NOTE: Elements in the trash are not using the same storage structure as the others // NOTE: Elements in the trash are not using the same storage structure as the others
var _displayDirectory = function (path, force) { var _displayDirectory = function (path, force) {
if (APP.closed || (APP.$content && !$.contains(document.documentElement, APP.$content[0]))) { return; }
APP.hideMenu(); APP.hideMenu();
if (!APP.editable) { debug("Read-only mode"); } if (!APP.editable) { debug("Read-only mode"); }
@ -3372,6 +3375,7 @@ define([
appStatus.ready(true); appStatus.ready(true);
}; };
var displayDirectory = APP.displayDirectory = function (path, force) { var displayDirectory = APP.displayDirectory = function (path, force) {
if (APP.closed || (APP.$content && !$.contains(document.documentElement, APP.$content[0]))) { return; }
if (history.isHistoryMode) { if (history.isHistoryMode) {
return void _displayDirectory(path, force); return void _displayDirectory(path, force);
} }
@ -4118,16 +4122,6 @@ define([
APP.hideMenu(); APP.hideMenu();
}); });
$(window).on('mouseup', onWindowMouseUp);
$(window).on('keydown', onWindowKeydown);
$(window).on('click', onWindowClick);
var removeWindowListeners = function () {
$(window).off('mouseup', onWindowMouseUp);
$(window).off('keydown', onWindowKeydown);
$(window).off('click', onWindowClick);
};
// Chrome considers the double-click means "select all" in the window // Chrome considers the double-click means "select all" in the window
$content.on('mousedown', function (e) { $content.on('mousedown', function (e) {
$content.focus(); $content.focus();
@ -4211,7 +4205,7 @@ define([
} }
}; };
sframeChan.on('EV_DRIVE_CHANGE', function (data) { var onEvDriveChange = sframeChan.on('EV_DRIVE_CHANGE', function (data) {
if (history.isHistoryMode) { return; } if (history.isHistoryMode) { return; }
var path = data.path.slice(); var path = data.path.slice();
@ -4247,7 +4241,7 @@ define([
} }
return false; return false;
}); });
sframeChan.on('EV_DRIVE_REMOVE', function (data) { var onEvDriveRemove = sframeChan.on('EV_DRIVE_REMOVE', function (data) {
if (history.isHistoryMode) { return; } if (history.isHistoryMode) { return; }
var path = data.path.slice(); var path = data.path.slice();
@ -4280,6 +4274,21 @@ define([
return false; return false;
}); });
$(window).on('mouseup', onWindowMouseUp);
$(window).on('keydown', onWindowKeydown);
$(window).on('click', onWindowClick);
var removeWindowListeners = function () {
$(window).off('mouseup', onWindowMouseUp);
$(window).off('keydown', onWindowKeydown);
$(window).off('click', onWindowClick);
try {
onEvDriveChange.stop();
onEvDriveRemove.stop();
} catch (e) {}
};
if (APP.histConfig) { if (APP.histConfig) {
APP.histConfig.onOpen = function () { APP.histConfig.onOpen = function () {
// If we're in a shared folder history, store its id in memory // If we're in a shared folder history, store its id in memory
@ -4353,6 +4362,7 @@ define([
return { return {
refresh: refresh, refresh: refresh,
close: function () { close: function () {
APP.closed = true;
removeWindowListeners(); removeWindowListeners();
} }
}; };

@ -437,13 +437,13 @@ define([
var onDisconnect = function (noAlert) { var onDisconnect = function (noAlert) {
setEditable(false); setEditable(false);
if (driveAPP.refresh) { driveAPP.refresh(); } if (APP.team && driveAPP.refresh) { driveAPP.refresh(); }
toolbar.failed(); toolbar.failed();
if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); } if (!noAlert) { UI.alert(Messages.common_connectionLost, undefined, true); }
}; };
var onReconnect = function (info) { var onReconnect = function (info) {
setEditable(true); setEditable(true);
if (driveAPP.refresh) { driveAPP.refresh(); } if (APP.team && driveAPP.refresh) { driveAPP.refresh(); }
toolbar.reconnecting(info.myId); toolbar.reconnecting(info.myId);
UI.findOKButton().click(); UI.findOKButton().click();
}; };

Loading…
Cancel
Save