-
Notifications
You must be signed in to change notification settings - Fork 23
/
prefs.js
161 lines (149 loc) · 4.61 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"use strict";
import Gio from "gi://Gio";
import Gtk from "gi://Gtk";
import GObject from "gi://GObject";
import Adw from "gi://Adw";
import Gst from "gi://Gst";
import GstAudio from "gi://GstAudio";
import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
const KeyValuePair = GObject.registerClass(
{
Properties: {
key: GObject.ParamSpec.string(
"key",
null,
null,
GObject.ParamFlags.READWRITE,
"",
),
value: GObject.ParamSpec.string(
"value",
"Value",
"Value",
GObject.ParamFlags.READWRITE,
"",
),
},
},
class KeyValuePair extends GObject.Object {},
);
export default class extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings();
const page = new Adw.PreferencesPage({
icon_name: "dialog-information-symbolic",
});
window.add(page);
let group = new Adw.PreferencesGroup({
title: "Keybindings",
description: "Keybindings for muting and unmuting",
});
page.add(group);
// keybinding row
group.add(
(() => {
const accel =
settings.get_strv("keybinding-toggle-mute")[0] || "<Alt>backslash";
const keybindingsRow = new Adw.EntryRow({
title: "Mute/Unmute",
show_apply_button: true,
text: accel,
});
const resetButton = new Gtk.Button({
icon_name: "edit-clear-symbolic",
tooltip_text: "Reset to default",
valign: Gtk.Align.CENTER,
});
resetButton.connect("clicked", () => {
settings.reset("keybinding-toggle-mute");
keybindingsRow.text =
settings.get_strv("keybinding-toggle-mute")[0] || "<Alt>backslash";
});
keybindingsRow.add_suffix(resetButton);
keybindingsRow.connect("apply", () => {
settings.set_strv("keybinding-toggle-mute", [keybindingsRow.text]);
});
return keybindingsRow;
})(),
);
group = new Adw.PreferencesGroup({
title: "Other",
});
page.add(group);
// top bar icon row
group.add(
(() => {
const model = new Gio.ListStore({ item_type: KeyValuePair });
model.splice(0, 0, [
new KeyValuePair({ key: "when-recording", value: "When recording" }),
new KeyValuePair({ key: "always", value: "Always" }),
new KeyValuePair({ key: "never", value: "Never" }),
]);
const iconVisibleComboBox = new Adw.ComboRow({
title: "Top bar icon",
subtitle: "Whether to show top bar icon",
model: model,
expression: new Gtk.PropertyExpression(KeyValuePair, null, "value"),
});
for (let i = 0; i < model.n_items; i++) {
if (
model.get_item(i).key ===
settings.get_string("icon-visibility", "when-recording")
) {
iconVisibleComboBox.selected = i;
break;
}
}
iconVisibleComboBox.connect("notify::selected-item", () => {
const selected_item = iconVisibleComboBox.selected_item;
if (selected_item) {
settings.set_string("icon-visibility", selected_item.key);
}
});
settings.bind(
"icon-visibility",
iconVisibleComboBox,
"active-id",
Gio.SettingsBindFlags.DEFAULT,
);
return iconVisibleComboBox;
})(),
);
// osd row
const toggleOSD = new Adw.SwitchRow({
title: "OSD notification",
subtitle: "Whether to show OSD notification",
});
settings.bind(
"show-osd",
toggleOSD,
"active",
Gio.SettingsBindFlags.DEFAULT,
);
group.add(toggleOSD);
// sound notification row
const feedbackSoundsSwitch = new Adw.SwitchRow({
title: "Sound notification",
subtitle: "Play sound when muting and unmuting",
});
settings.bind(
"play-feedback-sounds",
feedbackSoundsSwitch,
"active",
Gio.SettingsBindFlags.DEFAULT,
);
group.add(feedbackSoundsSwitch);
// no sound alert row
const isPlayingSoundSupported = Gst != null && GstAudio != null;
if (!isPlayingSoundSupported) {
const playingSoundNotSupportedLabel = new Gtk.Label({
halign: Gtk.Align.START,
});
playingSoundNotSupportedLabel.set_markup(
"<span foreground='red'>WARNING. Playing sound is not supported on this system. Is GStreamer package installed?</span>",
);
playingSoundNotSupportedLabel.set_wrap(true);
group.add(playingSoundNotSupportedLabel);
}
}
}