mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-23 04:46:08 -08:00
feat(plugins): add JavaScript plugin system with overlay panel (#303)
This commit is contained in:
1 parent
90fc7cf940
commit
a9a4c4f083
110 files changed
+5897
-344
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { ResolveContext } from './context';
|
||||
import { isObject } from './shared';
|
||||
|
||||
/** Keeps well-formed `plugins.<id>` entries; ids are validated again when the plugin loads. */
|
||||
export function applyPluginsConfig(context: ResolveContext): void {
|
||||
const { src, resolved, warn } = context;
|
||||
if (src.plugins === undefined) return;
|
||||
if (!isObject(src.plugins)) {
|
||||
warn('plugins', src.plugins, resolved.plugins, 'Expected object keyed by plugin id.');
|
||||
return;
|
||||
}
|
||||
|
||||
for (const [id, entry] of Object.entries(src.plugins)) {
|
||||
const path = `plugins.${id}`;
|
||||
if (!isObject(entry)) {
|
||||
warn(path, entry, undefined, 'Expected { "enabled": boolean, "settings"?: object }.');
|
||||
continue;
|
||||
}
|
||||
if (entry.enabled !== undefined && typeof entry.enabled !== 'boolean') {
|
||||
warn(`${path}.enabled`, entry.enabled, false, 'Expected boolean.');
|
||||
}
|
||||
if (entry.settings !== undefined && !isObject(entry.settings)) {
|
||||
warn(`${path}.settings`, entry.settings, {}, 'Expected object.');
|
||||
}
|
||||
resolved.plugins[id] = {
|
||||
enabled: entry.enabled === true,
|
||||
settings: isObject(entry.settings) ? { ...entry.settings } : {},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user