Implemented cmd args into client with a help menu

This commit is contained in:
Erik Reider
2021-07-28 21:03:43 +02:00
parent c25e587490
commit ef26e63efb
2 changed files with 84 additions and 9 deletions

View File

@@ -1,16 +1,79 @@
[DBus (name = "org.erikreider.swaync.cc")]
interface CcDaemon : GLib.Object {
public abstract uint notification_count () throws DBusError, IOError;
public abstract void toggle () throws DBusError, IOError;
public signal void on_notificaion (uint count);
}
public void main (string[] args) {
public class Client : Application {
private CcDaemon cc_daemon = null;
public Client () {
Object (application_id: "org.erikreider.swaync.client",
flags : ApplicationFlags.HANDLES_COMMAND_LINE);
set_inactivity_timeout (10000);
try {
CcDaemon controlCenter = Bus.get_proxy_sync (BusType.SESSION, "org.erikreider.swaync.cc",
cc_daemon = Bus.get_proxy_sync (
BusType.SESSION,
"org.erikreider.swaync.cc",
"/org/erikreider/swaync/cc");
controlCenter.toggle ();
} catch (IOError e) {
stderr.printf ("Could not connect to CC service\n");
} catch (DBusError e) {
} 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;
}
}

View File

@@ -9,6 +9,8 @@ namespace SwayNotificatonCenter {
cc = new ControlCenterWidget ();
}
public signal void on_notificaion (uint count);
public bool get_visibility () throws DBusError, IOError {
return cc.visible;
}
@@ -17,6 +19,10 @@ namespace SwayNotificatonCenter {
cc.close_all_notifications ();
}
public uint notification_count () throws DBusError, IOError {
return cc.notification_count ();
}
public void toggle () throws DBusError, IOError {
if (cc.toggle_visibility ()) {
dbusInit.notiDaemon.set_noti_window_visibility (false);
@@ -25,10 +31,12 @@ namespace SwayNotificatonCenter {
public void add_notification (NotifyParams param) throws DBusError, IOError {
cc.add_notification (param, dbusInit.notiDaemon);
on_notificaion (notification_count ());
}
public void close_notification (uint32 id) throws DBusError, IOError {
cc.close_notification (id);
on_notificaion (notification_count ());
}
}
@@ -46,6 +54,10 @@ namespace SwayNotificatonCenter {
GtkLayerShell.set_anchor (this, GtkLayerShell.Edge.RIGHT, true);
}
public uint notification_count () {
return box.get_children ().length ();
}
public void close_all_notifications () {
foreach (var w in box.get_children ()) {
box.remove (w);