pushing some last WIP changes before deprecation

master
Drake 2 years ago
parent a694bb1f60
commit 17c6bfd336

@ -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<any>) => 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];
};
}

@ -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<boolean> {
@ -80,7 +81,7 @@ async function startPlugin(name: string): Promise<boolean> {
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<boolean> {
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;

@ -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);

@ -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<void> {
const patcher = new Patcher();
@ -38,11 +38,8 @@ async function init(obj: Object): Promise<void> {
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);
}

Loading…
Cancel
Save