[PCCompat] Rewrite to use seperate global dir and object, other structural changes

This commit is contained in:
Ducko 2021-04-07 16:56:51 +01:00 committed by フズキ
parent 2584ce03c5
commit 61c94f40d3
No known key found for this signature in database
GPG key ID: E06450E46F83376C
8 changed files with 130 additions and 126 deletions

View file

@ -0,0 +1,33 @@
const sendMessage = goosemodScope.webpackModules.findByProps('sendMessage', 'receiveMessage').sendMessage;
const getChannelId = goosemod.webpackModules.findByProps('getChannelId').getChannelId;
export const registerCommand = ({ command, alias, description, usage, executor }) => {
// TODO: implement alias
goosemodScope.patcher.commands.add(command, description,
async ( { args: [ { text } ] } ) => {
const out = await executor(text.split(' ')); // Run original executor func (await incase it's an async function)
if (!out.send) {
goosemodScope.patcher.internalMessage(out.result); // PC impl. sends internal message when out.send === false, so we also do the same via our previous Patcher API function
return;
}
// When send is true, we send it as a message via sendMessage
sendMessage(getChannelId(), {
content: out.result,
tts: false,
invalidEmojis: [],
validNonShortcutEmojis: []
});
}, [
{ type: 3, required: false, name: 'args', description: 'Arguments for PC command' } // Argument for any string for compat. with PC's classical commands
]);
};
export const unregisterCommand = (command) => {
goosemodScope.patcher.commands.remove(command);
};

View file

@ -0,0 +1,11 @@
import * as commands from './commands.js';
import * as notices from './notices.js';
import * as settings from './settings.js';
export default {
api: {
commands,
notices,
settings
}
};

View file

@ -0,0 +1,5 @@
export const sendToast = (_id, { header, content, type, buttons }) => {
// TODO: implement full toast in future instead of just small current GM toast
goosemodScope.showToast(content);
};

View file

@ -0,0 +1,39 @@
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) => {
if (!sections.find(c => c.section === 'changelog')) return sections;
const dividers = sections.filter(c => c.section === 'DIVIDER');
const finalLabel = typeof label === 'function' ? label() : label;
sections.splice(sections.indexOf(dividers[dividers.length - 2]) - 2, 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);
};