diff --git a/src/api/commands.js b/src/api/commands.js index a3d7fa1..7259728 100644 --- a/src/api/commands.js +++ b/src/api/commands.js @@ -1,16 +1,18 @@ // @flow - const commandsSym = Symbol("__commands"); function init(obj: Object) { - obj.demon[commandsSym] = {}; - obj.demon.patcher.after( + const { after } = window.demon.require("patcher") + const { findByProps } = window.demon.require("webpack") + window.demonCommands = {} + window.demonCommands[commandsSym] = {}; + after( "sendMessage", - obj.demon.webpack.findByProps("sendMessage"), + findByProps("sendMessage"), (args, otherRes) => { let res; - for (const key of Reflect.ownKeys(obj.demon[commandsSym])) { - let command = obj.demon[commandsSym][key]; + for (const key of Reflect.ownKeys(window.demonCommands[commandsSym])) { + let command = window.demonCommands[commandsSym][key]; if (args[1].content.split(" ")[0] === ">" + command.name) { res = command.callback(args); break; @@ -31,9 +33,9 @@ function add(command: { callback: (args: Array) => string }): () => void { let sym = Symbol(command.name); - window.demon[commandsSym][sym] = command; + window.demonCommands[commandsSym][sym] = command; return () => { - delete window.demon[commandsSym][sym]; + delete window.demonCommands[commandsSym][sym]; }; } diff --git a/src/api/plugins.js b/src/api/plugins.js index af3e0a5..20cc1dd 100644 --- a/src/api/plugins.js +++ b/src/api/plugins.js @@ -3,6 +3,7 @@ import { get, set } from "idb-keyval"; import logger from "./utils/logger.js"; import settingsInj from "./settings/settingsInj.js"; +window.demonPlugins = {} //TODO: jank const pluginsSym = Symbol("__plugins"); async function init(obj: Object): Promise { @@ -80,7 +81,7 @@ async function startPlugin(name: string): Promise { exports.settings ); logger.log(`Started ${name}!`, ["Plugins"]); - window.demon[pluginsSym][name] = { status: 1, ctx: ctx }; + window.demonPlugins[pluginsSym][name] = { status: 1, ctx: ctx }; return true; } } @@ -97,7 +98,7 @@ async function stopPlugin(name: string): Promise { const plug = globalSettings["plugin"][name]; const exports: Object = (0, eval)(plug.iife); const onStop: (ctx: Object) => void = exports.onStop; - onStop(window.demon[pluginsSym][name].ctx); + onStop(window.demonPlugins[pluginsSym][name].ctx); settingsInj.unregisterSettingsEntry("DEMON_PLUGIN_SETTINGS_" + name); logger.log(`Stopped ${name}!`, ["Plugins"]); return true; diff --git a/src/index.js b/src/index.js index 56f149e..2033818 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ // @flow import init from "./init.js"; import settingsInj from "./api/settings/settingsInj"; +import commands from "./api/commands"; const obj = {}; @@ -30,3 +31,4 @@ window.demon.require = (mod: String): Object => { }; settingsInj.init(); +commands.init(obj); diff --git a/src/init.js b/src/init.js index c136a48..bfa144e 100644 --- a/src/init.js +++ b/src/init.js @@ -2,10 +2,10 @@ import Patcher from "simian"; import webpack from "./api/webpack"; import common from "./api/common"; -import commands from "./api/commands"; import plugins from "./api/plugins"; import settings from "./api/settings/settings"; import css from "./api/css"; +import commands from "./api/commands"; async function init(obj: Object): Promise { const patcher = new Patcher(); @@ -38,11 +38,8 @@ async function init(obj: Object): Promise { commands: { add: commands.add }, - __DO_NOT_USE_OR_YOU_WILL_BE_FIRED_UNTO_THE_DEPTHS_OF_HELL: { - plugins - } + plugins }; - commands.init(obj); plugins.init(obj); css.init(obj); }