-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.js
More file actions
46 lines (37 loc) · 1.17 KB
/
extension.js
File metadata and controls
46 lines (37 loc) · 1.17 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
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import Gio from 'gi://Gio';
const SCHEDULER_INTERFACE = '<node> \
<interface name="com.system76.Scheduler"> \
<method name="SetForegroundProcess"> \
<arg name="pid" type="u" direction="in" /> \
</method> \
</interface> \
</node> \
';
const SchedulerProxy = Gio.DBusProxy.makeProxyWrapper(SCHEDULER_INTERFACE);
const schedulerProxy = new SchedulerProxy(Gio.DBus.system, 'com.system76.Scheduler', '/com/system76/Scheduler');
export default class System76SchedulerExtension extends Extension {
enable() {
this._foreground = 0;
this._handler = global.display.connect('notify::focus-window', () => {
const meta_window = global.display.get_focus_window();
if (!meta_window) {
return;
}
const pid = meta_window.get_pid();
if (!pid || pid === this._foreground) {
return;
}
this._foreground = pid;
schedulerProxy.SetForegroundProcessRemote(pid, (result, error) => {
if (!error) {
return;
}
logError(error);
});
});
}
disable() {
global.display.disconnect(this._handler);
}
}