mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
38 lines
No EOL
1.2 KiB
JavaScript
38 lines
No EOL
1.2 KiB
JavaScript
import * as Settings from '../util/settings';
|
|
|
|
export const registerSettings = (id, { label, render, category }) => {
|
|
const { React } = goosemodScope.webpackModules.common;
|
|
|
|
const SettingsView = goosemodScope.webpackModules.findByDisplayName('SettingsView');
|
|
|
|
const FormTitle = goosemodScope.webpackModules.findByDisplayName('FormTitle');
|
|
const FormSection = goosemodScope.webpackModules.findByDisplayName('FormSection');
|
|
|
|
goosemodScope.patcher.inject(id, SettingsView.prototype, 'getPredicateSections', (_, sections) => {
|
|
const logout = sections.find((c) => c.section === 'logout');
|
|
if (!logout) return sections;
|
|
|
|
const finalLabel = typeof label === 'function' ? label() : label;
|
|
|
|
sections.splice(sections.indexOf(logout) - 1, 0,
|
|
{
|
|
section: finalLabel,
|
|
label: finalLabel,
|
|
predicate: () => { },
|
|
element: () => React.createElement(FormSection, { },
|
|
React.createElement(FormTitle, { tag: 'h2' }, finalLabel),
|
|
|
|
render({
|
|
...Settings.settingStores[category]
|
|
})
|
|
)
|
|
}
|
|
);
|
|
|
|
return sections;
|
|
});
|
|
};
|
|
|
|
export const unregisterSettings = (id) => {
|
|
goosemodScope.patcher.uninject(id);
|
|
}; |