-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathupdater.js
More file actions
49 lines (43 loc) · 1.4 KB
/
updater.js
File metadata and controls
49 lines (43 loc) · 1.4 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 wrap from 'src/utils/2.pokemon.js';
import { registerModule } from 'src/utils/plugin.js';
import { registerPlugin } from 'src/hooks/updates.js';
import * as settings from 'src/utils/settings/index.js';
import Translation from 'src/structures/constants/translation.ts';
const text = Translation.Setting('update.plugin');
const setting = settings.register({
name: text,
key: 'underscript.disable.plugins.update',
category: 'Plugins',
});
wrap(() => {
const name = 'updater';
function mod(plugin) {
if (!plugin.version) return undefined;
let updater = false;
const update = plugin.settings().add({
name: text,
key: 'plugin.update',
default: () => setting.value(),
disabled: () => setting.value(),
hidden: () => !updater,
});
setting.on(() => update.refresh());
Object.defineProperty(plugin, 'canUpdate', {
get: () => updater && !setting.value() && !update.value(),
});
return (data = {}) => {
if (!['string', 'object'].includes(typeof data)) throw new Error();
if (updater) throw new Error('Already registered');
const {
downloadURL = typeof data === 'string' ? data : undefined,
updateURL,
} = data;
updater = registerPlugin(plugin, { downloadURL, updateURL });
return () => {
updater();
updater = false;
};
};
}
registerModule(name, mod, 'events', 'settings');
});