Added a confirmation popup which will be triggered when user is closing the page while some tabs in Sshwifty is still open

This commit is contained in:
Ni Rui
2022-08-12 19:13:18 +08:00
parent d5badd135b
commit 28ab19aa8a

View File

@@ -253,20 +253,32 @@ export default {
this.$emit("navigate-to", ""); this.$emit("navigate-to", "");
}); });
} }
window.addEventListener("beforeunload", this.onBrowserClose);
}, },
beforeDestroy() { beforeDestroy() {
window.removeEventListener("beforeunload", this.onBrowserClose);
if (this.ticker === null) { if (this.ticker === null) {
clearInterval(this.ticker); clearInterval(this.ticker);
this.ticker = null; this.ticker = null;
} }
}, },
methods: { methods: {
onBrowserClose(e) {
if (this.tab.current < 0) {
return undefined;
}
const msg = "Some tabs are still open, are you sure you want to exit?";
(e || window.event).returnValue = msg;
return msg;
},
tick() { tick() {
let now = new Date(); let now = new Date();
this.socket.update(now, this); this.socket.update(now, this);
}, },
closeAllWindow() { closeAllWindow(e) {
for (let i in this.windows) { for (let i in this.windows) {
this.windows[i] = false; this.windows[i] = false;
} }