From 28ab19aa8a2165d15914bf7e3be5847ef0b64fb9 Mon Sep 17 00:00:00 2001 From: Ni Rui Date: Fri, 12 Aug 2022 19:13:18 +0800 Subject: [PATCH] Added a confirmation popup which will be triggered when user is closing the page while some tabs in Sshwifty is still open --- ui/home.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ui/home.vue b/ui/home.vue index bc667ce..5f6624f 100644 --- a/ui/home.vue +++ b/ui/home.vue @@ -253,20 +253,32 @@ export default { this.$emit("navigate-to", ""); }); } + + window.addEventListener("beforeunload", this.onBrowserClose); }, beforeDestroy() { + window.removeEventListener("beforeunload", this.onBrowserClose); + if (this.ticker === null) { clearInterval(this.ticker); this.ticker = null; } }, 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() { let now = new Date(); this.socket.update(now, this); }, - closeAllWindow() { + closeAllWindow(e) { for (let i in this.windows) { this.windows[i] = false; }