reinforce ES6 import for secretariat
This commit is contained in:
parent
c8fe102fa6
commit
983f0c3af9
1 changed files with 20 additions and 24 deletions
|
@ -4,7 +4,8 @@ Window and window content management */
|
||||||
import texts from "../../mapping/read.js";
|
import texts from "../../mapping/read.js";
|
||||||
import net from "/scripts/utils/net.js";
|
import net from "/scripts/utils/net.js";
|
||||||
import Window from "../window.js";
|
import Window from "../window.js";
|
||||||
import {global} from "/scripts/secretariat.js";
|
import logging from '/scripts/logging.js';
|
||||||
|
import {global, observe} from "/scripts/secretariat.js";
|
||||||
|
|
||||||
export default class windowman {
|
export default class windowman {
|
||||||
static new(URL, height, width) {
|
static new(URL, height, width) {
|
||||||
|
@ -40,14 +41,11 @@ export default class windowman {
|
||||||
throw new ReferenceError((new texts(`error_msg_fileNotFound`, [source])).localized);
|
throw new ReferenceError((new texts(`error_msg_fileNotFound`, [source])).localized);
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
const secretariat = (await import(chrome.runtime.getURL(`/scripts/secretariat.js`)));
|
|
||||||
const logging = (await import(chrome.runtime.getURL(`/scripts/logging.js`))).default;
|
|
||||||
|
|
||||||
// Raise an alert.
|
// Raise an alert.
|
||||||
logging.error(err.name, err.message, err.stack, true, [source]);
|
logging.error(err.name, err.message, err.stack, true, [source]);
|
||||||
|
|
||||||
// Stop loading the page when an error has occured; it's not going to work!
|
// Stop loading the page when an error has occured; it's not going to work!
|
||||||
if ((await secretariat.global.read(`debug`, -1) != null) ? await secretariat.global.read(`debug`, -1) : true) {
|
if ((await global.read(`debug`, -1) != null) ? await global.read(`debug`, -1) : true) {
|
||||||
window.close();
|
window.close();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -200,14 +198,16 @@ export default class windowman {
|
||||||
: null;
|
: null;
|
||||||
target[`dimensions`][`width`] = (button.getAttribute(`tab-width`)) ? parseInt(button.getAttribute(`tab-width`))
|
target[`dimensions`][`width`] = (button.getAttribute(`tab-width`)) ? parseInt(button.getAttribute(`tab-width`))
|
||||||
: null;
|
: null;
|
||||||
|
target[`path`] = (
|
||||||
|
!target[`source`].includes(`://`)
|
||||||
|
? window.location.pathname.split(`/`).slice(0, -1).join(`/`).concat(`/`)
|
||||||
|
: ``
|
||||||
|
).concat(target[`source`]);
|
||||||
|
|
||||||
const event = function () {
|
const event = () => {
|
||||||
// Get the correct path.
|
// Get the correct path.
|
||||||
target[`path`] = (
|
|
||||||
!target[`source`].includes(`://`)
|
new logging((new texts(`page_opening`)).localized, target[`path`]);
|
||||||
? window.location.pathname.split(`/`).slice(0, -1).join(`/`).concat(`/`)
|
|
||||||
: ``
|
|
||||||
).concat(target[`source`]);
|
|
||||||
|
|
||||||
// Open the window as a popup.
|
// Open the window as a popup.
|
||||||
new Window(target[`path`], Object.assign(target[`dimensions`], {"type": "popup"}));
|
new Window(target[`path`], Object.assign(target[`dimensions`], {"type": "popup"}));
|
||||||
|
@ -258,10 +258,6 @@ export default class windowman {
|
||||||
|
|
||||||
/* Run this function if you would like to synchronize with data. */
|
/* Run this function if you would like to synchronize with data. */
|
||||||
async sync() {
|
async sync() {
|
||||||
// Import the module.
|
|
||||||
const secretariat = await import(chrome.runtime.getURL("scripts/secretariat.js"));
|
|
||||||
const logging = (await import(chrome.runtime.getURL(`/scripts/logging.js`))).default;
|
|
||||||
|
|
||||||
async function fill() {
|
async function fill() {
|
||||||
let input_elements = document.querySelectorAll("[data-store]");
|
let input_elements = document.querySelectorAll("[data-store]");
|
||||||
|
|
||||||
|
@ -271,7 +267,7 @@ export default class windowman {
|
||||||
let data = {};
|
let data = {};
|
||||||
data[`source`] = input_element.getAttribute(`data-store`);
|
data[`source`] = input_element.getAttribute(`data-store`);
|
||||||
// data[`origin`] = (input_element.hasAttribute(`data-store-location`)) ? parseInt(input_element.getAttribute(`data-store-location`)) : -1
|
// data[`origin`] = (input_element.hasAttribute(`data-store-location`)) ? parseInt(input_element.getAttribute(`data-store-location`)) : -1
|
||||||
data[`value`] = secretariat.global.read(data[`source`]);
|
data[`value`] = global.read(data[`source`]);
|
||||||
|
|
||||||
data[`value`].then(async function(value) {
|
data[`value`].then(async function(value) {
|
||||||
switch (input_element.getAttribute(`type`).toLowerCase()) {
|
switch (input_element.getAttribute(`type`).toLowerCase()) {
|
||||||
|
@ -316,7 +312,7 @@ export default class windowman {
|
||||||
UI_item[`source`] = this.getAttribute(`data-store`);
|
UI_item[`source`] = this.getAttribute(`data-store`);
|
||||||
UI_item[`value`] = this.checked;
|
UI_item[`value`] = this.checked;
|
||||||
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
|
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
|
||||||
secretariat.global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
|
global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -338,7 +334,7 @@ export default class windowman {
|
||||||
: parseInt(this.value)
|
: parseInt(this.value)
|
||||||
: this.value;
|
: this.value;
|
||||||
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
|
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
|
||||||
secretariat.global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
|
global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -352,7 +348,7 @@ export default class windowman {
|
||||||
*/
|
*/
|
||||||
async function updates() {
|
async function updates() {
|
||||||
// Get the storage data.
|
// Get the storage data.
|
||||||
let storage_data = await secretariat.global.read();
|
let storage_data = await global.read();
|
||||||
|
|
||||||
async function enable() {
|
async function enable() {
|
||||||
let input_elements = document.querySelectorAll("[data-enable]");
|
let input_elements = document.querySelectorAll("[data-enable]");
|
||||||
|
@ -361,10 +357,10 @@ export default class windowman {
|
||||||
input_elements.forEach(async (input_element) => {
|
input_elements.forEach(async (input_element) => {
|
||||||
if (input_element.getAttribute("data-enable")) {
|
if (input_element.getAttribute("data-enable")) {
|
||||||
// Enable the element.
|
// Enable the element.
|
||||||
input_element.disabled = ((await secretariat.global.read(input_element.getAttribute("data-enable"))) != null
|
input_element.disabled = ((await global.read(input_element.getAttribute("data-enable"))) != null
|
||||||
? (typeof (await secretariat.global.read(input_element.getAttribute("data-enable")))).includes(`obj`)
|
? (typeof (await global.read(input_element.getAttribute("data-enable")))).includes(`obj`)
|
||||||
? (Object.keys(await secretariat.global.read(input_element.getAttribute("data-enable")))).length <= 0
|
? (Object.keys(await global.read(input_element.getAttribute("data-enable")))).length <= 0
|
||||||
: !(!!(await secretariat.global.read(input_element.getAttribute("data-enable"))))
|
: !(!!(await global.read(input_element.getAttribute("data-enable"))))
|
||||||
: true);
|
: true);
|
||||||
(input_element.disabled) ? input_element.classList.add(`disabled`) : input_element.classList.remove(`disabled`);
|
(input_element.disabled) ? input_element.classList.add(`disabled`) : input_element.classList.remove(`disabled`);
|
||||||
|
|
||||||
|
@ -379,7 +375,7 @@ export default class windowman {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the input elements.
|
// Update the input elements.
|
||||||
secretariat.observe((what) => {
|
observe((what) => {
|
||||||
enable();
|
enable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue