-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathextension.ts
85 lines (72 loc) · 2.75 KB
/
extension.ts
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*!
* Copyright (C) 2023 Lju
*
* This file is part of Astra Monitor extension for GNOME Shell.
* [https://github.com/AstraExt/astra-monitor]
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import GLib from 'gi://GLib';
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import AstraMonitorContainer from './src/container.js';
import Utils from './src/utils/utils.js';
import ProcessorMonitor from './src/processor/processorMonitor.js';
import GpuMonitor from './src/gpu/gpuMonitor.js';
import MemoryMonitor from './src/memory/memoryMonitor.js';
import StorageMonitor from './src/storage/storageMonitor.js';
import NetworkMonitor from './src/network/networkMonitor.js';
import SensorsMonitor from './src/sensors/sensorsMonitor.js';
export default class AstraMonitorExtension extends Extension {
private container?: InstanceType<typeof AstraMonitorContainer>;
private timeout: number = 0;
enable() {
Utils.init({
service: 'astra-monitor',
extension: this,
metadata: this.metadata,
settings: this.getSettings(),
ProcessorMonitor,
GpuMonitor,
MemoryMonitor,
StorageMonitor,
NetworkMonitor,
SensorsMonitor,
});
Utils.log('AstraMonitor enabled');
this.container = new AstraMonitorContainer();
// Startup delay to allow the initialization of the monitors
// avoiding graphical glitches / empty widgets
this.timeout = GLib.timeout_add(GLib.PRIORITY_DEFAULT, Utils.startupDelay * 1000, () => {
if(this.container) this.container.place(this.uuid);
this.timeout = 0;
Utils.ready = true;
return false;
});
}
disable() {
Utils.log('AstraMonitor disabled');
Utils.ready = false;
if(this.timeout !== 0) {
GLib.source_remove(this.timeout);
this.timeout = 0;
}
try {
this.container?.destroy();
} catch(e: any) {
Utils.error('Error destroying container', e);
}
this.container = undefined;
Utils.clear();
}
}