From 2568a6fc408fd7a385cbc565cb9dddfda839d6f0 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 27 Mar 2025 12:21:39 +0530 Subject: [PATCH 1/4] feat: imrpove plugin loading - load themes plugin on acode startup and load others after successfully starting acode --- biome.json | 22 ++++++++++++- src/lib/loadPlugins.js | 70 +++++++++++++++++++++++++++++++++++++++--- src/lib/main.js | 21 ++++++++++--- 3 files changed, 102 insertions(+), 11 deletions(-) diff --git a/biome.json b/biome.json index 389b37960..364cfc827 100644 --- a/biome.json +++ b/biome.json @@ -4,8 +4,28 @@ "organizeImports": { "enabled": true }, "linter": { "enabled": true, - "rules": { "recommended": false } + "rules": { + "recommended": false, + "complexity": { + "noForEach": "warn", + "noStaticOnlyClass": "error", + "noUselessSwitchCase": "error", + "useFlatMap": "error" + }, + "style": { + "noNegationElse": "off", + "useForOf": "error", + "useNodejsImportProtocol": "error", + "useNumberNamespace": "error" + }, + "suspicious": { + "noDoubleEquals": "error", + "noThenProperty": "error", + "useIsArray": "error" + } + } }, + "javascript": { "globals": ["Global1"] }, "files": { "include": ["src/**/*", "utils/**/*.js", "www/**/*.js", "www/res/**/*.css"], "ignore": [ diff --git a/src/lib/loadPlugins.js b/src/lib/loadPlugins.js index 2a00bb7e3..f1a5f7c2c 100644 --- a/src/lib/loadPlugins.js +++ b/src/lib/loadPlugins.js @@ -1,32 +1,85 @@ import fsOperation from "../fileSystem"; import Url from "../utils/Url"; import loadPlugin from "./loadPlugin"; +import settings from "./settings"; -export default async function loadPlugins() { +// theme-related keywords for determining theme plugins +const THEME_IDENTIFIERS = new Set([ + "theme", + "catppuccin", + "pine", + "githubdark", + "radiant", + "rdtheme", + "ayumirage", + "dust", + "synthwave", + "dragon", + "mint", + "monokai", + "lumina_code", + "sweet", + "moonlight", + "bluloco", +]); + +export default async function loadPlugins(onlyTheme = false) { const plugins = await fsOperation(PLUGIN_DIR).lsDir(); const results = []; const failedPlugins = []; + const loadedPlugins = new Set(); if (plugins.length > 0) { toast(strings["loading plugins"]); } + let pluginsToLoad = []; + const currentTheme = settings.value.appTheme; + + if (onlyTheme) { + // Only load theme plugins matching current theme + pluginsToLoad = plugins.filter((pluginDir) => { + const pluginId = Url.basename(pluginDir.url); + return isThemePlugin(pluginId) && !loadedPlugins.has(pluginId); + }); + } else { + // Load non-theme plugins that aren't loaded yet + pluginsToLoad = plugins.filter((pluginDir) => { + const pluginId = Url.basename(pluginDir.url); + return !isThemePlugin(pluginId) && !loadedPlugins.has(pluginId); + }); + } + // Load plugins concurrently - const loadPromises = plugins.map(async (pluginDir) => { + const loadPromises = pluginsToLoad.map(async (pluginDir) => { const pluginId = Url.basename(pluginDir.url); + + if (onlyTheme && currentTheme) { + const pluginIdLower = pluginId.toLowerCase(); + const currentThemeLower = currentTheme.toLowerCase(); + let matchFound = false; + if (pluginIdLower.includes(currentThemeLower)) { + matchFound = true; + } + + if (!matchFound && !isThemePlugin(pluginId)) { + return; + } + } + try { await loadPlugin(pluginId); + loadedPlugins.add(pluginId); results.push(true); } catch (error) { - window.log("error", `Failed to load plugin: ${pluginId}`); - window.log("error", error); - toast(`Failed to load plugin: ${pluginId}`); + console.error(`Error loading plugin ${pluginId}:`, error); failedPlugins.push(pluginId); results.push(false); } }); await Promise.allSettled(loadPromises); + if (failedPlugins.length > 0) { setTimeout(() => { cleanupFailedPlugins(failedPlugins).catch((error) => { @@ -37,6 +90,13 @@ export default async function loadPlugins() { return results.filter(Boolean).length; } +function isThemePlugin(pluginId) { + // Convert to lowercase for case-insensitive matching + const id = pluginId.toLowerCase(); + // Check if any theme identifier is present in the plugin ID + return Array.from(THEME_IDENTIFIERS).some((theme) => id.includes(theme)); +} + async function cleanupFailedPlugins(pluginIds) { for (const pluginId of pluginIds) { try { diff --git a/src/lib/main.js b/src/lib/main.js index 0e5f4a2e5..610a816e9 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -233,12 +233,23 @@ async function onDeviceReady() { window.log("error", error); toast(`Error: ${error.message}`); } finally { - setTimeout(() => { + setTimeout(async () => { document.body.removeAttribute("data-small-msg"); app.classList.remove("loading", "splash"); applySettings.afterRender(); + + // load plugins + try { + await loadPlugins(); + } catch (error) { + window.log("error", "Failed to load theme plugins!"); + window.log("error", error); + toast("Failed to load theme plugins!"); + } + applySettings.afterRender(); }, 500); } + // Check for app updates if (navigator.onLine) { cordova.plugin.http.sendRequest( @@ -430,13 +441,13 @@ async function loadApp() { new EditorFile(); - //load plugins + // load theme plugins try { - await loadPlugins(); + await loadPlugins(true); } catch (error) { - window.log("error", "Plugins loading failed!"); + window.log("error", "Failed to load theme plugins!"); window.log("error", error); - toast("Plugins loading failed!"); + toast("Failed to load theme plugins!"); } acode.setLoadingMessage("Loading folders..."); From d7230965d3cf3cdf4f20ea993cff2a76e051a7d4 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 27 Mar 2025 12:37:33 +0530 Subject: [PATCH 2/4] fix: add few comments and remove duplicate calls --- src/lib/loadPlugins.js | 9 ++++----- src/lib/main.js | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/lib/loadPlugins.js b/src/lib/loadPlugins.js index f1a5f7c2c..49a814a18 100644 --- a/src/lib/loadPlugins.js +++ b/src/lib/loadPlugins.js @@ -57,11 +57,10 @@ export default async function loadPlugins(onlyTheme = false) { if (onlyTheme && currentTheme) { const pluginIdLower = pluginId.toLowerCase(); const currentThemeLower = currentTheme.toLowerCase(); - let matchFound = false; - if (pluginIdLower.includes(currentThemeLower)) { - matchFound = true; - } - + const matchFound = pluginIdLower.includes(currentThemeLower); + // Skip if: + // 1. No match found with current theme AND + // 2. It's not a theme plugin at all if (!matchFound && !isThemePlugin(pluginId)) { return; } diff --git a/src/lib/main.js b/src/lib/main.js index 610a816e9..c076f6dbc 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -236,7 +236,6 @@ async function onDeviceReady() { setTimeout(async () => { document.body.removeAttribute("data-small-msg"); app.classList.remove("loading", "splash"); - applySettings.afterRender(); // load plugins try { From 2e7a956e2dd8e146636580f7ed1c4d25e62a759a Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 27 Mar 2025 12:41:37 +0530 Subject: [PATCH 3/4] fix: wrong typo --- src/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/main.js b/src/lib/main.js index c076f6dbc..cde10b092 100644 --- a/src/lib/main.js +++ b/src/lib/main.js @@ -241,9 +241,9 @@ async function onDeviceReady() { try { await loadPlugins(); } catch (error) { - window.log("error", "Failed to load theme plugins!"); + window.log("error", "Failed to load plugins!"); window.log("error", error); - toast("Failed to load theme plugins!"); + toast("Failed to load plugins!"); } applySettings.afterRender(); }, 500); From 8299274e3a6f34c11a20f5c7455e877784862094 Mon Sep 17 00:00:00 2001 From: Raunak Raj <71929976+bajrangCoder@users.noreply.github.com> Date: Thu, 27 Mar 2025 12:47:38 +0530 Subject: [PATCH 4/4] fix --- src/lib/loadPlugins.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/loadPlugins.js b/src/lib/loadPlugins.js index 49a814a18..2679bb332 100644 --- a/src/lib/loadPlugins.js +++ b/src/lib/loadPlugins.js @@ -23,7 +23,7 @@ const THEME_IDENTIFIERS = new Set([ "bluloco", ]); -export default async function loadPlugins(onlyTheme = false) { +export default async function loadPlugins(loadOnlyTheme = false) { const plugins = await fsOperation(PLUGIN_DIR).lsDir(); const results = []; const failedPlugins = []; @@ -36,7 +36,7 @@ export default async function loadPlugins(onlyTheme = false) { let pluginsToLoad = []; const currentTheme = settings.value.appTheme; - if (onlyTheme) { + if (loadOnlyTheme) { // Only load theme plugins matching current theme pluginsToLoad = plugins.filter((pluginDir) => { const pluginId = Url.basename(pluginDir.url); @@ -54,7 +54,7 @@ export default async function loadPlugins(onlyTheme = false) { const loadPromises = pluginsToLoad.map(async (pluginDir) => { const pluginId = Url.basename(pluginDir.url); - if (onlyTheme && currentTheme) { + if (loadOnlyTheme && currentTheme) { const pluginIdLower = pluginId.toLowerCase(); const currentThemeLower = currentTheme.toLowerCase(); const matchFound = pluginIdLower.includes(currentThemeLower); @@ -104,7 +104,7 @@ async function cleanupFailedPlugins(pluginIds) { await fsOperation(pluginDir).delete(); } } catch (error) { - window.log("error", `Failed to cleanup plugin ${pluginId}:`, error); + console.error(`Failed to cleanup plugin ${pluginId}:`, error); } } }