[Plugins] Normalize ID in anything that uses them
This commit is contained in:
parent
6ed08a0ac9
commit
cfccd5f5b2
1 changed files with 5 additions and 1 deletions
|
@ -49,6 +49,7 @@ export async function fetchPlugin(id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installPlugin(id: string, enabled = true) {
|
export async function installPlugin(id: string, enabled = true) {
|
||||||
|
if (!id.endsWith("/")) id += "/";
|
||||||
if (typeof id !== "string" || id in plugins) throw new Error("Plugin already installed");
|
if (typeof id !== "string" || id in plugins) throw new Error("Plugin already installed");
|
||||||
await fetchPlugin(id);
|
await fetchPlugin(id);
|
||||||
if (enabled) await startPlugin(id);
|
if (enabled) await startPlugin(id);
|
||||||
|
@ -71,6 +72,7 @@ export async function evalPlugin(plugin: Plugin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startPlugin(id: string) {
|
export async function startPlugin(id: string) {
|
||||||
|
if (!id.endsWith("/")) id += "/";
|
||||||
const plugin = plugins[id];
|
const plugin = plugins[id];
|
||||||
if (!plugin) throw new Error("Attempted to start non-existent plugin");
|
if (!plugin) throw new Error("Attempted to start non-existent plugin");
|
||||||
|
|
||||||
|
@ -94,6 +96,7 @@ export async function startPlugin(id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopPlugin(id: string, disable = true) {
|
export function stopPlugin(id: string, disable = true) {
|
||||||
|
if (!id.endsWith("/")) id += "/";
|
||||||
const plugin = plugins[id];
|
const plugin = plugins[id];
|
||||||
const pluginRet = loadedPlugins[id];
|
const pluginRet = loadedPlugins[id];
|
||||||
if (!plugin) throw new Error("Attempted to stop non-existent plugin");
|
if (!plugin) throw new Error("Attempted to stop non-existent plugin");
|
||||||
|
@ -110,6 +113,7 @@ export function stopPlugin(id: string, disable = true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removePlugin(id: string) {
|
export function removePlugin(id: string) {
|
||||||
|
if (!id.endsWith("/")) id += "/";
|
||||||
const plugin = plugins[id];
|
const plugin = plugins[id];
|
||||||
if (plugin.enabled) stopPlugin(id);
|
if (plugin.enabled) stopPlugin(id);
|
||||||
delete plugins[id];
|
delete plugins[id];
|
||||||
|
@ -127,4 +131,4 @@ export async function initPlugins() {
|
||||||
|
|
||||||
const stopAllPlugins = () => Object.keys(loadedPlugins).forEach(p => stopPlugin(p, false));
|
const stopAllPlugins = () => Object.keys(loadedPlugins).forEach(p => stopPlugin(p, false));
|
||||||
|
|
||||||
export const getSettings = (id: string) => loadedPlugins[id]?.settings;
|
export const getSettings = (id: string) => loadedPlugins[id]?.settings;
|
||||||
|
|
Loading…
Reference in a new issue