From 0a79f64528d168d7548f9e4d5a184aa2836ad164 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Sun, 28 Apr 2024 21:58:57 +0800 Subject: [PATCH 01/33] set options as part of instantiating a window --- scripts/GUI/window.js | 90 +++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/scripts/GUI/window.js b/scripts/GUI/window.js index f8f1fae..3a655e7 100644 --- a/scripts/GUI/window.js +++ b/scripts/GUI/window.js @@ -5,36 +5,39 @@ export default class Window { constructor(url, options) { this.url = url; - - if ((typeof options).includes(`obj`) && options != null) { - this.#options = options; - (Object.keys(options)).forEach((OPTION) => { - this[OPTION] = options[OPTION]; - }); - } - - // Check if the URL starts with a valid protocol. If not, it is most likely an extension page. - if (!(this.url.startsWith(`http`) && this.url.contains(`://`))) { - this.url = chrome.runtime.getURL(this.url); - } - - this.#options = (this.#options) ? this.#options : {}; - this.#options[`url`] = (this.url != this.#options[`url`]) ? this.url : this.#options[`url`]; - - // Remove options only readable here and not in the API. - (this.hidden != null) ? delete this.#options.hidden : this.hidden = false; + this.update(options); // Show the window if it's not hidden. (!this.hidden) ? this.show() : false; } + /* + Check this window's state. + */ + #check() { + // 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; + } + /* Show the window. */ show() { - chrome.windows.create(this.#options, (window) => { - this.ID = window.id; - }); + this.#check(); + + (this.hidden || this.hidden == null || !(this.ID)) + ? chrome.windows.create(this.#options, (window) => { + this.hidden = false; + this.ID = window.id; + }) + : false; }; @@ -42,11 +45,14 @@ export default class Window { Hide the window. */ hide() { + this.#check(); + // Close the window if it is still defined. (this.ID) ? chrome.windows.remove(this.ID) : false; // Remove the ID. delete this.ID; + this.hidden = true; } /* Create an action listener. @@ -61,4 +67,46 @@ export default class Window { // Add the event. chrome.windows[event].addListener(callback); } + + /* + Set the options of the window. + */ + update(options) { + if ((typeof options).includes(`obj`) && options != null) { + // Merge the options if defined. If not, set it to the options itself. + this.#options = (this.#options) + ? Object.assign(this.#options, options) + : options; + + (Object.keys(options)).forEach((OPTION) => { + this[OPTION] = options[OPTION]; + }); + } + + // Check if the URL starts with a valid protocol. If not, it is most likely an extension page. + (!(this.url.startsWith(`http`) && this.url.contains(`://`))) + ? this.url = chrome.runtime.getURL(this.url) + : false; + + this.#options[`url`] = (this.url != this.#options[`url`]) ? this.url : this.#options[`url`]; + + // Make sure height and width are integers. + [`height`, `width`].forEach((DIMENSION) => { + if (this[DIMENSION]) { + this[DIMENSION] = Math.abs(parseInt(this[DIMENSION])); + this.#options[DIMENSION] = this[DIMENSION]; + } + }); + + // Remove options only readable here and not in the API. + (this.hidden != null) + ? delete this.#options.hidden + : this.hidden = ((this.hidden != null) + ? this.hidden + : false); + + // Update windows already open. + this.#check(); + (this.ID) ? chrome.windows.update(this.ID, options) : false; + } }; \ No newline at end of file From 181df98a98c0c96c5ec76c48de1c3a0be085317d 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:05:30 +0800 Subject: [PATCH 02/33] remove window type --- pages/popup.htm | 2 +- styles/popup.css | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pages/popup.htm b/pages/popup.htm index cd7759f..0ae6fd1 100644 --- a/pages/popup.htm +++ b/pages/popup.htm @@ -4,7 +4,7 @@ - +