feat: cleanup work on plugins system

This commit is contained in:
SethBurkart123
2025-03-17 15:06:26 +11:00
parent 75446c6855
commit 5c0044a4d4
6 changed files with 59 additions and 93 deletions
+3 -7
View File
@@ -1,6 +1,5 @@
import { import {
initializeSettingsState,
settingsState, settingsState,
} from "@/seqta/utils/listeners/SettingsState" } from "@/seqta/utils/listeners/SettingsState"
import documentLoadCSS from "@/css/documentload.scss?inline" import documentLoadCSS from "@/css/documentload.scss?inline"
@@ -21,9 +20,8 @@ if (document.childNodes[1]) {
init() init()
} }
import * as plugins from "@/plugins" // Import the plugins from folder import * as plugins from "@/plugins"
import { main } from "@/seqta/main"
async function init() { async function init() {
const hasSEQTATitle = document.title.includes("SEQTA Learn") const hasSEQTATitle = document.title.includes("SEQTA Learn")
@@ -40,14 +38,12 @@ async function init() {
icon.href = icon48 // Change the icon icon.href = icon48 // Change the icon
try { try {
// wait until settingsState has been loaded from storage await main()
await initializeSettingsState()
if (settingsState.onoff) { if (settingsState.onoff) {
Object.values(plugins).forEach(plugin => { Object.values(plugins).forEach(plugin => {
plugin(); plugin();
}) })
} }
console.info( console.info(
"[BetterSEQTA+] Successfully initalised BetterSEQTA+, starting to load assets.", "[BetterSEQTA+] Successfully initalised BetterSEQTA+, starting to load assets.",
-3
View File
@@ -1,3 +0,0 @@
export async function init() {
console.log('Hello, world!')
}
+1 -1
View File
@@ -1,2 +1,2 @@
export { init as Monofile } from './monofile' export { init as Monofile } from './monofile'
export { init as Hello } from './hello' export { init as Themes } from './themes'
+1 -82
View File
@@ -10,7 +10,6 @@ import { delay } from "@/seqta/utils/delay"
import stringToHTML from "@/seqta/utils/stringToHTML" import stringToHTML from "@/seqta/utils/stringToHTML"
import { MessageHandler } from "@/seqta/utils/listeners/MessageListener" import { MessageHandler } from "@/seqta/utils/listeners/MessageListener"
import { import {
initializeSettingsState,
settingsState, settingsState,
} from "@/seqta/utils/listeners/SettingsState" } from "@/seqta/utils/listeners/SettingsState"
import { StorageChangeHandler } from "@/seqta/utils/listeners/StorageChanges" import { StorageChangeHandler } from "@/seqta/utils/listeners/StorageChanges"
@@ -21,9 +20,7 @@ import { eventManager } from "@/seqta/utils/listeners/EventManager"
import { enableNotificationCollector } from "@/seqta/utils/CreateEnable/EnableNotificationCollector" import { enableNotificationCollector } from "@/seqta/utils/CreateEnable/EnableNotificationCollector"
import RegisterClickListeners from "@/seqta/utils/listeners/ClickListeners" import RegisterClickListeners from "@/seqta/utils/listeners/ClickListeners"
import { AddBetterSEQTAElements } from "@/seqta/ui/AddBetterSEQTAElements" import { AddBetterSEQTAElements } from "@/seqta/ui/AddBetterSEQTAElements"
import { enableCurrentTheme } from "@/seqta/ui/themes/enableCurrent"
import { updateAllColors } from "@/seqta/ui/colors/Manager" import { updateAllColors } from "@/seqta/ui/colors/Manager"
import pageState from "@/pageState.js?url"
import loading from "@/seqta/ui/Loading" import loading from "@/seqta/ui/Loading"
import { SendNewsPage } from "@/seqta/utils/SendNewsPage" import { SendNewsPage } from "@/seqta/utils/SendNewsPage"
import { loadHomePage } from "@/seqta/utils/Loaders/LoadHomePage" import { loadHomePage } from "@/seqta/utils/Loaders/LoadHomePage"
@@ -34,77 +31,14 @@ import MenuitemSVGKey from "@/seqta/content/MenuItemSVGKey.json"
// Icons and fonts // Icons and fonts
import IconFamily from "@/resources/fonts/IconFamily.woff" import IconFamily from "@/resources/fonts/IconFamily.woff"
import icon48 from "@/resources/icons/icon-48.png?base64"
// Stylesheets // Stylesheets
import iframeCSS from "@/css/iframe.scss?raw" import iframeCSS from "@/css/iframe.scss?raw"
import injectedCSS from "@/css/injected.scss?inline"
import documentLoadCSS from "@/css/documentload.scss?inline"
var IsSEQTAPage = false
let hasSEQTAText = false
// This check is placed outside of the document load event due to issues with EP (https://github.com/BetterSEQTA/BetterSEQTA-Plus/issues/84)
if (document.childNodes[1]) {
hasSEQTAText =
document.childNodes[1].textContent?.includes(
"Copyright (c) SEQTA Software",
) ?? false
init()
}
export async function init() {
CheckForMenuList()
const hasSEQTATitle = document.title.includes("SEQTA Learn")
if (hasSEQTAText && hasSEQTATitle && !IsSEQTAPage) {
IsSEQTAPage = true
console.info("[BetterSEQTA+] Verified SEQTA Page")
const documentLoadStyle = document.createElement("style")
documentLoadStyle.textContent = documentLoadCSS
document.head.appendChild(documentLoadStyle)
const icon = document.querySelector('link[rel*="icon"]')! as HTMLLinkElement
icon.href = icon48
try {
// wait until settingsState has been loaded from storage
await initializeSettingsState()
if (settingsState.onoff) {
injectMainScript()
enableCurrentTheme()
if (typeof settingsState.assessmentsAverage == "undefined") {
settingsState.assessmentsAverage = true
}
// TEMP FIX for bug! -> this is a hack to get the injected.css file to have HMR in development mode as this import system is currently broken with crxjs
if (import.meta.env.MODE === "development") {
import("../css/injected.scss")
} else {
const injectedStyle = document.createElement("style")
injectedStyle.textContent = injectedCSS
document.head.appendChild(injectedStyle)
}
}
console.info(
"[BetterSEQTA+] Successfully initalised BetterSEQTA+, starting to load assets.",
)
main()
} catch (error: any) {
console.error(error)
}
}
}
function SetDisplayNone(ElementName: string) { function SetDisplayNone(ElementName: string) {
return `li[data-key=${ElementName}]{display:var(--menuHidden) !important; transition: 1s;}` return `li[data-key=${ElementName}]{display:var(--menuHidden) !important; transition: 1s;}`
} }
async function HideMenuItems(): Promise<void> { async function HideMenuItems(): Promise<void> {
try { try {
let stylesheetInnerText: string = "" let stylesheetInnerText: string = ""
@@ -125,14 +59,6 @@ async function HideMenuItems(): Promise<void> {
} }
} }
function injectMainScript() {
const mainScript = document.createElement("script")
mainScript.src = browser.runtime.getURL(pageState)
document.head.appendChild(mainScript)
}
export function hideSideBar() { export function hideSideBar() {
const sidebar = document.getElementById("menu") // The sidebar element to be closed const sidebar = document.getElementById("menu") // The sidebar element to be closed
const main = document.getElementById("main") // The main content element that must be resized to fill the page const main = document.getElementById("main") // The main content element that must be resized to fill the page
@@ -173,13 +99,6 @@ export async function finishLoad() {
} }
} }
export function GetCSSElement(file: string) { export function GetCSSElement(file: string) {
const cssFile = browser.runtime.getURL(file) const cssFile = browser.runtime.getURL(file)
const fileref = document.createElement("link") const fileref = document.createElement("link")
@@ -855,7 +774,7 @@ export function showConflictPopup() {
}) })
} }
function main() { export function init() {
if (typeof settingsState.onoff === "undefined") { if (typeof settingsState.onoff === "undefined") {
browser.runtime.sendMessage({ type: "setDefaultStorage" }) browser.runtime.sendMessage({ type: "setDefaultStorage" })
} }
+5
View File
@@ -0,0 +1,5 @@
import { enableCurrentTheme } from "@/seqta/ui/themes/enableCurrent";
export async function init() {
enableCurrentTheme();
}
+49
View File
@@ -0,0 +1,49 @@
// Third-party libraries
import browser from "webextension-polyfill"
// Internal utilities and functions
import {
initializeSettingsState,
settingsState,
} from "@/seqta/utils/listeners/SettingsState"
// UI and theme management
import pageState from "@/pageState.js?url"
// Stylesheets
import injectedCSS from "@/css/injected.scss?inline"
export async function main() {
return new Promise(async (resolve, reject) => {
try {
await initializeSettingsState()
if (settingsState.onoff) {
injectPageState()
if (typeof settingsState.assessmentsAverage == "undefined") {
settingsState.assessmentsAverage = true
}
// TEMP FIX for bug! -> this is a hack to get the injected.css file to have HMR in development mode as this import system is currently broken with crxjs
if (import.meta.env.MODE === "development") {
import("../css/injected.scss")
} else {
const injectedStyle = document.createElement("style")
injectedStyle.textContent = injectedCSS
document.head.appendChild(injectedStyle)
}
}
resolve(true)
} catch (error: any) {
console.error(error)
reject(error)
}
})
}
function injectPageState() {
const mainScript = document.createElement("script")
mainScript.src = browser.runtime.getURL(pageState)
document.head.appendChild(mainScript)
}