-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprefs.js
104 lines (83 loc) · 3.83 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
import Adw from "gi://Adw";
import Gtk from "gi://Gtk";
import Gio from "gi://Gio";
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
function getNoAppsRow() {
return new Adw.ActionRow({ title: _("No hidden apps") });
}
class GnomeAppHiderExtensionPrefs extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings();
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup();
page.add(group);
const hiddenApps = settings.get_strv("hidden-apps");
let hiddenSearchApps = settings.get_strv("hidden-search-apps");
if (hiddenApps.length === 0) {
group.add(getNoAppsRow());
} else {
for (const appId of hiddenApps) {
const appInfo = Gio.DesktopAppInfo.new(appId);
let row;
if (appInfo == null) {
console.error(`Could not find app info for app with id ${appId}`);
row = new Adw.ActionRow({
icon_name: "application-x-executable",
title: appId,
subtitle: _("Missing app info"),
});
} else {
const appIcon = appInfo.get_icon() == null ? "application-x-executable" : appInfo.get_icon().to_string();
row = new Adw.ActionRow({
icon_name: appIcon,
title: appInfo.get_name(),
subtitle: appInfo.get_description(),
});
}
const button = new Gtk.Button({
icon_name: "edit-delete-symbolic",
tooltip_text: _("Unhide"),
});
button.connect("clicked", (self) => {
const index = hiddenApps.indexOf(appId);
if (index > -1) {
hiddenApps.splice(index, 1);
}
settings.set_strv("hidden-apps", hiddenApps);
group.remove(row);
if (hiddenApps.length === 0) {
group.add(getNoAppsRow());
}
});
const tooltip_text = hiddenSearchApps.includes(appId) ? _("Unhide from search") : _("Hide from search");
const hideSearchButton = new Gtk.Button({
icon_name: hiddenSearchApps.includes(appId) ? "edit-clear-symbolic" : "system-search-symbolic",
tooltip_text,
});
hideSearchButton.connect("clicked", (self) => {
const index = hiddenSearchApps.indexOf(appId);
if (index > -1) {
hiddenSearchApps.splice(index, 1);
} else {
hiddenSearchApps.push(appId);
}
settings.set_strv("hidden-search-apps", hiddenSearchApps);
hideSearchButton.set_icon_name(hiddenSearchApps.includes(appId) ? "edit-clear-symbolic" : "system-search-symbolic");
hideSearchButton.set_tooltip_text(tooltip_text);
});
const buttonBox = new Gtk.Box({
orientation: Gtk.Orientation.HORIZONTAL,
spacing: 6,
margin_top: 8,
margin_bottom: 8,
});
buttonBox.append(hideSearchButton);
buttonBox.append(button);
row.add_suffix(buttonBox);
group.add(row);
}
}
window.add(page);
}
}
export default GnomeAppHiderExtensionPrefs;