-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprefs.js
More file actions
422 lines (369 loc) · 13.8 KB
/
prefs.js
File metadata and controls
422 lines (369 loc) · 13.8 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';
import { ExtensionPreferences } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import { isGtk4PaintableSinkAvailable } from './utils/check_dependencies.js';
import { Keys } from "./enums.js";
//TODO: Split into separate classes
export default class LiveLockscreenExtensionPrefs extends ExtensionPreferences {
fillPreferencesWindow(window) {
window._settings = this.getSettings();
window.set_default_size(600, 700);
let page = new Adw.PreferencesPage();
if (!isGtk4PaintableSinkAvailable()) {
page.add(this._buildDependencyErrorGroup());
}
page.add(this._buildGeneralGroup(window))
page.add(this._buildAppearanceGroup(window))
page.add(this._buildPromptGroup(window))
page.add(this._buildDebugGroup(window))
window.add(page);
}
_buildDependencyErrorGroup() {
const group = new Adw.PreferencesGroup();
const row = new Adw.ActionRow({
title: 'Missing dependency',
subtitle:
`gtk4paintablesink is not available.\n\n` +
`Install the GStreamer GTK4 plugin for your distribution:\n` +
` • Fedora/RHEL: gstreamer1-plugins-gtk4\n` +
` • Ubuntu/Debian: gstreamer1.0-gtk4\n` +
` • Arch: gst-plugin-gtk4\n\n` +
`See README.md for more information.`,
icon_name: 'dialog-error-symbolic',
});
row.add_css_class('error');
group.add(row);
return group;
}
_buildGeneralGroup(window) {
let generalGroup = new Adw.PreferencesGroup({
title: 'General',
});
generalGroup.add(this._buildPathRow(window));
const scalingRow = new Adw.ComboRow({
title: 'Scaling mode',
subtitle: 'How the video is scaled to fit the screen',
model: new Gtk.StringList({
strings: ['Stretch', 'Fit', 'Cover']
}),
});
scalingRow.set_selected(window._settings.get_int(Keys.SCALING_MODE));
scalingRow.connect('notify::selected', row => {
window._settings.set_int(Keys.SCALING_MODE, row.selected);
});
generalGroup.add(scalingRow)
let volumeRow = new Adw.SpinRow({
title: 'Volume',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1,
value: window._settings.get_int(Keys.AUDIO_VOLUME),
}),
});
let volumeSuffix = new Gtk.Label({
label: '%',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
volumeRow.add_suffix(volumeSuffix);
volumeRow.connect('notify::value', row => {
window._settings.set_int(Keys.AUDIO_VOLUME, row.get_value());
});
generalGroup.add(volumeRow);
const loopSwitch = new Adw.SwitchRow({
title: 'Loop video',
});
window._settings.bind(
Keys.LOOPED, loopSwitch,
'active', Gio.SettingsBindFlags.DEFAULT
);
generalGroup.add(loopSwitch);
const batteryRow = new Adw.SwitchRow({
title: 'Disable on battery',
});
window._settings.bind(
Keys.DISABLE_ON_BATTERY, batteryRow,
'active', Gio.SettingsBindFlags.DEFAULT
);
generalGroup.add(batteryRow);
return generalGroup;
}
_buildAppearanceGroup(window) {
let appearanceGroup = new Adw.PreferencesGroup({
title: 'Appearance',
});
let changeFramerateRow = new Adw.SwitchRow({
title: 'Change framerate',
subtitle: 'This may cause artifacts and performance issues due to conversion overhead',
});
window._settings.bind(
Keys.USE_VIDEORATE, changeFramerateRow,
'active', Gio.SettingsBindFlags.DEFAULT
);
appearanceGroup.add(changeFramerateRow);
let fpsRow = new Adw.SpinRow({
title: 'Framerate',
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 120,
step_increment: 1,
value: window._settings.get_int(Keys.FRAMERATE),
}),
});
fpsRow.connect('notify::value', row => {
window._settings.set_int(Keys.FRAMERATE, row.get_value());
});
let fpsSuffix = new Gtk.Label({
label: 'fps',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
fpsRow.add_suffix(fpsSuffix);
appearanceGroup.add(fpsRow);
const toggleFpsRow = () => {
fpsRow.set_visible(changeFramerateRow.active);
};
toggleFpsRow();
changeFramerateRow.connect('notify::active', toggleFpsRow);
let fadeInRow = new Adw.SpinRow({
title: 'Fade in',
subtitle: 'Video fade-in animation duration',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 600 * 1000,
step_increment: 100,
value: window._settings.get_int(Keys.FADE_IN_DURATION),
}),
});
let fadeSuffix = new Gtk.Label({
label: 'ms',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
fadeInRow.add_suffix(fadeSuffix);
fadeInRow.connect('notify::value', row => {
window._settings.set_int(Keys.FADE_IN_DURATION, row.get_value());
});
appearanceGroup.add(fadeInRow);
let blurRadiusRow = new Adw.SpinRow({
title: 'Blur radius',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1,
value: window._settings.get_int(Keys.BLUR_RADIUS),
}),
});
let radiusSuffix = new Gtk.Label({
label: 'px',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
blurRadiusRow.add_suffix(radiusSuffix);
appearanceGroup.add(blurRadiusRow);
let blurBrightnessRow = new Adw.SpinRow({
title: 'Blur brightness',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1,
value: window._settings.get_double(Keys.BLUR_BRIGHTNESS) * 100,
}),
});
let brightnessSuffix = new Gtk.Label({
label: '%',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
blurBrightnessRow.add_suffix(brightnessSuffix);
appearanceGroup.add(blurBrightnessRow);
const toggleBrightnessSpin = () => {
blurBrightnessRow.set_sensitive(blurRadiusRow.get_value() !== 0);
};
toggleBrightnessSpin();
blurRadiusRow.connect('notify::value', row => {
window._settings.set_int(Keys.BLUR_RADIUS, row.get_value());
toggleBrightnessSpin();
});
blurBrightnessRow.connect('notify::value', row => {
window._settings.set_double(Keys.BLUR_BRIGHTNESS, row.get_value() / 100);
});
return appearanceGroup;
}
_buildPromptGroup(window) {
let promptGroup = new Adw.PreferencesGroup({
title: 'Password Prompt',
description: 'Customize behavior when password prompt appears',
});
const pauseSwitch = new Adw.SwitchRow({
title: 'Pause video'
});
window._settings.bind(
Keys.PROMPT_PAUSE, pauseSwitch,
'active', Gio.SettingsBindFlags.DEFAULT
);
promptGroup.add(pauseSwitch);
const grayscaleSwitch = new Adw.SwitchRow({
title: 'Grayscale video'
});
window._settings.bind(
Keys.PROMPT_GRAYSCALE, grayscaleSwitch,
'active', Gio.SettingsBindFlags.DEFAULT
);
promptGroup.add(grayscaleSwitch);
const changeBlurSwitch = new Adw.SwitchRow({
title: 'Change blur'
});
window._settings.bind(
Keys.PROMPT_CHANGE_BLUR, changeBlurSwitch,
'active', Gio.SettingsBindFlags.DEFAULT
);
promptGroup.add(changeBlurSwitch);
const blurRadiusRow = new Adw.SpinRow({
title: 'Blur radius',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1,
value: window._settings.get_int(Keys.PROMPT_BLUR_RADIUS),
}),
});
let radiusSuffix = new Gtk.Label({
label: 'px',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
blurRadiusRow.add_suffix(radiusSuffix);
window._settings.bind(
Keys.PROMPT_BLUR_RADIUS, blurRadiusRow,
'value', Gio.SettingsBindFlags.DEFAULT
);
promptGroup.add(blurRadiusRow);
const blurBrightnessRow = new Adw.SpinRow({
title: 'Blur brightness',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 100,
step_increment: 1,
value: window._settings.get_double(Keys.PROMPT_BLUR_BRIGHTNESS) * 100,
}),
});
blurBrightnessRow.connect('notify::value', row => {
window._settings.set_double(Keys.PROMPT_BLUR_BRIGHTNESS, row.get_value() / 100);
});
let suffix = new Gtk.Label({
label: '%',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
blurBrightnessRow.add_suffix(suffix);
promptGroup.add(blurBrightnessRow);
const animDurationRow = new Adw.SpinRow({
title: 'Animation duration',
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 600000,
step_increment: 100,
value: window._settings.get_int(Keys.PROMPT_BLUR_ANIM_DURATION),
}),
});
window._settings.bind(
Keys.PROMPT_BLUR_ANIM_DURATION, animDurationRow,
'value', Gio.SettingsBindFlags.DEFAULT
);
let animSuffix = new Gtk.Label({
label: 'ms',
valign: Gtk.Align.CENTER,
css_classes: ['dim-label'],
});
animDurationRow.add_suffix(animSuffix);
promptGroup.add(animDurationRow);
const toggleBlurRows = () => {
const enabled = changeBlurSwitch.active;
blurRadiusRow.set_visible(enabled);
blurBrightnessRow.set_visible(enabled);
};
toggleBlurRows();
changeBlurSwitch.connect('notify::active', toggleBlurRows);
return promptGroup;
}
_buildDebugGroup(window) {
let debugGroup = new Adw.PreferencesGroup({
title: 'Debug',
});
let disableColorRow = new Adw.SwitchRow({
title: 'Disable color conversion',
subtitle: 'Enabling this might improve performance but will cause color inaccuracy',
});
disableColorRow.active = !window._settings.get_boolean(Keys.DEBUG_USE_COLOR_ACCURATE);
disableColorRow.connect('notify::active', (row) => {
// Inverting the value so:
// disable color conversion -> use_color_accurate = false
window._settings.set_boolean(
Keys.DEBUG_USE_COLOR_ACCURATE,
!row.active
);
});
debugGroup.add(disableColorRow);
let forceFullscreenRow = new Adw.SwitchRow({
title: 'Force fullscreen',
subtitle: 'Enable this if you experience video positioning issues',
});
window._settings.bind(
Keys.DEBUG_FORCE_FULLSCREEN, forceFullscreenRow,
'active', Gio.SettingsBindFlags.DEFAULT
);
debugGroup.add(forceFullscreenRow);
return debugGroup;
}
_buildPathRow(window) {
let path = window._settings.get_string(Keys.VIDEO_PATH);
const row = new Adw.ActionRow({
title: "Video",
subtitle: `${path !== '' ? path : 'None'}`,
});
let button = new Adw.ButtonContent({
icon_name: 'document-open-symbolic',
label: 'Browse',
});
row.activatable_widget = button;
row.add_suffix(button);
row.connect('activated', () => {
this._openFileDialog(window, row)
});
return row;
}
_openFileDialog(window, row) {
let filter = new Gtk.FileFilter();
filter.set_name('Video files');
filter.add_mime_type('video/*');
let filters = new Gio.ListStore({ item_type: Gtk.FileFilter });
filters.append(filter);
let dialog = new Gtk.FileDialog({ title: 'Select Video File' });
dialog.set_filters(filters);
const videoPath = window._settings.get_string(Keys.VIDEO_PATH);
if (videoPath) {
const file = Gio.File.new_for_path(videoPath);
const parentFolder = file.get_parent();
if (parentFolder)
dialog.set_initial_folder(parentFolder);
}
dialog.open(window, null, (d, result) => {
try {
let file = d.open_finish(result);
if (file) {
row.subtitle = file.get_path()
window._settings.set_string(Keys.VIDEO_PATH, file.get_path());
}
else {
row.subtitle = 'None'
window._settings.set_string(Keys.VIDEO_PATH, "");
}
} catch (e) {
console.log(`Error selecting file: ${e}`);
}
});
}
}