attempt to fix popup being blank

This commit is contained in:
buzz-lightsnack-2007 2024-05-02 11:14:16 +08:00
parent 6dab37bf5c
commit 97306bf393

View file

@ -3,7 +3,7 @@
*/ */
// Import modules. // Import modules.
import {session, observe} from "/scripts/secretariat.js"; import {session} from "/scripts/secretariat.js";
import Window from "/scripts/GUI/window.js"; import Window from "/scripts/GUI/window.js";
import Page from "/scripts/pages/page.js"; import Page from "/scripts/pages/page.js";
import Loader from "/scripts/GUI/loader.js"; import Loader from "/scripts/GUI/loader.js";
@ -17,7 +17,8 @@ class Page_Popup extends Page {
}; };
async background() { async background() {
observe(() => {this.content();}); // Wait until a change in the session storage.
} }
async loading() { async loading() {
@ -25,26 +26,24 @@ class Page_Popup extends Page {
} }
async switch() { async switch() {
// Get the last edited site.
let SITE = {};
SITE.url = await session.read([`last`]);
SITE.details = await session.read([`sites`, SITE.url]);
let PAGES = { let PAGES = {
"results": "results.htm", "results": "results.htm",
"loading": "load.htm", "loading": "load.htm",
"error": "error.htm" "error": "error.htm"
} }
console.log(PAGES); // Get the last edited site.
let SITE = {};
SITE = await session.read([`last`], -1);
SITE.details = (SITE.url) ? await session.read([`sites`, SITE.url]) : null;
// Set the relative chrome URLs // Set the relative chrome URLs
(Object.keys(PAGES)).forEach(PAGE => { (Object.keys(PAGES)).forEach(PAGE => {
PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`); PAGES[PAGE] = chrome.runtime.getURL(`pages/popup/${PAGES[PAGE]}`);
}); });
// Check if the site is available. // Check if the site is available.
if (SITE.details == null) { if (SITE.url ? (!SITE.done) : true) {
this.elements[`frame`].src = PAGES[`loading`]; this.elements[`frame`].src = PAGES[`loading`];
} else if (SITE.details.error) { } else if (SITE.details.error) {
// Set the iframe src to display the error. // Set the iframe src to display the error.
@ -61,7 +60,8 @@ class Page_Popup extends Page {
// Check if the frame is available. // Check if the frame is available.
if (this.elements[`frame`].length) { if (this.elements[`frame`].length) {
this.switch() await this.switch();
// observe((DATA) => {this.switch();});
} else { } else {
this.loading(); this.loading();
} }