mirror of
https://github.com/zoriya/astal.git
synced 2026-06-03 02:23:44 +00:00
add cli tool
This commit is contained in:
+2
-1
@@ -1 +1,2 @@
|
||||
option('typelib', type: 'boolean', value: true, description: 'Needed files for runtime bindings')
|
||||
option('typelib', type: 'boolean', value: true, description: 'Needed files for runtime bindings.')
|
||||
option('cli', type: 'boolean', value: true, description: 'a simple cli tool for interacting with the tray.')
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
static bool help;
|
||||
static bool version;
|
||||
static bool daemonize;
|
||||
|
||||
const OptionEntry[] options = {
|
||||
{ "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, "Print version number", null },
|
||||
{ "daemon", 'd', OptionFlags.NONE, OptionArg.NONE, ref daemonize, "Monitor the systemtray", null },
|
||||
{ null },
|
||||
};
|
||||
|
||||
int main(string[] argv) {
|
||||
try {
|
||||
var opts = new OptionContext();
|
||||
opts.add_main_entries(options, null);
|
||||
opts.set_help_enabled(true);
|
||||
opts.set_ignore_unknown_options(false);
|
||||
opts.parse(ref argv);
|
||||
} catch (OptionError err) {
|
||||
printerr (err.message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
var loop = new MainLoop();
|
||||
var tray = new AstalTray.Tray();
|
||||
|
||||
if (version) {
|
||||
print(AstalTray.VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (daemonize) {
|
||||
tray.item_added.connect((id) => {
|
||||
|
||||
AstalTray.TrayItem item = tray.get_item(id);
|
||||
|
||||
string item_json = item.to_json_string();
|
||||
stdout.printf("{\"event\":\"item_added\",\"id\":\"%s\",\"item\":%s}\n",
|
||||
id, item_json);
|
||||
stdout.flush();
|
||||
|
||||
item.changed.connect(() => {
|
||||
stdout.printf("{\"event\":\"item_changed\",\"id\":\"%s\",\"item\":%s}\n",
|
||||
id, item_json);
|
||||
stdout.flush();
|
||||
});
|
||||
});
|
||||
tray.item_removed.connect((id) => {
|
||||
stdout.printf("{\"event\":\"item_removed\",\"id\":\"%s\"}\n", id);
|
||||
stdout.flush();
|
||||
});
|
||||
}
|
||||
|
||||
loop.run();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace AstalTray {
|
||||
const int MAJOR_VERSION = @MAJOR_VERSION@;
|
||||
const int MINOR_VERSION = @MINOR_VERSION@;
|
||||
const int MICRO_VERSION = @MICRO_VERSION@;
|
||||
const string VERSION = "@VERSION@";
|
||||
}
|
||||
+25
-2
@@ -4,6 +4,17 @@ tray_gir = 'AstalTray-' + api_version + '.gir'
|
||||
tray_typelib = 'AstalTray-' + api_version + '.typelib'
|
||||
tray_so = 'libastal-tray.so.' + meson.project_version()
|
||||
|
||||
config = configure_file(
|
||||
input: 'config.vala.in',
|
||||
output: 'config.vala',
|
||||
configuration: {
|
||||
'VERSION': meson.project_version(),
|
||||
'MAJOR_VERSION': version_split[0],
|
||||
'MINOR_VERSION': version_split[1],
|
||||
'MICRO_VERSION': version_split[2],
|
||||
},
|
||||
)
|
||||
|
||||
deps = [
|
||||
dependency('glib-2.0'),
|
||||
dependency('gobject-2.0'),
|
||||
@@ -33,11 +44,12 @@ dbusmenu_libs = run_command(
|
||||
check: true,
|
||||
).stdout().strip()
|
||||
|
||||
sources = files(
|
||||
sources = [
|
||||
config,
|
||||
'tray.vala',
|
||||
'watcher.vala',
|
||||
'trayItem.vala'
|
||||
)
|
||||
]
|
||||
|
||||
libtray = library(
|
||||
meson.project_name(),
|
||||
@@ -82,3 +94,14 @@ if get_option('typelib')
|
||||
)
|
||||
endif
|
||||
|
||||
if get_option('cli')
|
||||
executable(
|
||||
meson.project_name(),
|
||||
['cli.vala', sources],
|
||||
dependencies: deps,
|
||||
vala_args: ['--pkg', 'DbusmenuGtk3-0.4', '--pkg', 'Dbusmenu-0.4'],
|
||||
c_args: dbusmenu_cflags.split(' '),
|
||||
link_args: dbusmenu_libs.split(' '),
|
||||
install: true,
|
||||
)
|
||||
endif
|
||||
|
||||
+35
-8
@@ -93,7 +93,6 @@ namespace AstalTray {
|
||||
public string icon_theme_path { owned get { return proxy.IconThemePath ;} }
|
||||
public bool is_menu { get { return proxy.ItemIsMenu ;} }
|
||||
|
||||
public DbusmenuGtk.Menu? menu { get; private set;}
|
||||
public string icon_name {
|
||||
owned get {
|
||||
if(proxy.Status == Status.NEEDS_ATTENTION)
|
||||
@@ -103,6 +102,8 @@ namespace AstalTray {
|
||||
}
|
||||
|
||||
public Gdk.Pixbuf icon_pixbuf { owned get { return _get_icon_pixbuf(); } }
|
||||
|
||||
public string item_id { get; private set; }
|
||||
|
||||
public signal void changed();
|
||||
public signal void ready();
|
||||
@@ -110,6 +111,7 @@ namespace AstalTray {
|
||||
public TrayItem(string service, string path) {
|
||||
|
||||
connection_ids = new List<ulong>();
|
||||
item_id = service + path;
|
||||
setup_proxy(service, path);
|
||||
|
||||
}
|
||||
@@ -120,13 +122,7 @@ namespace AstalTray {
|
||||
proxy = yield Bus.get_proxy(
|
||||
BusType.SESSION,
|
||||
service,
|
||||
path);
|
||||
|
||||
if(proxy.Menu != null) {
|
||||
menu = new DbusmenuGtk.Menu(
|
||||
proxy.get_name_owner(),
|
||||
proxy.Menu);
|
||||
}
|
||||
path);
|
||||
|
||||
connection_ids.append(proxy.NewStatus.connect(() => refresh_all_properties()));
|
||||
connection_ids.append(proxy.NewToolTip.connect(() => refresh_all_properties()));
|
||||
@@ -190,6 +186,12 @@ namespace AstalTray {
|
||||
});
|
||||
}
|
||||
|
||||
public DbusmenuGtk.Menu create_menu() {
|
||||
if(proxy.Menu == null) return null;
|
||||
return new DbusmenuGtk.Menu(
|
||||
proxy.get_name_owner(),
|
||||
proxy.Menu);
|
||||
}
|
||||
|
||||
public Gdk.Pixbuf? _get_icon_pixbuf() {
|
||||
Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION
|
||||
@@ -252,6 +254,31 @@ namespace AstalTray {
|
||||
(int)(pixmap.width * 4)
|
||||
);
|
||||
}
|
||||
|
||||
public string to_json_string() {
|
||||
var generator = new Json.Generator();
|
||||
generator.set_root(to_json());
|
||||
return generator.to_data(null);
|
||||
}
|
||||
|
||||
internal Json.Node to_json() {
|
||||
return new Json.Builder()
|
||||
.begin_object()
|
||||
.set_member_name("item_id").add_string_value(item_id)
|
||||
.set_member_name("id").add_string_value(id)
|
||||
.set_member_name("bus_name").add_string_value(proxy.g_name)
|
||||
.set_member_name("object_path").add_string_value(proxy.g_object_path)
|
||||
.set_member_name("title").add_string_value(title)
|
||||
.set_member_name("status").add_string_value(status.to_string())
|
||||
.set_member_name("category").add_string_value(category.to_string())
|
||||
.set_member_name("tooltip").add_string_value(tooltip_markup)
|
||||
.set_member_name("icon_theme_path").add_string_value(proxy.IconThemePath)
|
||||
.set_member_name("icon_name").add_string_value(icon_name)
|
||||
.set_member_name("menu_path").add_string_value(proxy.Menu)
|
||||
.set_member_name("is_menu").add_boolean_value(is_menu)
|
||||
.end_object()
|
||||
.get_root();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user