diff --git a/api/js/framework/fw_base.js b/api/js/framework/fw_base.js index 0a94198402..b1951767f3 100644 --- a/api/js/framework/fw_base.js +++ b/api/js/framework/fw_base.js @@ -70,6 +70,7 @@ window.fw_base = (function(){ "use strict"; return Class.extend( // keep track of opened popups this.popups = []; + window.addEventListener("beforeunload", this.beforeUnloadHandler.bind(this)); // initiate dark mode @@ -1042,6 +1043,18 @@ window.fw_base = (function(){ "use strict"; return Class.extend( return popups.flat(); }, + /** + * If this window is closed, notify popups about it + * @param event + */ + beforeUnloadHandler: function (event) + { + this.popups.forEach(function (popup) + { + popup.egw_rejoin(popup); + }); + }, + /** * Get application window * @param {type} _app diff --git a/api/js/jsapi/egw.js b/api/js/jsapi/egw.js index 5b68a35583..3b3ec38378 100644 --- a/api/js/jsapi/egw.js +++ b/api/js/jsapi/egw.js @@ -475,4 +475,31 @@ window.app = {classes: {}}; window.et2_call = function(_func) { return egw.applyFunc(_func, [].slice.call(arguments, 1), window); +} + +/** + * Main window was reloaded, rejoin + */ +window.egw_rejoin = function () +{ + let warning = egw(this).message(egw.lang("Lost connection to main window"), "warning"); + + window.setTimeout(function () + { + opener.addEventListener("load", () => + { + /* It takes more than just re-setting this.framework to get things working again + + let reconnecting = egw(this).message("Reconnecting..."); + window.setTimeout(() => + { + opener.console.log("Re-set framework"); + warning.close(); + reconnecting.close(); + this.framework = this.opener.framework; + this.framework.egw_appWindow().console.log("Popup %s rejoined", this.location.href); + }, 5000); + */ + }); + }.bind(window), 500); } \ No newline at end of file