From b5bcb59de254972df8e612d8fd5e98fd910a0de5 Mon Sep 17 00:00:00 2001 From: buzz-lightsnack-2007 <73412182+buzz-lightsnack-2007@users.noreply.github.com> Date: Mon, 15 Apr 2024 15:16:40 +0800 Subject: [PATCH] relocate windowman to be in /scripts/GUI --- gui/scripts/pages/open/popup.JS | 4 +- gui/scripts/pages/open/settings.JS | 2 +- gui/scripts/pages/popup.js | 2 +- gui/scripts/pages/settings.js | 8 +- .../windowman.JS => scripts/GUI/windowman.js | 80 +++++++------------ .../GUI}/windowman.search.js | 2 +- scripts/filters.js | 4 +- 7 files changed, 39 insertions(+), 63 deletions(-) rename gui/scripts/windowman.JS => scripts/GUI/windowman.js (86%) rename {gui/scripts => scripts/GUI}/windowman.search.js (99%) diff --git a/gui/scripts/pages/open/popup.JS b/gui/scripts/pages/open/popup.JS index bdbf119..5693613 100644 --- a/gui/scripts/pages/open/popup.JS +++ b/gui/scripts/pages/open/popup.JS @@ -1,7 +1,7 @@ -import { windowman } from "../../windowman.JS"; +import windowman from "/scripts/GUI/windowman.JS"; function redirect() { - windowman.new(`gui/pages/settings.htm`); + windowman.new(`/gui/pages/settings.htm`); window.close(); } diff --git a/gui/scripts/pages/open/settings.JS b/gui/scripts/pages/open/settings.JS index 76715f3..2ef7fa5 100644 --- a/gui/scripts/pages/open/settings.JS +++ b/gui/scripts/pages/open/settings.JS @@ -1,6 +1,6 @@ // Open the settings in a pop-up window. -import { windowman } from "../../windowman.JS"; +import windowman from "/scripts/GUI/windowman.JS"; function redirect() { windowman.new(`gui/pages/settings.htm`); diff --git a/gui/scripts/pages/popup.js b/gui/scripts/pages/popup.js index 884589e..5becf1b 100644 --- a/gui/scripts/pages/popup.js +++ b/gui/scripts/pages/popup.js @@ -3,7 +3,7 @@ */ // Import modules. -import windowman from "../windowman.js"; +import windowman from "/scripts/GUI/windowman.js"; let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js")); function start() { diff --git a/gui/scripts/pages/settings.js b/gui/scripts/pages/settings.js index 2e5e94e..fa0a3df 100644 --- a/gui/scripts/pages/settings.js +++ b/gui/scripts/pages/settings.js @@ -6,12 +6,8 @@ //import { windowman } from "../windowman.js"; async function build() { - let secretariat = await import( - chrome.runtime.getURL("scripts/secretariat.js") - ); - let windowman = ( - await import(chrome.runtime.getURL("gui/scripts/windowman.js")) - ).default; + let secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js")); + let windowman = (await import(chrome.runtime.getURL("/scripts/GUI/windowman.js"))).default; let window = new windowman(); window.sync(); diff --git a/gui/scripts/windowman.JS b/scripts/GUI/windowman.js similarity index 86% rename from gui/scripts/windowman.JS rename to scripts/GUI/windowman.js index 17a2036..6c98cd1 100644 --- a/gui/scripts/windowman.JS +++ b/scripts/GUI/windowman.js @@ -1,7 +1,8 @@ /* windowman Window and window content management */ -import texts from "./read.js"; +import texts from "../strings/read.js"; +import net from "../net.js"; // MAKE SURE TO TURN THIS OFF DURING BUILD. let DEBUG = false; @@ -18,13 +19,13 @@ export default class windowman { // Prepare the window with its metadata. constructor() { - function headers() { + async function headers() { let LOAD_STATE = true; let UI = { CSS: [ - chrome.runtime.getURL("gui/styles/external/fonts/materialdesignicons.min.css"), - chrome.runtime.getURL("gui/styles/external/materialize/css/materialize.css"), - chrome.runtime.getURL("gui/styles/ui.css"), + chrome.runtime.getURL("/gui/styles/external/fonts/materialdesignicons.min.css"), + chrome.runtime.getURL("/gui/styles/external/materialize/css/materialize.css"), + chrome.runtime.getURL("/gui/styles/ui.css"), ] }; @@ -32,40 +33,31 @@ export default class windowman { const source = UI.CSS[index]; try { - (async () => { - // Import source reading for later. - const reader = (await import(chrome.runtime.getURL(`/gui/scripts/read.js`))).default; - - const net = await import(chrome.runtime.getURL(`/scripts/net.js`)); - - let resource = false; - try { + let resource = false; + + try { resource = await net.download(source, `text`, true); - } catch (err) {} + } catch (err) {} - if (resource) { - let metadata_element = document.createElement(`link`); - metadata_element.setAttribute(`rel`, `stylesheet`); - metadata_element.setAttribute(`type`, `text/css`); - metadata_element.setAttribute(`href`, source); - document.querySelector(`head`).appendChild(metadata_element); - } else { - throw new ReferenceError(reader.localized(`error_msg_fileNotFound`)); - } - - })(); + if (resource) { + let metadata_element = document.createElement(`link`); + metadata_element.setAttribute(`rel`, `stylesheet`); + metadata_element.setAttribute(`type`, `text/css`); + metadata_element.setAttribute(`href`, source); + document.querySelector(`head`).appendChild(metadata_element); + } else { + throw new ReferenceError(new texts(`error_msg_fileNotFound`, [UI.CSS[index]])); + } } catch(err) { - (async() => { - const alerts = (await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))).default; - - // Raise an alert. - alerts.error(err.name, err.message, err.stack, true, [source]); + const alerts = (await import(chrome.runtime.getURL(`/gui/scripts/alerts.js`))).default; + + // Raise an alert. + alerts.error(err.name, err.message, err.stack, true, [source]); - // Stop loading the page when an error has occured; it's not going to work! - if (!DEBUG) { - window.close(); - } - })(); + // Stop loading the page when an error has occured; it's not going to work! + if (!DEBUG) { + window.close(); + } // Stop loading immediately during the error. break; @@ -76,16 +68,6 @@ export default class windowman { // Get the window. this[`metadata`] = chrome.windows.getCurrent(); - /* - window_metadata[`id`] = window.id; - window_metadata[`focused`] = window.focused; - window_metadata[`state`] = window.state; - window_metadata[`type`] = window.type; - window_metadata[`incognito`] = window.incognito; - window_metadata[`alwaysOnTop`] = window.alwaysOnTop; - window_metadata[`sessionId`] = window.sessionId; - window_metadata[`tabs`] = window.tabs;*/ - /* Fill in data and events. */ function appearance() { // Add missing classes to all elements. @@ -417,15 +399,13 @@ export default class windowman { /* Enable the searching interface. */ async function search() { - const search_GUI_manager = (await import(chrome.runtime.getURL(`gui/scripts/windowman.search.js`))); + const search_GUI_manager = (await import(chrome.runtime.getURL(`scripts/gui/windowman.search.js`))); return (search_GUI_manager.search()); - } + }; fill(); update(); updates(); this[`search`] = search(); } -} - -export { windowman }; +} \ No newline at end of file diff --git a/gui/scripts/windowman.search.js b/scripts/GUI/windowman.search.js similarity index 99% rename from gui/scripts/windowman.search.js rename to scripts/GUI/windowman.search.js index dd0c466..5b6e918 100644 --- a/gui/scripts/windowman.search.js +++ b/scripts/GUI/windowman.search.js @@ -1,6 +1,6 @@ import {read, write, observe} from "/scripts/secretariat.js"; import alerts from "/gui/scripts/alerts.js" -import texts from "/gui/scripts/read.js"; +import texts from "/scripts/strings/read.js"; export function search() { if (document.querySelectorAll(`[data-result]`)) { diff --git a/scripts/filters.js b/scripts/filters.js index 8a72ee9..1940dfc 100644 --- a/scripts/filters.js +++ b/scripts/filters.js @@ -3,7 +3,7 @@ Manage filters. */ import {read, write, forget, search} from "./secretariat.js"; -import {download} from "./net.js"; +import net from "./net.js"; import texts from "/gui/scripts/read.js"; import {Queue} from "./common.js"; import alerts from "/gui/scripts/alerts.js" @@ -73,7 +73,7 @@ export default class filters { new alerts (texts.localized(`settings_filters_update_status`, null, [filter_URL])); // Create promise of downloading. - let filter_download = download(filter_URL, `JSON`, false, true); + let filter_download = net.download(filter_URL, `JSON`, false, true); filter_download .then(async function (result) { // Only work when the filter is valid.