mirror of
https://github.com/ErikReider/SwayNotificationCenter.git
synced 2024-11-25 23:45:41 +03:00
Mpris blacklist support (#390)
* Initial mpris blacklist support * Fix merge conflict * Simplify blacklist type and parse * Fix man * Trim whitespaces * Fix blacklisting when a new player appears * Remove flake.nix * Remove log * Remove comment * Address review suggestions * Fixed linter errors --------- Co-authored-by: 12thgenpenguin <cjgibb@protonmail.com> Co-authored-by: MrPenguin07 <127086564+MrPenguin07@users.noreply.github.com> Co-authored-by: Erik Reider <35975961+ErikReider@users.noreply.github.com>
This commit is contained in:
parent
653058beac
commit
723645ebb7
@ -330,6 +330,15 @@ config file to be able to detect config errors
|
|||||||
optional: true ++
|
optional: true ++
|
||||||
default: 12 ++
|
default: 12 ++
|
||||||
description: The border radius of the album art. ++
|
description: The border radius of the album art. ++
|
||||||
|
blacklist: ++
|
||||||
|
type: array ++
|
||||||
|
optional: true ++
|
||||||
|
default: [] ++
|
||||||
|
description: Audio sources for the mpris widget to ignore. ++
|
||||||
|
Valid array values: ++
|
||||||
|
type: string ++
|
||||||
|
description: Audio source/app name. Regex alowed. Hint ++
|
||||||
|
`$ qdbus | grep mpris` to find source names. ++
|
||||||
description: A widget that displays multiple music players. ++
|
description: A widget that displays multiple music players. ++
|
||||||
*menubar*++
|
*menubar*++
|
||||||
type: object ++
|
type: object ++
|
||||||
@ -595,7 +604,8 @@ config file to be able to detect config errors
|
|||||||
},
|
},
|
||||||
"mpris": {
|
"mpris": {
|
||||||
"image-size": 96,
|
"image-size": 96,
|
||||||
"image-radius": 12
|
"image-radius": 12,
|
||||||
|
"blacklist": ["playerctld"]
|
||||||
},
|
},
|
||||||
"menubar": {
|
"menubar": {
|
||||||
"menu#power": {
|
"menu#power": {
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
"mpris": {
|
"mpris": {
|
||||||
"image-size": 96,
|
"image-size": 96,
|
||||||
"image-radius": 12
|
"image-radius": 12
|
||||||
|
"blacklist": []
|
||||||
},
|
},
|
||||||
"buttons-grid": {
|
"buttons-grid": {
|
||||||
"actions": [
|
"actions": [
|
||||||
|
@ -3,6 +3,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
|||||||
int image_size;
|
int image_size;
|
||||||
int image_radius;
|
int image_radius;
|
||||||
bool blur;
|
bool blur;
|
||||||
|
string[] blacklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Mpris : BaseWidget {
|
public class Mpris : BaseWidget {
|
||||||
@ -99,6 +100,18 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
|||||||
bool blur_found;
|
bool blur_found;
|
||||||
bool? blur = get_prop<bool> (config, "blur", out blur_found);
|
bool? blur = get_prop<bool> (config, "blur", out blur_found);
|
||||||
if (blur_found) mpris_config.blur = blur;
|
if (blur_found) mpris_config.blur = blur;
|
||||||
|
|
||||||
|
Json.Array ? blacklist = get_prop_array (config, "blacklist");
|
||||||
|
if (blacklist != null) {
|
||||||
|
mpris_config.blacklist = new string[blacklist.get_length ()];
|
||||||
|
for (int i = 0; i < blacklist.get_length (); i++) {
|
||||||
|
if (blacklist.get_element (i).get_node_type () != Json.NodeType.VALUE) {
|
||||||
|
warning ("Blacklist entries should be strings");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mpris_config.blacklist[i] = blacklist.get_string_element (i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hide ();
|
hide ();
|
||||||
@ -174,6 +187,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
|||||||
string[] names = dbus_iface.list_names ();
|
string[] names = dbus_iface.list_names ();
|
||||||
foreach (string name in names) {
|
foreach (string name in names) {
|
||||||
if (!name.has_prefix (MPRIS_PREFIX)) continue;
|
if (!name.has_prefix (MPRIS_PREFIX)) continue;
|
||||||
|
if (is_blacklisted (name)) continue;
|
||||||
if (check_player_exists (name)) return;
|
if (check_player_exists (name)) return;
|
||||||
MprisSource ? source = MprisSource.get_player (name);
|
MprisSource ? source = MprisSource.get_player (name);
|
||||||
if (source != null) add_player (name, source);
|
if (source != null) add_player (name, source);
|
||||||
@ -185,6 +199,7 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
|||||||
remove_player (name);
|
remove_player (name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (is_blacklisted (name)) return;
|
||||||
if (check_player_exists (name)) return;
|
if (check_player_exists (name)) return;
|
||||||
MprisSource ? source = MprisSource.get_player (name);
|
MprisSource ? source = MprisSource.get_player (name);
|
||||||
if (source != null) add_player (name, source);
|
if (source != null) add_player (name, source);
|
||||||
@ -243,5 +258,18 @@ namespace SwayNotificationCenter.Widgets.Mpris {
|
|||||||
0, children_length - 1);
|
0, children_length - 1);
|
||||||
carousel.scroll_to (children.nth_data (position));
|
carousel.scroll_to (children.nth_data (position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool is_blacklisted (string name) {
|
||||||
|
foreach (string blacklistedPattern in mpris_config.blacklist) {
|
||||||
|
if (blacklistedPattern == null || blacklistedPattern.length == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (GLib.Regex.match_simple (blacklistedPattern, name, GLib.RegexCompileFlags.JAVASCRIPT_COMPAT, 0)) {
|
||||||
|
message ("\"%s\" is blacklisted", name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user