-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
prefs.js
300 lines (256 loc) · 13.8 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
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
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// See the GNU General Public License, version 3 or later for details.
// Based on GNOME shell extension NASA APOD by Elia Argentieri https://github.com/Elinvention/gnome-shell-extension-nasa-apod
import Gtk from 'gi://Gtk';
import Gdk from 'gi://Gdk';
import Gio from 'gi://Gio';
import Soup from 'gi://Soup';
import Adw from 'gi://Adw';
import {ExtensionPreferences, gettext as _} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
import * as Config from 'resource:///org/gnome/Shell/Extensions/js/misc/config.js';
import * as Utils from './utils.js';
import Carousel from './carousel.js';
const BingImageURL = Utils.BingImageURL;
var DESKTOP_SCHEMA = 'org.gnome.desktop.background';
// this is pretty wide because of the size of the gallery
var PREFS_DEFAULT_WIDTH = 750;
var PREFS_DEFAULT_HEIGHT = 750;
export default class BingWallpaperExtensionPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
// formally globals
let settings = this.getSettings(Utils.BING_SCHEMA);
//let desktop_settings = this.getSettings(Utils.DESKTOP_SCHEMA);
window.set_default_size(PREFS_DEFAULT_WIDTH, PREFS_DEFAULT_HEIGHT);
/*let icon_image = null;*/
let provider = new Gtk.CssProvider();
provider.load_from_path(this.dir.get_path() + '/ui/prefs.css');
Gtk.StyleContext.add_provider_for_display(
Gdk.Display.get_default(),
provider,
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
let carousel = null;
let httpSession = null;
let log = (msg) => { // avoids need for globals
if (settings.get_boolean('debug-logging'))
console.log("BingWallpaper extension: " + msg); // disable to keep the noise down in journal
}
let buildable = new Gtk.Builder();
// GTK4 removes some properties, and builder breaks when it sees them
buildable.add_from_file( this.dir.get_path() + '/ui/prefsadw.ui' );
// adw or gtk objects we'll attach to below
const settings_page = buildable.get_object('settings_page');
const hideSwitch = buildable.get_object('hideSwitch');
const notifySwitch = buildable.get_object('notifySwitch');
const iconEntry = buildable.get_object('iconEntry');
const bgSwitch = buildable.get_object('bgSwitch');
const shuffleSwitch = buildable.get_object('shuffleSwitch');
const shuffleInterval = buildable.get_object('shuffleInterval');
const folderRow = buildable.get_object('folderRow');
const lockscreen_page = buildable.get_object('lockscreen_page');
const overrideSwitch = buildable.get_object('overrideSwitch');
const blurPresets = buildable.get_object('blurPresets');
const strengthEntry = buildable.get_object('strengthEntry');
const brightnessEntry = buildable.get_object('brightnessEntry');
const blurAdjustment = buildable.get_object('blurAdjustment');
const brightnessAdjustment = buildable.get_object('brightnessAdjustment');
const resolutionEntry = buildable.get_object('resolutionEntry');
const debugSwitch = buildable.get_object('debug_switch');
const revertSwitch = buildable.get_object('revert_switch');
const trash_purge_switch = buildable.get_object('trash_purge_switch');
const delete_previous_switch = buildable.get_object('delete_previous_switch');
const delete_previous_adjustment = buildable.get_object('delete_previous_adjustment');
const always_export_switch = buildable.get_object('always_export_switch');
const gallery_page = buildable.get_object('gallery_page');
const carouselFlowBox = buildable.get_object('carouselFlowBox');
const randomIntervalEntry = buildable.get_object('entry_random_interval');
const debug_page = buildable.get_object('debug_page');
const json_actionrow = buildable.get_object('json_actionrow');
const about_page = buildable.get_object('about_page');
const version_button = buildable.get_object('version_button');
const change_log = buildable.get_object('change_log');
window.add(settings_page);
window.add(lockscreen_page);
window.add(gallery_page);
window.add(debug_page);
window.add(about_page);
iconEntry.set_value(1+Utils.icon_list.indexOf(settings.get_string('icon-name')));
// shuffle intervals
const shuffleIntervals = new Gtk.StringList;
Utils.randomIntervals.forEach((x) => {
shuffleIntervals.append(_(x.title));
});
shuffleInterval.set_model(shuffleIntervals);
shuffleInterval.set_selected(Utils.randomIntervals.map( e => e.value).indexOf(settings.get_string('random-interval-mode')));
// add wallpaper folder open and change buttons
const openBtn = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'folder-pictures-symbolic',
label: _('Open folder'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
const changeBtn = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'folder-download-symbolic',
label: _('Change folder'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
folderRow.add_suffix(openBtn);
folderRow.add_suffix(changeBtn);
blurAdjustment.set_value(settings.get_int('lockscreen-blur-strength'));
brightnessAdjustment.set_value(settings.get_int('lockscreen-blur-brightness'));
const defaultBtn = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'emblem-default-symbolic',
label: _('Default'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
const noBlurBtn = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'emblem-default-symbolic',
label: _('No blur, slight dim'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
const slightBlurBtn = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'emblem-default-symbolic',
label: _('Slight blur & dim'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
// add to presets row
blurPresets.add_suffix(defaultBtn);
blurPresets.add_suffix(noBlurBtn);
blurPresets.add_suffix(slightBlurBtn);
randomIntervalEntry.set_value(settings.get_int('random-interval'));
// these buttons either export or import saved JSON data
const buttonImportData = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'document-send-symbolic',
label: _('Import'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
const buttonExportData = new Gtk.Button( {
child: new Adw.ButtonContent({
icon_name: 'document-save-symbolic',
label: _('Export'),
},),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
json_actionrow.add_suffix(buttonImportData);
json_actionrow.add_suffix(buttonExportData);
version_button.set_label(this.metadata.version.toString());
try {
httpSession = new Soup.Session();
httpSession.user_agent = 'User-Agent: Mozilla/5.0 (X11; GNOME Shell/' + Config.PACKAGE_VERSION + '; Linux x86_64; +https://github.com/neffo/bing-wallpaper-gnome-extension ) BingWallpaper Gnome Extension/' + this.metadata.version;
}
catch (e) {
log("Error creating httpSession: " + e);
}
const icon_image = buildable.get_object('icon_image');
// check that these are valid (can be edited through dconf-editor)
Utils.validate_resolution(settings);
Utils.validate_icon(settings, this.path, icon_image);
Utils.validate_interval(settings);
// Indicator & notifications
settings.bind('hide', hideSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('notify', notifySwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.connect('changed::icon-name', () => {
Utils.validate_icon(settings, this.path, icon_image);
iconEntry.set_value(1 + Utils.icon_list.indexOf(settings.get_string('icon-name')));
});
iconEntry.connect('output', () => {
settings.set_string('icon-name', Utils.icon_list[iconEntry.get_value()-1]);
});
// connect switches to settings changes
settings.bind('set-background', bgSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('debug-logging', debugSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('revert-to-current-image', revertSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
//settings.bind('override-unsafe-wayland', unsafeSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('random-interval', randomIntervalEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('trash-deletes-images', trash_purge_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('always-export-bing-json', always_export_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('delete-previous', delete_previous_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
// button opens Nautilus at our image folder
openBtn.connect('clicked', (widget) => {
Utils.openImageFolder(settings);
});
// we populate the tab (gtk4+, gnome 40+), this was previously a button to open a new window in gtk3
carousel = new Carousel(settings, null, null, carouselFlowBox, this.dir.get_path()); // auto load carousel
// this is intended for migrating image folders between computers (or even sharing) or backups
// we export the Bing JSON data to the image directory, so this folder becomes portable
buttonImportData.connect('clicked', () => {
Utils.importBingJSON(settings);
});
buttonExportData.connect('clicked', () => {
Utils.exportBingJSON(settings);
});
// change wallpaper button
const dirChooser = new Gtk.FileDialog( {
accept_label: "Select",
modal: true,
title: _("Select wallpaper download folder"),
});
changeBtn.connect('clicked', (widget) => {
dirChooser.set_initial_folder(Gio.File.new_for_path(Utils.getWallpaperDir(settings)));
dirChooser.select_folder(window, null, (self, res) => {
let new_path = self.select_folder_finish(res).get_uri().replace('file://', '');
log(new_path);
Utils.moveImagesToNewFolder(settings, Utils.getWallpaperDir(settings), new_path);
Utils.setWallpaperDir(settings, new_path);
});
});
// Resolution
const resolutionModel = new Gtk.StringList();
Utils.resolutions.forEach((res) => { // add res to dropdown list (aka a GtkComboText)
resolutionModel.append(res);
});
resolutionEntry.set_model(resolutionModel);
settings.connect('changed::resolution', () => {
resolutionEntry.set_selected(Utils.resolutions.map( e => e.value).indexOf(settings.get_string('resolution')));
});
settings.connect('changed::resolution', () => {
Utils.validate_resolution(settings);
});
// shuffle modes
settings.bind('random-mode-enabled', shuffleSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
/*settings.bind('random-interval-mode', entryShuffleMode, 'active_id', Gio.SettingsBindFlags.DEFAULT);*/
settings.connect('changed::random-interval-mode', () => {
shuffleInterval.set_selected(Utils.randomIntervals.map( e => e.value).indexOf(settings.get_string('random-interval-mode')));
});
// GDM3 lockscreen blur override
settings.bind('override-lockscreen-blur', overrideSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('lockscreen-blur-strength', strengthEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('lockscreen-blur-brightness', brightnessEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('previous-days', delete_previous_adjustment, 'value', Gio.SettingsBindFlags.DEFAULT);
// add a couple of preset buttons
defaultBtn.connect('clicked', (widget) => {
Utils.set_blur_preset(settings, Utils.PRESET_GNOME_DEFAULT);
});
noBlurBtn.connect('clicked', (widget) => {
Utils.set_blur_preset(settings, Utils.PRESET_NO_BLUR);
});
slightBlurBtn.connect('clicked', (widget) => {
Utils.set_blur_preset(settings, Utils.PRESET_SLIGHT_BLUR);
});
// fetch change log (on about page)
if (httpSession)
Utils.fetch_change_log(this.metadata.version.toString(), change_log, httpSession);
}
}