-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsettings.js
More file actions
49 lines (44 loc) · 1.36 KB
/
settings.js
File metadata and controls
49 lines (44 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as settings from 'src/utils/settings/index.js';
import wrap from 'src/utils/2.pokemon.js';
import { registerModule } from 'src/utils/plugin.js';
import SettingType from 'src/utils/settings/types/setting.js';
wrap(() => {
const name = 'settings';
function add(plugin) {
const prefix = `underscript.plugin.${plugin.name}`;
return (data = {}) => {
if (!data.key) throw new Error('Key must be provided');
const setting = {
...data,
key: `${prefix}.${data.key}`,
name: data.name || data.key,
page: plugin,
};
return settings.register(setting);
};
}
function mod(plugin) {
const obj = {
add: add(plugin),
on: (...args) => settings.on(...args),
open: () => settings.open(plugin),
isOpen: () => settings.isOpen(),
addType(type) {
if (!(type instanceof SettingType)) {
plugin.logger.error('SettingType: Attempted to register object of:', typeof type);
return;
}
if (!type.name.startsWith(`${plugin.name}:`)) {
type.name = `${plugin.name}:${type.name}`;
}
settings.registerType(type, plugin.addStyle);
},
value(key) {
if (!settings.exists(key)) return undefined;
return settings.value(key);
},
};
return () => Object.freeze(obj);
}
registerModule(name, mod);
});