You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

// @flow
import webpack from "./webpack";
const settingsSym = Symbol("__settings");
const settingsView = webpack.find(m => m.default && m.default.displayName === "SettingsView");
type getPredicateSectionsEntry =
| {
section: "HEADER",
label: string,
}
| {
section: "DIVIDER",
}
| {
section: string,
label: string,
component: Function,
};
function patch(args: mixed, ret: getPredicateSectionsEntry[]) {
const processedEntries = window.demon[settingsSym].entries.map((e) => ({
section: "DEMON_SETTINGS_LOADER_" + e.name,
label: e.name,
element: e.component,
}));
const injectionIndex =
2 + ret.findIndex((section) => section.section === "Game Activity");
ret.splice(
injectionIndex,
0,
{ section: "HEADER", label: "Demon" },
...processedEntries,
{ section: "DIVIDER" }
);
return ret;
}
function init() {
window.demon[settingsSym] = {
patch: window.demon.patcher.after(
"getPredicateSections",
settingsView.default.prototype,
patch
),
entries: [],
};
// debug
window.demonunpatch = window.demon[settingsSym].patch;
}
function unInit(obj: Object) {
window.demon[settingsSym].patch();
delete window.demon[settingsSym];
}
function unregisterSettingsEntry(name: string) {
let s = window.demon[settingsSym];
s.entries = s.entries.filter((e) => e.name !== name);
}
function registerSettingsEntry(name: string, component: Function): () => void {
window.demon[settingsSym].entries.push({ name, component });
return () => unregisterSettingsEntry(name);
}
export default { init, unInit, registerSettingsEntry, unregisterSettingsEntry };