forked from jirkavrba/noannoyance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
108 lines (85 loc) · 2.96 KB
/
prefs.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
import GObject from "gi://GObject";
import Adw from "gi://Adw";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
const BLOCKLIST_KEY = "blocklist";
export default class Preferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
let settings = this.getSettings();
const page = new Adw.PreferencesPage({
title: "General",
icon_name: "dialog-information-symbolic",
});
const group = new Adw.PreferencesGroup({
title: "Ignored Apps",
description:
"Some apps try to grab your attention too often. Block them here!",
});
page.add(group);
const originalBlocklist = settings.get_strv(BLOCKLIST_KEY);
const newBlocklist = new Set(originalBlocklist);
const updateBlocklist = () => {
const newBlocklistArr = Array.from(newBlocklist);
newBlocklistArr.sort();
settings.set_strv(BLOCKLIST_KEY, newBlocklistArr);
};
const addRow = (value, isNew) => {
const row = new Adw.ActionRow({
title: value,
});
if (isNew) newBlocklist.add(value);
const removeButton = new Gtk.Button({
icon_name: "user-trash-symbolic",
});
removeButton.get_style_context().add_class("flat");
row.add_suffix(removeButton);
group.add(row);
removeButton.connect("clicked", () => {
group.remove(row);
newBlocklist.delete(row.title);
updateBlocklist();
});
};
const addOldRow = (value) => {
addRow(value, false);
};
const addNewRow = (value) => {
addRow(value, true);
};
originalBlocklist.forEach(addOldRow);
const addByWmClass = () => {
const dialog = new Adw.MessageDialog({
transient_for: window,
modal: true,
});
dialog.set_heading("Enter WM__CLASS");
dialog.set_body("If you need help finding the WM__CLASS, press \"Alt + F2\", run \"lg\" in the run opened window, and then click \"Windows\" and search for the 'WM_CLASS' of the apps you want to ignore.");
const entry = new Adw.EntryRow();
entry.set_title('WM_CLASS to ignore');
dialog.set_extra_child(entry);
dialog.add_response("cancel", "Cancel");
dialog.add_response("add", "Add");
dialog.set_default_response("add");
dialog.set_response_appearance("add", Adw.ResponseAppearance.SUGGESTED);
dialog.connect("response", (dialog, response) => {
if (response === "add") {
const text = entry.get_text();
if (text) {
addNewRow(text);
updateBlocklist();
}
}
dialog.destroy();
});
dialog.show();
};
const byRawEnter = new Gtk.Button({
icon_name: "window-new-symbolic",
});
byRawEnter.get_style_context().add_class("flat");
byRawEnter.connect("clicked", addByWmClass);
group.set_header_suffix(byRawEnter);
window.add(page);
}
}