-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathprefs.js
More file actions
321 lines (274 loc) · 11 KB
/
Copy pathprefs.js
File metadata and controls
321 lines (274 loc) · 11 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
/*
* Spotify Controls Extension
* Copyright (C) 2024 Athanasios Raptis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import Adw from 'gi://Adw';
import Gtk from 'gi://Gtk';
import Gio from 'gi://Gio';
import GObject from 'gi://GObject';
import { ExtensionPreferences, gettext as _ } from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
/**
* Define the PositionItem GObject class for Indicator Position choices.
*/
const PositionItem = GObject.registerClass(
{
GTypeName: 'SpotifyControlsPositionItem',
Properties: {
'title': GObject.ParamSpec.string('title', 'Title', 'Title', GObject.ParamFlags.READWRITE, ''),
'value': GObject.ParamSpec.string('value', 'Value', 'Value', GObject.ParamFlags.READWRITE, ''),
},
},
class PositionItem extends GObject.Object {
_init(props = {}) {
super._init(props);
}
}
);
/**
* Define the ControlsPositionItem GObject class for Playback Controls Position choices.
*/
const ControlsPositionItem = GObject.registerClass(
{
GTypeName: 'SpotifyControlsControlsPositionItem',
Properties: {
'title': GObject.ParamSpec.string('title', 'Title', 'Title', GObject.ParamFlags.READWRITE, ''),
'value': GObject.ParamSpec.string('value', 'Value', 'Value', GObject.ParamFlags.READWRITE, ''),
},
},
class ControlsPositionItem extends GObject.Object {
_init(props = {}) {
super._init(props);
}
}
);
/**
* SpotifyControlsPrefs class handles the preferences window for the extension.
*/
export default class SpotifyControlsPrefs extends ExtensionPreferences {
/**
* Fills the preferences window with necessary widgets and settings.
* @param {Gtk.Window} window - The preferences window.
*/
fillPreferencesWindow(window) {
const settings = this.getSettings();
// Set window properties
window.set_default_size(600, 400);
window.set_title(_('Spotify Controls Preferences'));
// Create the main preferences page
const page = new Adw.PreferencesPage();
/**
* GENERAL SETTINGS GROUP
*/
const generalGroup = new Adw.PreferencesGroup({
title: _('General Settings'),
});
/**
* INDICATOR POSITION SECTION
*/
const positions = [
new PositionItem({ title: _('Far Left'), value: 'far-left' }),
new PositionItem({ title: _('Mid Left'), value: 'mid-left' }),
new PositionItem({ title: _('Rightmost Left'), value: 'rightmost-left' }),
new PositionItem({ title: _('Middle Left'), value: 'middle-left' }),
new PositionItem({ title: _('Center'), value: 'center' }),
new PositionItem({ title: _('Middle Right'), value: 'middle-right' }),
new PositionItem({ title: _('Leftmost Right'), value: 'leftmost-right' }),
new PositionItem({ title: _('Mid Right'), value: 'mid-right' }),
new PositionItem({ title: _('Far Right'), value: 'far-right' }),
];
const positionStore = new Gio.ListStore({ item_type: PositionItem });
positions.forEach(pos => positionStore.append(pos));
const positionComboRow = new Adw.ComboRow({
title: _('Indicator Position'),
subtitle: _('Select the position of the Spotify controls in the top bar'),
model: positionStore,
expression: Gtk.PropertyExpression.new(PositionItem, null, 'title'),
});
const currentPositionValue = settings.get_string('position');
const currentIndex = positions.findIndex(pos => pos.value === currentPositionValue);
positionComboRow.set_selected(currentIndex >= 0 ? currentIndex : 0);
positionComboRow.connect('notify::selected', (row) => {
const selectedIndex = row.get_selected();
const selectedItem = positionStore.get_item(selectedIndex);
if (selectedItem) {
settings.set_string('position', selectedItem.value);
}
});
generalGroup.add(positionComboRow);
/**
* PLAYBACK CONTROLS POSITION SECTION
*/
const controlsPositions = [
new ControlsPositionItem({ title: _('Left'), value: 'left' }),
new ControlsPositionItem({ title: _('Right'), value: 'right' }),
];
const controlsPositionStore = new Gio.ListStore({ item_type: ControlsPositionItem });
controlsPositions.forEach(pos => controlsPositionStore.append(pos));
const controlsPositionComboRow = new Adw.ComboRow({
title: _('Playback Controls Position'),
subtitle: _('Select whether the playback controls should appear on the left or right'),
model: controlsPositionStore,
expression: Gtk.PropertyExpression.new(ControlsPositionItem, null, 'title'),
});
const currentControlsPositionValue = settings.get_string('controls-position');
const controlsSelectedIndex = controlsPositions.findIndex(pos => pos.value === currentControlsPositionValue);
controlsPositionComboRow.set_selected(controlsSelectedIndex >= 0 ? controlsSelectedIndex : 1);
controlsPositionComboRow.connect('notify::selected', (row) => {
const selectedIndex = row.get_selected();
const selectedItem = controlsPositionStore.get_item(selectedIndex);
if (selectedItem) {
settings.set_string('controls-position', selectedItem.value);
}
});
generalGroup.add(controlsPositionComboRow);
/**
* ENABLE VOLUME CONTROL TOGGLE
*/
const enableVolumeControlSwitch = new Adw.SwitchRow({
title: _('Enable Volume Control'),
subtitle: _('Toggle the volume control feature using the scroll wheel over the song title'),
activatable: true,
active: settings.get_boolean('enable-volume-control'),
});
settings.bind(
'enable-volume-control',
enableVolumeControlSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
generalGroup.add(enableVolumeControlSwitch);
/**
* ENABLE MIDDLE CLICK TOGGLE
*/
const enableMiddleClickSwitch = new Adw.SwitchRow({
title: _('Enable Middle Click Play/Pause'),
subtitle: _('Allows toggling the current track with a middle-click on the extension.'),
activatable: true,
active: settings.get_boolean('enable-middle-click'),
});
settings.bind(
'enable-middle-click',
enableMiddleClickSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
generalGroup.add(enableMiddleClickSwitch);
/**
* MINIMIZE ON SECOND CLICK TOGGLE
*/
const minimizeOnSecondClickSwitch = new Adw.SwitchRow({
title: _('Minimize on Second Click'),
subtitle: _('If true, clicking the extension again minimizes Spotify if it is already in the foreground.'),
activatable: true,
active: settings.get_boolean('minimize-on-second-click'),
});
// Bind to the new key
settings.bind(
'minimize-on-second-click',
minimizeOnSecondClickSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
generalGroup.add(minimizeOnSecondClickSwitch);
// Add the general group to the main page
page.add(generalGroup);
/**
* DISPLAY OPTIONS GROUP
*/
const displayGroup = new Adw.PreferencesGroup({
title: _('Display Options'),
});
/**
* SHOW PLAYBACK CONTROLS TOGGLE
*/
const showControlsSwitch = new Adw.SwitchRow({
title: _('Show Playback Controls'),
subtitle: _('Toggle the visibility of the playback controls (Previous, Play/Pause, Next)'),
activatable: true,
active: settings.get_boolean('show-playback-controls'),
});
settings.bind(
'show-playback-controls',
showControlsSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
displayGroup.add(showControlsSwitch);
/**
* SHOW SPOTIFY ICON TOGGLE
*/
const showSpotifyIconSwitch = new Adw.SwitchRow({
title: _('Show Spotify Icon'),
subtitle: _('Toggle the visibility of the Spotify logo in the top bar'),
activatable: true,
active: settings.get_boolean('show-spotify-icon'),
});
settings.bind(
'show-spotify-icon',
showSpotifyIconSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
displayGroup.add(showSpotifyIconSwitch);
/**
* SHOW ARTIST/TRACK INFO TOGGLE
*/
const showTrackInfoSwitch = new Adw.SwitchRow({
title: _('Show Artist/Track Info'),
subtitle: _('Toggle the visibility of the Artist and Track information in the top bar'),
activatable: true,
active: settings.get_boolean('show-track-info'),
});
settings.bind(
'show-track-info',
showTrackInfoSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);
displayGroup.add(showTrackInfoSwitch);
/**
* MAXIMUM WIDTH SETTING
*/
const maxWidthRow = new Adw.ActionRow({
title: _('Maximum Width (pixels)'),
subtitle: _('Limit how wide the extension label can be in the top bar (0 = no limit)'),
});
const maxWidthAdjustment = new Gtk.Adjustment({
lower: 0,
upper: 1000,
step_increment: 10,
page_increment: 50,
});
const maxWidthSpin = new Gtk.SpinButton({
adjustment: maxWidthAdjustment,
numeric: true,
});
settings.bind(
'max-width',
maxWidthSpin,
'value',
Gio.SettingsBindFlags.DEFAULT
);
maxWidthRow.add_suffix(maxWidthSpin);
maxWidthRow.activatable_widget = maxWidthSpin;
displayGroup.add(maxWidthRow);
// Add the display group to the page
page.add(displayGroup);
// Finally, add the page to the window and show
window.add(page);
window.show();
}
}