-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoduleManager.js
42 lines (34 loc) · 863 Bytes
/
moduleManager.js
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
class ModuleManager {
constructor() {
this.panel = null;
this.config = null;
this.module = null;
this.cleanup = this.cleanup.bind(this);
}
async init(ModuleClass) {
this.cleanup();
this.module = new ModuleClass();
if (this.module.config) {
this.panel = new ConfigPanel(this.module.config, () => {
if (this.module.onConfigUpdate) {
this.module.onConfigUpdate();
}
});
}
if (this.module.init) {
await this.module.init();
}
window.addEventListener('beforeunload', this.cleanup);
}
cleanup() {
if (this.panel) {
this.panel.destroy();
this.panel = null;
}
if (this.module && this.module.cleanup) {
this.module.cleanup();
}
window.removeEventListener('beforeunload', this.cleanup);
}
}
window.ModuleManager = ModuleManager;