Implemented cmd args into client with a help menu
This commit is contained in:
@@ -1,16 +1,79 @@
|
|||||||
[DBus (name = "org.erikreider.swaync.cc")]
|
[DBus (name = "org.erikreider.swaync.cc")]
|
||||||
interface CcDaemon : GLib.Object {
|
interface CcDaemon : GLib.Object {
|
||||||
|
|
||||||
|
public abstract uint notification_count () throws DBusError, IOError;
|
||||||
|
|
||||||
public abstract void toggle () throws DBusError, IOError;
|
public abstract void toggle () throws DBusError, IOError;
|
||||||
|
|
||||||
|
public signal void on_notificaion (uint count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void main (string[] args) {
|
|
||||||
try {
|
public class Client : Application {
|
||||||
CcDaemon controlCenter = Bus.get_proxy_sync (BusType.SESSION, "org.erikreider.swaync.cc",
|
private CcDaemon cc_daemon = null;
|
||||||
"/org/erikreider/swaync/cc");
|
|
||||||
controlCenter.toggle ();
|
public Client () {
|
||||||
} catch (IOError e) {
|
Object (application_id: "org.erikreider.swaync.client",
|
||||||
stderr.printf ("Could not connect to CC service\n");
|
flags : ApplicationFlags.HANDLES_COMMAND_LINE);
|
||||||
} catch (DBusError e) {
|
set_inactivity_timeout (10000);
|
||||||
stderr.printf ("Could not connect to CC service\n");
|
try {
|
||||||
|
cc_daemon = Bus.get_proxy_sync (
|
||||||
|
BusType.SESSION,
|
||||||
|
"org.erikreider.swaync.cc",
|
||||||
|
"/org/erikreider/swaync/cc");
|
||||||
|
} catch (Error e) {
|
||||||
|
stderr.printf ("Could not connect to CC service\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void print_help (string[] args) {
|
||||||
|
print(@"Usage:\n");
|
||||||
|
print(@"\t $(args[0]) <OPTION>\n");
|
||||||
|
print(@"Help:\n");
|
||||||
|
print(@"\t -h, --help \t\t Show help options\n");
|
||||||
|
print(@"Options:\n");
|
||||||
|
print(@"\t -t, --toggle \t\t Toggle the notificaion panel\n");
|
||||||
|
print(@"\t -c, --count \t\t Print the current notificaion count\n");
|
||||||
|
print(@"\t -s, --subscribe \t Subscribe to notificaion add and close events\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int command_line (ApplicationCommandLine cmd_line) {
|
||||||
|
try {
|
||||||
|
string[] args = cmd_line.get_arguments ();
|
||||||
|
if (args.length < 2) {
|
||||||
|
print_help (args);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
switch (args[1]) {
|
||||||
|
case "--help":
|
||||||
|
case "-h":
|
||||||
|
print_help (args);
|
||||||
|
break;
|
||||||
|
case "--count":
|
||||||
|
case "-c":
|
||||||
|
print (cc_daemon.notification_count ().to_string ());
|
||||||
|
break;
|
||||||
|
case "--toggle":
|
||||||
|
case "-t":
|
||||||
|
cc_daemon.toggle ();
|
||||||
|
break;
|
||||||
|
case "--subscribe":
|
||||||
|
case "-s":
|
||||||
|
cc_daemon.on_notificaion.connect ((c) => print (c.to_string ()));
|
||||||
|
var loop = new MainLoop ();
|
||||||
|
loop.run ();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (Error e) {
|
||||||
|
stderr.printf (e.message + "\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int main (string[] args) {
|
||||||
|
Client client = new Client ();
|
||||||
|
int status = client.run (args);
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,8 @@ namespace SwayNotificatonCenter {
|
|||||||
cc = new ControlCenterWidget ();
|
cc = new ControlCenterWidget ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public signal void on_notificaion (uint count);
|
||||||
|
|
||||||
public bool get_visibility () throws DBusError, IOError {
|
public bool get_visibility () throws DBusError, IOError {
|
||||||
return cc.visible;
|
return cc.visible;
|
||||||
}
|
}
|
||||||
@@ -17,6 +19,10 @@ namespace SwayNotificatonCenter {
|
|||||||
cc.close_all_notifications ();
|
cc.close_all_notifications ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public uint notification_count () throws DBusError, IOError {
|
||||||
|
return cc.notification_count ();
|
||||||
|
}
|
||||||
|
|
||||||
public void toggle () throws DBusError, IOError {
|
public void toggle () throws DBusError, IOError {
|
||||||
if (cc.toggle_visibility ()) {
|
if (cc.toggle_visibility ()) {
|
||||||
dbusInit.notiDaemon.set_noti_window_visibility (false);
|
dbusInit.notiDaemon.set_noti_window_visibility (false);
|
||||||
@@ -25,10 +31,12 @@ namespace SwayNotificatonCenter {
|
|||||||
|
|
||||||
public void add_notification (NotifyParams param) throws DBusError, IOError {
|
public void add_notification (NotifyParams param) throws DBusError, IOError {
|
||||||
cc.add_notification (param, dbusInit.notiDaemon);
|
cc.add_notification (param, dbusInit.notiDaemon);
|
||||||
|
on_notificaion (notification_count ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close_notification (uint32 id) throws DBusError, IOError {
|
public void close_notification (uint32 id) throws DBusError, IOError {
|
||||||
cc.close_notification (id);
|
cc.close_notification (id);
|
||||||
|
on_notificaion (notification_count ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,6 +54,10 @@ namespace SwayNotificatonCenter {
|
|||||||
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
|
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public uint notification_count () {
|
||||||
|
return box.get_children ().length ();
|
||||||
|
}
|
||||||
|
|
||||||
public void close_all_notifications () {
|
public void close_all_notifications () {
|
||||||
foreach (var w in box.get_children ()) {
|
foreach (var w in box.get_children ()) {
|
||||||
box.remove (w);
|
box.remove (w);
|
||||||
|
Reference in New Issue
Block a user