From 8b7dba6555f7508b948afca89f8be294b9472d63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yi=C4=9Fit=20=C3=87olako=C4=9Flu?= Date: Thu, 18 Mar 2021 12:18:23 +0300 Subject: [PATCH] Fixed mpris crash when service does not respond (ex. spotifyd) Added battery command to mconnectctl --- meson.build | 1 + src/mconnect/mpris.vala | 7 ++++++- src/mconnect/utils.vala | 4 ++-- src/mconnectctl/battery-iface.vala | 30 ++++++++++++++++++++++++++++++ src/mconnectctl/main.vala | 29 ++++++++++++++++++++++++++++- 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 src/mconnectctl/battery-iface.vala diff --git a/meson.build b/meson.build index 8d90d1d..8649171 100644 --- a/meson.build +++ b/meson.build @@ -75,6 +75,7 @@ mconnectctl_src = [ 'src/mconnectctl/main.vala', 'src/mconnectctl/device-manager-iface.vala', 'src/mconnectctl/device-iface.vala', + 'src/mconnectctl/battery-iface.vala', 'src/mconnectctl/share-iface.vala', 'src/mconnectctl/telephony-iface.vala', ] diff --git a/src/mconnect/mpris.vala b/src/mconnect/mpris.vala index b92ad38..c02f4ef 100644 --- a/src/mconnect/mpris.vala +++ b/src/mconnect/mpris.vala @@ -396,7 +396,12 @@ class MprisHandler : Object, PacketHandlerInterface { MprisProxy mpris = Bus.get_proxy_sync (BusType.SESSION, bus_name, "/org/mpris/MediaPlayer2"); - player_list.insert (mpris.identity, bus_name); + debug(mpris.identity); + if(mpris.identity == null){ + warning ("failed to connect to mpris player"); + }else{ + player_list.insert (mpris.identity, bus_name); + } } catch (Error e) { warning ("failed to connect to mpris player: %s", e.message); } diff --git a/src/mconnect/utils.vala b/src/mconnect/utils.vala index 1d7f5cb..83e35bf 100644 --- a/src/mconnect/utils.vala +++ b/src/mconnect/utils.vala @@ -160,7 +160,7 @@ namespace Utils { // regex taken from SO // uncrustify breaks the regex, so *INDENT-OFF* - Regex r = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+,.~#?&\/=]*)/; + GLib.Regex r = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+,.~#?&\/=]*)/; // *INDENT-ON* MatchInfo mi; @@ -180,7 +180,7 @@ namespace Utils { debug ("no match"); } return matches; - } catch (RegexError e) { + } catch (GLib.RegexError e) { warning ("failed to compile regex: %s", e.message); return {}; } diff --git a/src/mconnectctl/battery-iface.vala b/src/mconnectctl/battery-iface.vala new file mode 100644 index 0000000..12831a6 --- /dev/null +++ b/src/mconnectctl/battery-iface.vala @@ -0,0 +1,30 @@ +/** + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * AUTHORS + * Maciek Borzecki + */ +namespace Mconnect { + + [DBus (name = "org.mconnect.Device.Battery")] + public interface BatteryIface : Object { + + public abstract uint level { + owned get; + } + public abstract bool charging { + owned get; + } + } +} diff --git a/src/mconnectctl/main.vala b/src/mconnectctl/main.vala index ebee13a..62f6086 100644 --- a/src/mconnectctl/main.vala +++ b/src/mconnectctl/main.vala @@ -66,6 +66,7 @@ namespace Mconnect { list-devices List devices allow-device Allow device show-device Show device details + show-battery Show device battery & charging share-url Share URL with device share-text Share text with device @@ -94,6 +95,7 @@ namespace Mconnect { Command ("list-devices", 0, cl.cmd_list_devices), Command ("allow-device", 1, cl.cmd_allow_device), Command ("show-device", 1, cl.cmd_show_device), + Command ("show-battery", 1, cl.cmd_show_battery), Command ("share-url", 2, cl.cmd_share_url), Command ("share-text", 2, cl.cmd_share_text), Command ("share-file", 2, cl.cmd_share_file), @@ -136,6 +138,7 @@ namespace Mconnect { } debug ("running callback"); + debug("TEST"); return cmden.clbk (command_args); } } @@ -254,6 +257,18 @@ namespace Mconnect { }); } + private int cmd_show_battery(string[] args) { + debug("DEBUG_0"); + return checked_dbus_call (() => { + var bt = get_battery (new ObjectPath (args[0])); + + stdout.printf ("Level: %u\n" + + "Charging: %d\n", + bt.level, + bt.charging); + return 0; + }); + } private delegate int CheckDBusCallFunc () throws Error; /** @@ -323,6 +338,18 @@ namespace Mconnect { return get_mconnect_obj_proxy (path); } + /** + * get_device: + * @path device object path + * + * Obtain DBus interface to Device.Battery + * + * @return interface or null + */ + private BatteryIface ? get_battery (ObjectPath path) throws IOError { + return get_mconnect_obj_proxy (path); + } + /** * get_share: * @@ -378,4 +405,4 @@ namespace Mconnect { private delegate string GetDescFunc (ObjectPath obj_path); } -} \ No newline at end of file +}