Skip to content

Commit ea9456e

Browse files
committed
Added new configuration options
1 parent 8421d01 commit ea9456e

File tree

5 files changed

+364
-20
lines changed

5 files changed

+364
-20
lines changed

extension.js

Lines changed: 216 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,27 @@ const { getMetadata, getPlayers, getPlaybackStatus, playbackAction } =
1010

1111
// User-defined settings
1212

13-
let maxDisplayLength, updateDelay;
13+
let maxDisplayLength,
14+
updateDelay,
15+
hideTrackName,
16+
hidePlayerIcon,
17+
hideControls,
18+
extensionPosition,
19+
extensionIndex;
1420

1521
// Global variables
1622

1723
let currentPlayer, playerIcon, playerState, displayText;
18-
let onUpdateDelayChanged, onMaxLengthChanged;
24+
let onUpdateDelayChanged,
25+
onMaxLengthChanged,
26+
onHideTrackNameChanged,
27+
onHidePlayerIconChanged,
28+
onHideControlsChanged,
29+
onExtensionPositionChanged,
30+
onExtensionIndexChanged;
31+
1932
let mainLoop;
2033
let settings;
21-
2234
// Tracking variables
2335

2436
let lastPlayer,
@@ -31,10 +43,11 @@ let lastPlayer,
3143
// Constants
3244

3345
const playerIcons = {
34-
default: "",
35-
chrom: "",
36-
firefox: "",
37-
spotify: "",
46+
default: "audio-x-generic-symbolic",
47+
chromium: "chromium",
48+
firefox: "firefox",
49+
rhythmbox: "rhythmbox",
50+
spotify: "spotify",
3851
};
3952

4053
// UI elements
@@ -46,6 +59,7 @@ let buttonNext,
4659
iconPause,
4760
iconPlay,
4861
iconPrev,
62+
iconPlayer,
4963
labelText;
5064

5165
// Button trigger methods
@@ -72,17 +86,145 @@ const _playerPrev = () => {
7286
// Housekeeping methods
7387

7488
const addContent = () => {
75-
Main.panel._centerBox.insert_child_at_index(buttonNext, 0);
76-
Main.panel._centerBox.insert_child_at_index(buttonToggle, 0);
77-
Main.panel._centerBox.insert_child_at_index(buttonPrev, 0);
78-
Main.panel._centerBox.insert_child_at_index(labelText, 0);
89+
let currentIndex;
90+
log(`Adding to ${extensionPosition} box`);
91+
switch (extensionPosition) {
92+
case "left":
93+
currentIndex = 0;
94+
if (!hidePlayerIcon) {
95+
Main.panel._leftBox.insert_child_at_index(
96+
iconPlayer,
97+
extensionIndex + currentIndex
98+
);
99+
currentIndex++;
100+
}
101+
if (!hideTrackName) {
102+
Main.panel._leftBox.insert_child_at_index(
103+
labelText,
104+
extensionIndex + currentIndex
105+
);
106+
currentIndex++;
107+
}
108+
if (!hideControls) {
109+
Main.panel._leftBox.insert_child_at_index(
110+
buttonPrev,
111+
extensionIndex + currentIndex
112+
);
113+
currentIndex++;
114+
115+
Main.panel._leftBox.insert_child_at_index(
116+
buttonToggle,
117+
extensionIndex + currentIndex
118+
);
119+
currentIndex++;
120+
Main.panel._leftBox.insert_child_at_index(
121+
buttonNext,
122+
extensionIndex + currentIndex
123+
);
124+
currentIndex++;
125+
}
126+
127+
break;
128+
case "center":
129+
currentIndex = 0;
130+
131+
if (!hidePlayerIcon) {
132+
Main.panel._centerBox.insert_child_at_index(
133+
iconPlayer,
134+
extensionIndex + currentIndex
135+
);
136+
currentIndex++;
137+
}
138+
if (!hideTrackName) {
139+
Main.panel._centerBox.insert_child_at_index(
140+
labelText,
141+
extensionIndex + currentIndex
142+
);
143+
currentIndex++;
144+
}
145+
if (!hideControls) {
146+
Main.panel._centerBox.insert_child_at_index(
147+
buttonPrev,
148+
extensionIndex + currentIndex
149+
);
150+
currentIndex++;
151+
Main.panel._centerBox.insert_child_at_index(
152+
buttonToggle,
153+
extensionIndex + currentIndex
154+
);
155+
currentIndex++;
156+
157+
Main.panel._centerBox.insert_child_at_index(
158+
buttonNext,
159+
extensionIndex + currentIndex
160+
);
161+
currentIndex++;
162+
}
163+
164+
break;
165+
default:
166+
currentIndex = 0;
167+
if (!hideTrackName) {
168+
Main.panel._rightBox.insert_child_at_index(
169+
labelText,
170+
extensionIndex + currentIndex
171+
);
172+
currentIndex++;
173+
}
174+
if (!hidePlayerIcon) {
175+
Main.panel._rightBox.insert_child_at_index(
176+
iconPlayer,
177+
extensionIndex + currentIndex
178+
);
179+
currentIndex++;
180+
}
181+
if (!hideControls) {
182+
Main.panel._rightBox.insert_child_at_index(
183+
buttonPrev,
184+
extensionIndex + currentIndex
185+
);
186+
currentIndex++;
187+
Main.panel._rightBox.insert_child_at_index(
188+
buttonToggle,
189+
extensionIndex + currentIndex
190+
);
191+
currentIndex++;
192+
Main.panel._rightBox.insert_child_at_index(
193+
buttonNext,
194+
extensionIndex + currentIndex
195+
);
196+
currentIndex++;
197+
}
198+
199+
break;
200+
}
79201
};
80202

81203
const removeContent = () => {
82-
Main.panel._centerBox.remove_actor(buttonNext);
83-
Main.panel._centerBox.remove_actor(buttonToggle);
84-
Main.panel._centerBox.remove_actor(buttonPrev);
85-
Main.panel._centerBox.remove_actor(labelText);
204+
log(`Removing from ${extensionPosition} box`);
205+
switch (extensionPosition) {
206+
case "left":
207+
Main.panel._leftBox.remove_actor(buttonNext);
208+
Main.panel._leftBox.remove_actor(buttonToggle);
209+
Main.panel._leftBox.remove_actor(buttonPrev);
210+
Main.panel._leftBox.remove_actor(labelText);
211+
Main.panel._leftBox.remove_actor(iconPlayer);
212+
break;
213+
case "center":
214+
Main.panel._centerBox.remove_actor(buttonNext);
215+
Main.panel._centerBox.remove_actor(buttonToggle);
216+
Main.panel._centerBox.remove_actor(buttonPrev);
217+
Main.panel._centerBox.remove_actor(labelText);
218+
Main.panel._centerBox.remove_actor(iconPlayer);
219+
break;
220+
default:
221+
Main.panel._rightBox.remove_actor(buttonNext);
222+
Main.panel._rightBox.remove_actor(buttonToggle);
223+
Main.panel._rightBox.remove_actor(buttonPrev);
224+
Main.panel._rightBox.remove_actor(labelText);
225+
Main.panel._rightBox.remove_actor(iconPlayer);
226+
break;
227+
}
86228
};
87229

88230
// Utility methods
@@ -198,7 +340,8 @@ const updateContent = () => {
198340
lastStateChanged = false;
199341
}
200342
if (lastMetaDataChanged) {
201-
labelText.set_text(`${playerIcon} | ${displayText} |`);
343+
iconPlayer.set_icon_name(playerIcon);
344+
labelText.set_text(`| ${displayText} |`);
202345
lastMetaDataChanged = false;
203346
}
204347
};
@@ -229,8 +372,55 @@ const enable = () => {
229372
// log(`Updated setting "maxDisplayLength": ${maxDisplayLength}`);
230373
});
231374

375+
onHideTrackNameChanged = settings.connect(
376+
"changed::hide-track-name",
377+
() => {
378+
hideTrackName = settings.get_boolean("hide-track-name");
379+
removeContent();
380+
addContent();
381+
}
382+
);
383+
384+
onHidePlayerIconChanged = settings.connect(
385+
"changed::hide-player-icon",
386+
() => {
387+
hidePlayerIcon = settings.get_boolean("hide-player-icon");
388+
removeContent();
389+
addContent();
390+
}
391+
);
392+
393+
onExtensionIndexChanged = settings.connect(
394+
"changed::extension-index",
395+
() => {
396+
extensionIndex = settings.get_int("extension-index");
397+
removeContent();
398+
addContent();
399+
}
400+
);
401+
402+
onExtensionPositionChanged = settings.connect(
403+
"changed::extension-position",
404+
() => {
405+
removeContent();
406+
extensionPosition = settings.get_string("extension-position");
407+
addContent();
408+
}
409+
);
410+
411+
onHideControlsChanged = settings.connect("changed::hide-controls", () => {
412+
hideControls = settings.get_boolean("hide-controls");
413+
removeContent();
414+
addContent();
415+
});
416+
232417
updateDelay = settings.get_int("update-delay");
233418
maxDisplayLength = settings.get_int("max-display-length");
419+
hideTrackName = settings.get_boolean("hide-track-name");
420+
hidePlayerIcon = settings.get_boolean("hide-player-icon");
421+
hideControls = settings.get_boolean("hide-controls");
422+
extensionIndex = settings.get_int("extension-index");
423+
extensionPosition = settings.get_string("extension-position");
234424

235425
// UI Elements
236426

@@ -254,6 +444,11 @@ const enable = () => {
254444
icon_name: "media-skip-backward-symbolic",
255445
style_class: "system-status-icon",
256446
});
447+
iconPlayer = new St.Icon({
448+
icon_name: playerIcons.default,
449+
icon_size: 16,
450+
style: "padding-right: 5px;",
451+
});
257452

258453
labelText = new St.Label({
259454
text: "No player found",
@@ -288,6 +483,11 @@ const disable = () => {
288483

289484
settings.disconnect(onMaxLengthChanged);
290485
settings.disconnect(onUpdateDelayChanged);
486+
settings.disconnect(onHideControlsChanged);
487+
settings.disconnect(onHidePlayerIconChanged);
488+
settings.disconnect(onHideTrackNameChanged);
489+
settings.disconnect(onExtensionIndexChanged);
490+
settings.disconnect(onExtensionPositionChanged);
291491

292492
buttonNext.destroy();
293493
buttonPrev.destroy();

metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "Media Controls",
33
"description": "Show controls for the current playing media in the panel",
44
"uuid": "mediacontrols@cliffniff.github.com",
5-
"url": "https://github.com/cliffniff/media-controls.git",
5+
"url": "https://github.com/cliffniff/media-controls",
66
"settings-schema": "org.gnome.shell.extensions.mediacontrols",
7-
"version": 0.3,
7+
"version": 0.4,
88
"shell-version": ["3.38", "40"]
99
}

0 commit comments

Comments
 (0)