From 5098e733eb0d9cad74995c86e1a73b7967d2f754 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:45:28 +0800 Subject: [PATCH] attempt to deactivate the window when it ceases to exist Prevent errors when re-opening --- scripts/GUI/window.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/GUI/window.js b/scripts/GUI/window.js index 3a655e7..c534753 100644 --- a/scripts/GUI/window.js +++ b/scripts/GUI/window.js @@ -15,15 +15,22 @@ export default class Window { Check this window's state. */ #check() { + const deactivate = () => { + delete this.ID; + this.hidden = true; + }; + // Determine if this window is still open. - (this.ID) - ? chrome.windows.get(this.ID, (window) => { - if (window == null) { - delete this.ID; - this.hidden = true; - } - }) - : false; + try { + (this.ID) + ? chrome.windows.get(this.ID, (window) => { + (window == null) ? deactivate() : false; + }) + : false; + } catch(err) { + deactivate(); + } + } /* @@ -32,12 +39,12 @@ export default class Window { show() { this.#check(); - (this.hidden || this.hidden == null || !(this.ID)) - ? chrome.windows.create(this.#options, (window) => { + if (!this.ID) { + chrome.windows.create(this.#options, (window) => { this.hidden = false; this.ID = window.id; }) - : false; + }; };