aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/index.ts
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
committerVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
commitf60ccb766f30e7518bc348013b72f071f86ecbc6 (patch)
tree5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/plugins/index.ts
parentbac8a648b6012e221fd2150062d2080b9ed0d702 (diff)
downloadVencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.gz
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.bz2
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.zip
Add Plugin.start, make Settings actually start/stop plugins
Diffstat (limited to 'src/plugins/index.ts')
-rw-r--r--src/plugins/index.ts43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/plugins/index.ts b/src/plugins/index.ts
index ae67f4f..448d247 100644
--- a/src/plugins/index.ts
+++ b/src/plugins/index.ts
@@ -1,7 +1,7 @@
import Plugins from "plugins";
import { Settings } from "../api/settings";
import Logger from "../utils/logger";
-import { Patch } from "../utils/types";
+import { Patch, Plugin } from "../utils/types";
const logger = new Logger("PluginManager", "#a6d189");
@@ -17,12 +17,43 @@ for (const plugin of Plugins) if (plugin.patches && Settings.plugins[plugin.name
}
export function startAll() {
- for (const plugin of plugins) if (plugin.start && Settings.plugins[plugin.name].enabled) {
+ for (const plugin of plugins) if (Settings.plugins[plugin.name].enabled) {
+ startPlugin(plugin);
+ }
+}
+
+export function startPlugin(p: Plugin) {
+ if (p.start) {
+ logger.info("Starting plugin", p.name);
+ if (p.started) {
+ logger.warn(`${p.name} already started`);
+ return false;
+ }
+ try {
+ p.start();
+ p.started = true;
+ return true;
+ } catch (err: any) {
+ logger.error(`Failed to start ${p.name}\n`, err);
+ return false;
+ }
+ }
+}
+
+export function stopPlugin(p: Plugin) {
+ if (p.stop) {
+ logger.info("Stopping plugin", p.name);
+ if (!p.started) {
+ logger.warn(`${p.name} already stopped / never started`);
+ return false;
+ }
try {
- logger.info("Starting plugin", plugin.name);
- plugin.start();
- } catch (err) {
- logger.error("Failed to start plugin", plugin.name, err);
+ p.stop();
+ p.started = false;
+ return true;
+ } catch (err: any) {
+ logger.error(`Failed to stop ${p.name}\n`, err);
+ return false;
}
}
} \ No newline at end of file