From e33b33ca68b4791f53bdc4e1825b774680662921 Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Thu, 10 Oct 2024 10:09:15 +0500 Subject: [PATCH 1/6] Updated handle for chromium albumArt in a PlayerRow --- src/Widgets/PlayerRow.vala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index 9e3a9132..c3e42019 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -482,6 +482,15 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { if (uri.has_prefix ("file://")) { string fname = uri.split ("file://")[1]; + + /** + * If a MPRIS source is Google Chrome, we can see strange file uri "file:///tmp/.com.google.Chrome.{Hash}", + * being stored in runtime directory, and we should handle it properly to display albumArt. + */ + if (fname.has_prefix ("/tmp/.com.google.Chrome")) { + fname = GLib.Environment.get_user_runtime_dir () + "/.flatpak/com.google.Chrome" + fname; + } + try { var pbuf = new Gdk.Pixbuf.from_file_at_size (fname, ICON_SIZE * scale, ICON_SIZE * scale); background.gicon = mask_pixbuf (pbuf, scale); From d868a0cb81738e0b13d1254d2f22c9b71912907f Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Tue, 15 Oct 2024 16:09:39 +0500 Subject: [PATCH 2/6] Updated PlayerRow albumArt loading --- src/Widgets/PlayerRow.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index c3e42019..23ea0b34 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -484,11 +484,11 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { string fname = uri.split ("file://")[1]; /** - * If a MPRIS source is Google Chrome, we can see strange file uri "file:///tmp/.com.google.Chrome.{Hash}", - * being stored in runtime directory, and we should handle it properly to display albumArt. + * For some MPRIS sources, we can see strange file uri like "file:///tmp/.com.google.Chrome.{Hash}", + * files being stored in users runtime directory, and we should handle it properly to display albumArt. */ - if (fname.has_prefix ("/tmp/.com.google.Chrome")) { - fname = GLib.Environment.get_user_runtime_dir () + "/.flatpak/com.google.Chrome" + fname; + if (! FileUtils.test (fname, FileTest.EXISTS)) { + fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", "com.google.Chrome", fname); } try { From a4951161c2d9ba66f4dea7880c3fa07f285f261d Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Wed, 16 Oct 2024 10:07:48 +0500 Subject: [PATCH 3/6] Updated handler for AlbumArt in PlayerRow Added Regex solution for strange app<->folder relations --- src/Widgets/PlayerRow.vala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index 23ea0b34..22c2145c 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -484,11 +484,25 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { string fname = uri.split ("file://")[1]; /** - * For some MPRIS sources, we can see strange file uri like "file:///tmp/.com.google.Chrome.{Hash}", - * files being stored in users runtime directory, and we should handle it properly to display albumArt. + * For some MPRIS sources, e.g. flatpak based Chromium, we can see strange file uri like "file:///tmp/.com.google.Chrome.{Hash}", + * but files being stored in users runtime directory, and we should handle it properly to display albumArt. + * According to MPRIS spec (https://specifications.freedesktop.org/mpris-spec/latest/#Bus-Name-Policy) + * we wont get actual app name, because chrome developers set it to `chromium` as DBUS name, + * e.g. 'org.mpris.MediaPlayer2.chromium.instance33959'. But it has no connection to actual app name and files folder. + * + * Tested version of Chrom(e/ium): 129.0.6668.100 + * One of possible solutions: to use RegExp. + * + * To be reviewed in future. */ if (! FileUtils.test (fname, FileTest.EXISTS)) { - fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", "com.google.Chrome", fname); + Regex tempAppFolderRegex = /^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; + MatchInfo info; + if(tempAppFolderRegex.match(fname, 0, out info)) { + var appName = info.fetch_named("appName"); + + fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", appName, fname); + } } try { From 36a1c84b24789b4514872c9aa00695eab227100e Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Mon, 21 Oct 2024 12:35:49 +0500 Subject: [PATCH 4/6] Updated PlayerRow due to code style violations --- src/Widgets/PlayerRow.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index 22c2145c..efaa7742 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -496,10 +496,10 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { * To be reviewed in future. */ if (! FileUtils.test (fname, FileTest.EXISTS)) { - Regex tempAppFolderRegex = /^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; - MatchInfo info; - if(tempAppFolderRegex.match(fname, 0, out info)) { - var appName = info.fetch_named("appName"); + Regex temp_regex = @/^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; + MatchInfo regex_match; + if (temp_regex.match (fname, 0, out info)) { + var app_name = info.fetch_named ("appName"); fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", appName, fname); } From e0f1f413719e5934aa14d4dcca54a6816b1e259d Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Mon, 21 Oct 2024 12:56:23 +0500 Subject: [PATCH 5/6] Updated PlayerRow due to typos --- src/Widgets/PlayerRow.vala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index efaa7742..5b159058 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -496,12 +496,12 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { * To be reviewed in future. */ if (! FileUtils.test (fname, FileTest.EXISTS)) { - Regex temp_regex = @/^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; + Regex temp_regex = /^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; MatchInfo regex_match; - if (temp_regex.match (fname, 0, out info)) { - var app_name = info.fetch_named ("appName"); + if (temp_regex.match (fname, 0, out regex_match)) { + var app_name = regex_match.fetch_named ("appName"); - fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", appName, fname); + fname = Path.build_path (Path.DIR_SEPARATOR_S, GLib.Environment.get_user_runtime_dir (), ".flatpak", app_name, fname); } } From 201b5526382626cc1517d6e9b932920a6e3fd829 Mon Sep 17 00:00:00 2001 From: Dmitry Besedin Date: Wed, 23 Oct 2024 13:42:18 +0500 Subject: [PATCH 6/6] Updated PlayerRow due to linter errors --- src/Widgets/PlayerRow.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Widgets/PlayerRow.vala b/src/Widgets/PlayerRow.vala index 5b159058..733d3c4e 100644 --- a/src/Widgets/PlayerRow.vala +++ b/src/Widgets/PlayerRow.vala @@ -496,7 +496,8 @@ public class Sound.Widgets.PlayerRow : Gtk.Box { * To be reviewed in future. */ if (! FileUtils.test (fname, FileTest.EXISTS)) { - Regex temp_regex = /^(\/tmp\/\.)(?P([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$/; + string folder_pattern = "^(/tmp/.)(?([a-zA-Z]*[.]){2}([a-zA-Z]*)).*$"; + Regex temp_regex = new Regex (folder_pattern); MatchInfo regex_match; if (temp_regex.match (fname, 0, out regex_match)) { var app_name = regex_match.fetch_named ("appName");