Skip to content

Commit 950f2c5

Browse files
committed
refactor(MediaPlayerSettings): integrate changes done on NightMode exceptions
- Use the appId matching function abstracted to Paths.qml. - Use common appId normalization functions to append/remove from settings list. - Align with GammaControlTab app list input fields to fix bug where white spaces only input would prevent field clearing on accept. - Align with GammaControlTab and use a Loader for AppBrowserPopup so that it can be recreated in case the popup is not closed with the dedicated button (i.e., via the compositor).
1 parent 63fa076 commit 950f2c5

3 files changed

Lines changed: 51 additions & 64 deletions

File tree

quickshell/Common/SettingsData.qml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3163,10 +3163,6 @@ Singleton {
31633163
saveSettings();
31643164
}
31653165

3166-
function addMediaExcludePlayer(identity) {
3167-
if (identity === undefined || identity === null)
3168-
return;
3169-
var normalizedIdentity = identity.toString().trim().toLowerCase();
31703166
function setNightModeExcludeFullscreen(enabled) {
31713167
nightModeExcludeFullscreen = enabled;
31723168
saveSettings();
@@ -3215,24 +3211,16 @@ Singleton {
32153211
SessionData.resetNightModeExcludedAppsMatchesCache();
32163212
saveSettings();
32173213
}
3218-
return;
3219-
var list = mediaExcludePlayers ? mediaExcludePlayers.slice() : [];
3220-
var normalizedList = list.map(function (id) {
3221-
return id ? id.toString().trim().toLowerCase() : "";
3222-
});
3223-
if (normalizedList.indexOf(normalizedIdentity) >= 0)
3224-
return;
3225-
list.push(normalizedIdentity);
3226-
mediaExcludePlayers = list;
3214+
3215+
function addMediaExcludePlayer(identity) {
3216+
var newList = addAppIdToList(identity, mediaExcludePlayers);
3217+
mediaExcludePlayers = newList;
32273218
saveSettings();
32283219
}
32293220

32303221
function removeMediaExcludePlayer(index) {
3231-
var list = mediaExcludePlayers ? mediaExcludePlayers.slice() : [];
3232-
if (index < 0 || index >= list.length)
3233-
return;
3234-
list.splice(index, 1);
3235-
mediaExcludePlayers = list;
3222+
var newList = removeAppIdFromList(index, mediaExcludePlayers);
3223+
mediaExcludePlayers = newList;
32363224
saveSettings();
32373225
}
32383226

quickshell/Modules/Settings/MediaPlayerTab.qml

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,40 @@ Item {
1818
desktopApps = [];
1919
}
2020

21+
Loader {
22+
id: popupLoader
23+
active: false
24+
sourceComponent: AppBrowserPopup {
25+
id: appBrowserPopup
26+
appsModel: root.desktopApps
27+
parentModal: root.parentModal
28+
onAppSelected: appId => {
29+
var name = appId;
30+
if (name.endsWith(".desktop")) {
31+
name = name.slice(0, -8);
32+
}
33+
SettingsData.addMediaExcludePlayer(name);
34+
}
35+
}
36+
37+
function recreatePopup() {
38+
log.debug("Recreating popup");
39+
popupLoader.active = false;
40+
popupLoader.active = true;
41+
}
42+
43+
function showPopup() {
44+
if (!popupLoader.item) {
45+
popupLoader.active = true;
46+
}
47+
popupLoader.item.show();
48+
if (!popupLoader.item.visible) {
49+
recreatePopup();
50+
popupLoader.item.show();
51+
}
52+
}
53+
}
54+
2155
DankFlickable {
2256
anchors.fill: parent
2357
clip: true
@@ -166,10 +200,11 @@ Item {
166200
placeholderText: I18n.tr("App name or identity (e.g., firefox)")
167201
font.pixelSize: Theme.fontSizeSmall
168202
onAccepted: {
169-
if (text.trim() !== "") {
170-
SettingsData.addMediaExcludePlayer(text.trim());
171-
text = "";
203+
var cleanInput = newExcludePlayerField.text.trim();
204+
if (cleanInput !== "") {
205+
SettingsData.addMediaExcludePlayer(cleanInput);
172206
}
207+
text = "";
173208
}
174209
}
175210

@@ -181,10 +216,11 @@ Item {
181216
backgroundColor: Theme.primary
182217
iconColor: Theme.onPrimary
183218
onClicked: {
184-
if (newExcludePlayerField.text.trim() !== "") {
185-
SettingsData.addMediaExcludePlayer(newExcludePlayerField.text.trim());
186-
newExcludePlayerField.text = "";
219+
var cleanInput = newExcludePlayerField.text.trim();
220+
if (cleanInput !== "") {
221+
SettingsData.addMediaExcludePlayer(cleanInput);
187222
}
223+
newExcludePlayerField.text = "";
188224
}
189225
}
190226

@@ -195,7 +231,7 @@ Item {
195231
iconSize: 20
196232
backgroundColor: Theme.surfaceContainer
197233
iconColor: Theme.primary
198-
onClicked: appBrowserPopup.show()
234+
onClicked: popupLoader.showPopup()
199235
}
200236
}
201237

@@ -267,17 +303,4 @@ Item {
267303
}
268304
}
269305
}
270-
271-
AppBrowserPopup {
272-
id: appBrowserPopup
273-
appsModel: root.desktopApps
274-
parentModal: root.parentModal
275-
onAppSelected: appId => {
276-
var name = appId;
277-
if (name.endsWith(".desktop")) {
278-
name = name.slice(0, -8);
279-
}
280-
SettingsData.addMediaExcludePlayer(name);
281-
}
282-
}
283306
}

quickshell/Services/MprisController.qml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,7 @@ Singleton {
1717
return players.filter(p => {
1818
const identity = (p.identity || "").toLowerCase();
1919
const desktopEntry = ("desktopEntry" in p && p.desktopEntry) ? String(p.desktopEntry).toLowerCase() : "";
20-
return !excluded.some(ex => {
21-
const exLower = String(ex).toLowerCase().trim();
22-
if (!exLower) return false;
23-
24-
// 1. Substring match
25-
if (identity.includes(exLower) || desktopEntry.includes(exLower))
26-
return true;
27-
28-
// 2. Match reverse-DNS segments (e.g. app.zen_browser.zen -> zen)
29-
if (exLower.indexOf(".") !== -1) {
30-
const parts = exLower.split(".");
31-
const lastPart = parts[parts.length - 1];
32-
if (lastPart && (identity.includes(lastPart) || desktopEntry.includes(lastPart)))
33-
return true;
34-
}
35-
36-
// 3. Bidirectional match (longer excluded name contains shorter player identity)
37-
if (identity.length >= 3 && exLower.includes(identity))
38-
return true;
39-
40-
return false;
41-
});
20+
return !excluded.some(ex => Paths.isAppIdMatch(identity, ex, desktopEntry));
4221
});
4322
}
4423
property MprisPlayer activePlayer: null
@@ -86,10 +65,7 @@ Singleton {
8665
}
8766

8867
function isIdle(player: MprisPlayer): bool {
89-
return player
90-
&& player.playbackState === MprisPlaybackState.Stopped
91-
&& !player.trackTitle
92-
&& !player.trackArtist;
68+
return player && player.playbackState === MprisPlaybackState.Stopped && !player.trackTitle && !player.trackArtist;
9369
}
9470

9571
function _resolveActivePlayer(): void {

0 commit comments

Comments
 (0)