forked from bdaase/noannoyance
-
Notifications
You must be signed in to change notification settings - Fork 7
/
extension.js
65 lines (52 loc) · 1.81 KB
/
extension.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import { Extension } from "resource:///org/gnome/shell/extensions/extension.js";
import Gio from "gi://Gio";
export default class NoAnnoyance extends Extension {
constructor(metadata) {
super(metadata);
this._settings = null;
this._blocklist = null;
this._settingsChangedId = null;
}
enable() {
console.debug("[NoAnnoyance] Disabling 'Window Is Ready' Notification");
this._settings = this.getSettings();
this._onSettingsChanged(); // Load the settings for the first time.
this._windowDemandsAttentionId = global.display.connect(
"window-demands-attention",
this._onWindowDemandsAttention.bind(this)
);
this._windowMarkedUrgentId = global.display.connect(
"window-marked-urgent",
this._onWindowDemandsAttention.bind(this)
);
this._settingsChangedId = this._settings.connect(
"changed::blocklist",
this._onSettingsChanged.bind(this)
);
}
disable() {
console.debug("[NoAnnoyance] Enabling 'Window Is Ready' Notification");
global.display.disconnect(this._windowDemandsAttentionId);
global.display.disconnect(this._windowMarkedUrgentId);
if (this._settingsChangedId) {
this._settings.disconnect(this._settingsChangedId);
this._settingsChangedId = null;
}
this._settings = null;
this._blocklist = null;
}
_onWindowDemandsAttention(display, window) {
if (!window || window.has_focus() || window.is_skip_taskbar()) return;
if (!this._blocklist.has(window.get_wm_class())) {
Main.activateWindow(window);
}
}
_onSettingsChanged() {
this._blocklist = new Set(this._settings.get_strv("blocklist"));
console.debug(
"[NoAnnoyance] Updating blocklist:",
Array.from(this._blocklist).join(", ")
);
}
}