Skip to content

Commit 99beccd

Browse files
Merge branch 'Acode-Foundation:main' into main
2 parents dfa1625 + df55be6 commit 99beccd

3 files changed

Lines changed: 73 additions & 56 deletions

File tree

src/lib/editorFile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import helpers from "utils/helpers";
2222
import Path from "utils/Path";
2323
import Url from "utils/Url";
2424
import config from "./config";
25+
import { isInitialPluginLoadComplete } from "./loadPlugins";
2526
import openFolder from "./openFolder";
2627
import run from "./run";
2728
import saveFile from "./saveFile";
@@ -229,6 +230,7 @@ function createSessionProxy(state, file) {
229230

230231
function maybeRecommendLanguageModeExtension(file, modeInfo) {
231232
if (appSettings.value.recommendExtensions === false) return;
233+
if (!isInitialPluginLoadComplete()) return;
232234
if (modeInfo?.name !== "text" || modeInfo.supportsFile(file.filename)) return;
233235

234236
void import("./languageModeRecommendations").then(

src/lib/loadPlugins.js

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const AUTO_DISABLED_PLUGINS = new Set();
3636
const PLUGIN_LOAD_TIMEOUT = 15000;
3737
const PLUGIN_DISABLE_TIMEOUT = 60000;
3838
let pluginDisabledUpdateQueue = Promise.resolve();
39+
let initialPluginLoadComplete = false;
3940

4041
class PluginLoadTimeoutError extends Error {
4142
constructor() {
@@ -45,70 +46,84 @@ class PluginLoadTimeoutError extends Error {
4546
}
4647

4748
export default async function loadPlugins(loadOnlyTheme = false) {
48-
const plugins = await fsOperation(PLUGIN_DIR).lsDir();
49-
const results = [];
50-
51-
if (plugins.length > 0) {
52-
toast(strings["loading plugins"]);
49+
if (!loadOnlyTheme) {
50+
initialPluginLoadComplete = false;
5351
}
5452

55-
let pluginsToLoad = [];
56-
const currentTheme = settings.value.appTheme;
57-
const enabledMap = settings.value.pluginsDisabled || {};
53+
try {
54+
const plugins = await fsOperation(PLUGIN_DIR).lsDir();
55+
const results = [];
5856

59-
if (loadOnlyTheme) {
60-
// Only load theme plugins matching current theme
61-
pluginsToLoad = plugins.filter((pluginDir) => {
62-
const pluginId = Url.basename(pluginDir.url);
63-
// Skip already loaded and plugins that were previously marked broken
64-
return (
65-
isThemePlugin(pluginId) &&
66-
!LOADED_PLUGINS.has(pluginId) &&
67-
enabledMap[pluginId] !== true &&
68-
!BROKEN_PLUGINS.has(pluginId)
69-
);
70-
});
71-
} else {
72-
// Load non-theme plugins that aren't loaded yet and are enabled
73-
pluginsToLoad = plugins.filter((pluginDir) => {
57+
if (plugins.length > 0) {
58+
toast(strings["loading plugins"]);
59+
}
60+
61+
let pluginsToLoad = [];
62+
const currentTheme = settings.value.appTheme;
63+
const enabledMap = settings.value.pluginsDisabled || {};
64+
65+
if (loadOnlyTheme) {
66+
// Only load theme plugins matching current theme
67+
pluginsToLoad = plugins.filter((pluginDir) => {
68+
const pluginId = Url.basename(pluginDir.url);
69+
// Skip already loaded and plugins that were previously marked broken
70+
return (
71+
isThemePlugin(pluginId) &&
72+
!LOADED_PLUGINS.has(pluginId) &&
73+
enabledMap[pluginId] !== true &&
74+
!BROKEN_PLUGINS.has(pluginId)
75+
);
76+
});
77+
} else {
78+
// Load non-theme plugins that aren't loaded yet and are enabled
79+
pluginsToLoad = plugins.filter((pluginDir) => {
80+
const pluginId = Url.basename(pluginDir.url);
81+
// Skip theme plugins, already loaded, disabled or previously marked broken
82+
return (
83+
!isThemePlugin(pluginId) &&
84+
!LOADED_PLUGINS.has(pluginId) &&
85+
enabledMap[pluginId] !== true &&
86+
!BROKEN_PLUGINS.has(pluginId)
87+
);
88+
});
89+
}
90+
91+
const loadPromises = pluginsToLoad.map(async (pluginDir) => {
7492
const pluginId = Url.basename(pluginDir.url);
75-
// Skip theme plugins, already loaded, disabled or previously marked broken
76-
return (
77-
!isThemePlugin(pluginId) &&
78-
!LOADED_PLUGINS.has(pluginId) &&
79-
enabledMap[pluginId] !== true &&
80-
!BROKEN_PLUGINS.has(pluginId)
81-
);
82-
});
83-
}
8493

85-
const loadPromises = pluginsToLoad.map(async (pluginDir) => {
86-
const pluginId = Url.basename(pluginDir.url);
87-
88-
if (loadOnlyTheme && currentTheme) {
89-
const pluginIdLower = pluginId.toLowerCase();
90-
const currentThemeLower = currentTheme.toLowerCase();
91-
const matchFound = pluginIdLower.includes(currentThemeLower);
92-
// Skip if:
93-
// 1. No match found with current theme AND
94-
// 2. It's not a theme plugin at all
95-
if (!matchFound && !isThemePlugin(pluginId)) {
96-
return;
94+
if (loadOnlyTheme && currentTheme) {
95+
const pluginIdLower = pluginId.toLowerCase();
96+
const currentThemeLower = currentTheme.toLowerCase();
97+
const matchFound = pluginIdLower.includes(currentThemeLower);
98+
// Skip if:
99+
// 1. No match found with current theme AND
100+
// 2. It's not a theme plugin at all
101+
if (!matchFound && !isThemePlugin(pluginId)) {
102+
return;
103+
}
97104
}
98-
}
99105

100-
try {
101-
results.push(await loadPluginWithTimeout(pluginId));
102-
} catch (error) {
103-
console.error(`Error loading plugin ${pluginId}:`, error);
104-
results.push(false);
105-
}
106-
});
106+
try {
107+
results.push(await loadPluginWithTimeout(pluginId));
108+
} catch (error) {
109+
console.error(`Error loading plugin ${pluginId}:`, error);
110+
results.push(false);
111+
}
112+
});
113+
114+
await Promise.allSettled(loadPromises);
107115

108-
await Promise.allSettled(loadPromises);
116+
acode[onPluginsLoadCompleteCallback]();
117+
return results.filter(Boolean).length;
118+
} finally {
119+
if (!loadOnlyTheme) {
120+
initialPluginLoadComplete = true;
121+
}
122+
}
123+
}
109124

110-
acode[onPluginsLoadCompleteCallback]();
111-
return results.filter(Boolean).length;
125+
export function isInitialPluginLoadComplete() {
126+
return initialPluginLoadComplete;
112127
}
113128

114129
export async function loadPluginWithTimeout(pluginId, justInstalled = false) {

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ async function onDeviceReady() {
297297
const { activeFile } = editorManager;
298298
for (const file of editorManager.files) {
299299
if (file?.type === "editor") {
300-
file.setMode(undefined, { recommend: false });
300+
file.setMode();
301301
}
302302
}
303303
editorManager.reapplyActiveFile();

0 commit comments

Comments
 (0)