Browse Source

Fixed mpris crash when service does not respond (ex. spotifyd) Added battery command to mconnectctl

master
Yiğit Çolakoğlu 4 years ago
parent
commit
8b7dba6555
5 changed files with 67 additions and 4 deletions
  1. +1
    -0
      meson.build
  2. +6
    -1
      src/mconnect/mpris.vala
  3. +2
    -2
      src/mconnect/utils.vala
  4. +30
    -0
      src/mconnectctl/battery-iface.vala
  5. +28
    -1
      src/mconnectctl/main.vala

+ 1
- 0
meson.build View File

@ -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',
]


+ 6
- 1
src/mconnect/mpris.vala View File

@ -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);
}


+ 2
- 2
src/mconnect/utils.vala View File

@ -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 {};
}


+ 30
- 0
src/mconnectctl/battery-iface.vala View File

@ -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 <maciek.borzecki (at] gmail.com>
*/
namespace Mconnect {
[DBus (name = "org.mconnect.Device.Battery")]
public interface BatteryIface : Object {
public abstract uint level {
owned get;
}
public abstract bool charging {
owned get;
}
}
}

+ 28
- 1
src/mconnectctl/main.vala View File

@ -66,6 +66,7 @@ namespace Mconnect {
list-devices List devices
allow-device <path> Allow device
show-device <path> Show device details
show-battery <path> Show device battery & charging
share-url <path> <url> Share URL with device
share-text <path> <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);
}
}
}

Loading…
Cancel
Save