attempt to deactivate the window when it ceases to exist

Prevent errors when re-opening
This commit is contained in:
buzz-lightsnack-2007 2024-04-28 22:45:28 +08:00
parent c9f4707e09
commit 5098e733eb

View file

@ -15,15 +15,22 @@ export default class Window {
Check this window's state. Check this window's state.
*/ */
#check() { #check() {
// Determine if this window is still open. const deactivate = () => {
(this.ID)
? chrome.windows.get(this.ID, (window) => {
if (window == null) {
delete this.ID; delete this.ID;
this.hidden = true; this.hidden = true;
} };
// Determine if this window is still open.
try {
(this.ID)
? chrome.windows.get(this.ID, (window) => {
(window == null) ? deactivate() : false;
}) })
: false; : false;
} catch(err) {
deactivate();
}
} }
/* /*
@ -32,12 +39,12 @@ export default class Window {
show() { show() {
this.#check(); this.#check();
(this.hidden || this.hidden == null || !(this.ID)) if (!this.ID) {
? chrome.windows.create(this.#options, (window) => { chrome.windows.create(this.#options, (window) => {
this.hidden = false; this.hidden = false;
this.ID = window.id; this.ID = window.id;
}) })
: false; };
}; };