mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 00:23:12 +09:00
Fix web interface breaking when disabling plugins
Fix incorrect logic to set up plugins in the web interface causing an emptry plugin to be atempted to be loaded when a plugin was disabled.
This commit is contained in:
1 parent
ddf15f9b92
commit
3e836c1dd3
1 file changed
+29
-12
@@ -25,7 +25,7 @@ async function loadScript(url) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPlugins() {
|
async function loadPluginInfos() {
|
||||||
let response = await fetch(`${webRoot}api/plugins`);
|
let response = await fetch(`${webRoot}api/plugins`);
|
||||||
let pluginList;
|
let pluginList;
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -36,7 +36,7 @@ async function loadPlugins() {
|
|||||||
pluginList = [];
|
pluginList = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
let plugins = new Map();
|
let pluginInfos = [];
|
||||||
await __webpack_init_sharing__("default");
|
await __webpack_init_sharing__("default");
|
||||||
for (let meta of pluginList) {
|
for (let meta of pluginList) {
|
||||||
if (meta.web.error) {
|
if (meta.web.error) {
|
||||||
@@ -51,26 +51,43 @@ async function loadPlugins() {
|
|||||||
}
|
}
|
||||||
await container.init(__webpack_share_scopes__.default);
|
await container.init(__webpack_share_scopes__.default);
|
||||||
let pluginInfo = (await container.get("./info"))();
|
let pluginInfo = (await container.get("./info"))();
|
||||||
let pluginPackage = (await container.get("./package.json"))();
|
pluginInfo.container = container;
|
||||||
|
pluginInfo.package = (await container.get("./package.json"))();
|
||||||
|
pluginInfo.enabled = meta.enabled;
|
||||||
|
pluginInfos.push(pluginInfo);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`Failed to load plugin info for ${meta.name}`);
|
||||||
|
if (err.stack) {
|
||||||
|
logger.error(err.stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pluginInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadPlugins(pluginInfos) {
|
||||||
|
let plugins = new Map();
|
||||||
|
for (let pluginInfo of pluginInfos) {
|
||||||
|
if (!pluginInfo.enabled) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
let WebPluginClass = libPlugin.BaseWebPlugin;
|
let WebPluginClass = libPlugin.BaseWebPlugin;
|
||||||
if (meta.enabled && pluginInfo.webEntrypoint) {
|
if (pluginInfo.webEntrypoint) {
|
||||||
let webModule = (await container.get(pluginInfo.webEntrypoint))();
|
let webModule = (await pluginInfo.container.get(pluginInfo.webEntrypoint))();
|
||||||
if (!webModule.WebPlugin) {
|
if (!webModule.WebPlugin) {
|
||||||
throw new Error("Plugin webEntrypoint does not export WebPlugin class");
|
throw new Error("Plugin webEntrypoint does not export WebPlugin class");
|
||||||
}
|
}
|
||||||
WebPluginClass = webModule.WebPlugin;
|
WebPluginClass = webModule.WebPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
let plugin = new WebPluginClass(container, pluginPackage, pluginInfo, logger);
|
let plugin = new WebPluginClass(pluginInfo.container, pluginInfo.package, pluginInfo, logger);
|
||||||
await plugin.init();
|
await plugin.init();
|
||||||
plugins.set(pluginInfo.name, plugin);
|
plugins.set(pluginInfo.name, plugin);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message) {
|
logger.error(`Failed to load plugin ${pluginInfo.name}`);
|
||||||
meta.web.error = err.message;
|
|
||||||
}
|
|
||||||
logger.error(`Failed to load plugin ${meta.name}`);
|
|
||||||
if (err.stack) {
|
if (err.stack) {
|
||||||
logger.error(err.stack);
|
logger.error(err.stack);
|
||||||
}
|
}
|
||||||
@@ -84,10 +101,10 @@ export default async function bootstrap() {
|
|||||||
level: "verbose",
|
level: "verbose",
|
||||||
format: new WebConsoleFormat(),
|
format: new WebConsoleFormat(),
|
||||||
}));
|
}));
|
||||||
let plugins = await loadPlugins();
|
let pluginInfos = await loadPluginInfos();
|
||||||
let pluginInfos = [...plugins.values()].map(p => p.info);
|
|
||||||
libConfig.registerPluginConfigGroups(pluginInfos);
|
libConfig.registerPluginConfigGroups(pluginInfos);
|
||||||
libConfig.finalizeConfigs();
|
libConfig.finalizeConfigs();
|
||||||
|
let plugins = await loadPlugins(pluginInfos);
|
||||||
|
|
||||||
let wsUrl = new URL(window.webRoot, document.location);
|
let wsUrl = new URL(window.webRoot, document.location);
|
||||||
wsUrl.protocol = wsUrl.protocol.replace("http", "ws");
|
wsUrl.protocol = wsUrl.protocol.replace("http", "ws");
|
||||||
|
|||||||
Reference in new issue
Block a user