Skip to content

Commit

Permalink
Fix tray icon
Browse files Browse the repository at this point in the history
  • Loading branch information
torikulhabib committed Apr 15, 2023
1 parent 07ed816 commit 12a89b8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 52 deletions.
29 changes: 14 additions & 15 deletions src/DbusIndicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Gabut {

public string id {
get {
return Environment.get_application_name ();
return updatesnewid;
}
}
public string category {
Expand All @@ -41,7 +41,7 @@ namespace Gabut {
}
public string status {
get {
return "Active";
return updatestatus;
}
}
public string icon_name {
Expand Down Expand Up @@ -98,32 +98,31 @@ namespace Gabut {
internal static DbusStatusWhacher dbusstatuswatcher = null;
internal string updateLabel = "";
internal string updateiconame = "com.github.gabutakut.gabutdm";
internal string updatestatus = "Active";
internal string updatesnewid = "";
public DbusIndicator (string path) {
objectpat = new ObjectPath (path);
}

internal async void register_dbus () throws Error {
var session_connection = yield GLib.Bus.@get (GLib.BusType.SESSION);
session_connection.register_object (objectpat, this);
Bus.get_proxy.begin<DbusStatusWhacher> (BusType.SESSION, "org.kde.StatusNotifierWatcher", "/StatusNotifierWatcher", GLib.DBusProxyFlags.NONE, null, (obj, res) => {
try {
dbusstatuswatcher = Bus.get_proxy.end (res);
((GLib.DBusProxy) dbusstatuswatcher).g_connection.signal_subscribe (null, "org.kde.StatusNotifierWatcher", null, "/StatusNotifierWatcher", null, GLib.DBusSignalFlags.NONE, (GLib.DBusSignalCallback)subscription_callback);
if (dbusstatuswatcher != null) {
dbusstatuswatcher.register_status_notifier_item (objectpat);
updatesnewid = Environment.get_application_name ();
}
} catch (GLib.Error e) {
critical (e.message);
}
});
}

internal void subscription_callback (DBusConnection connection, string? sender_name, string object_path, string interface_name, string signal_name, Variant parameters) {}

internal async void register_dbus () throws Error {
var session_connection = yield GLib.Bus.@get (GLib.BusType.SESSION);
session_connection.register_object (objectpat, this);
}
public void scroll (int delta, int orientation) throws GLib.Error {
}
public void secondary_activate (int x, int y) throws GLib.Error {
}
public void x_ayatana_secondary_activate (uint timestamp) throws GLib.Error {
}
private void subscription_callback (DBusConnection connection, string? sender_name, string object_path, string interface_name, string signal_name, Variant parameters) {}
public void scroll (int delta, int orientation) throws GLib.Error {}
public void secondary_activate (int x, int y) throws GLib.Error {}
public void x_ayatana_secondary_activate (uint timestamp) throws GLib.Error {}
}
}
90 changes: 58 additions & 32 deletions src/GabutWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ namespace Gabut {
}
set {
_dbmenu = value;
if (dbusserver != null && dbusindicator != null) {
if (!dbmenu) {
dbusindicator.updatestatus = "Passive";
} else {
update_quicklist.begin ();
if (indmenu) {
dbusindicator.updatestatus = "Active";
}
}
if (indmenu) {
dbusindicator.register_dbus.begin ();
}
dbusindicator.new_status (dbusindicator.updatestatus);
}
}
}

Expand All @@ -87,6 +101,17 @@ namespace Gabut {
}
set {
_indmenu = value;
if (dbusserver != null && dbusindicator != null) {
if (indmenu) {
dbusindicator.updatestatus = "Active";
} else {
dbusindicator.updatestatus = "Passive";
}
if (dbmenu) {
dbusindicator.register_dbus.begin ();
}
dbusindicator.new_status (dbusindicator.updatestatus);
}
}
}

Expand All @@ -97,16 +122,14 @@ namespace Gabut {
}
set {
_menulabel = value;
if (indmenu) {
if (_menulabel == 0) {
dbusindicator.updateLabel = "";
} else if (_menulabel == 1) {
dbusindicator.updateLabel = title;
} else {
update_info ();
}
dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, "");
if (_menulabel == 0) {
dbusindicator.updateLabel = "";
} else if (_menulabel == 1) {
dbusindicator.updateLabel = title;
} else {
update_info ();
}
dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, "");
}
}

Expand All @@ -119,12 +142,9 @@ namespace Gabut {

construct {
dbmenu = bool.parse (get_dbsetting (DBSettings.DBUSMENU));
indmenu = bool.parse (get_dbsetting (DBSettings.MENUINDICATOR));
dbusserver = new CanonicalDbusmenu ();
dbusindicator = new DbusIndicator (dbusserver.dbus_object);
if (indmenu) {
dbusindicator.register_dbus.begin ();
}
indmenu = bool.parse (get_dbsetting (DBSettings.MENUINDICATOR));
openmenu = new DbusmenuItem ();
openmenu.property_set (MenuItem.LABEL.to_string (), _("Gabut Download Manager"));
openmenu.property_set (MenuItem.ICON_NAME.to_string (), "com.github.gabutakut.gabutdm");
Expand Down Expand Up @@ -355,30 +375,30 @@ namespace Gabut {
update_options ();
});
preferences.close.connect (()=> {
if (bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)) != hide_on_close) {
hide_on_close = bool.parse (get_dbsetting (DBSettings.ONBACKGROUND));
}
if (bool.parse (get_dbsetting (DBSettings.DBUSMENU)) != dbmenu) {
dbmenu = bool.parse (get_dbsetting (DBSettings.DBUSMENU));
}
menulabel = int.parse (get_dbsetting (DBSettings.LABELMODE));
preferences = null;
save_close ();
});
preferences.close_request.connect (()=> {
if (bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)) != hide_on_close) {
hide_on_close = bool.parse (get_dbsetting (DBSettings.ONBACKGROUND));
}
if (bool.parse (get_dbsetting (DBSettings.DBUSMENU)) != dbmenu) {
dbmenu = bool.parse (get_dbsetting (DBSettings.DBUSMENU));
}
menulabel = int.parse (get_dbsetting (DBSettings.LABELMODE));
preferences = null;
save_close ();
return false;
});
preferences.show ();
}
}

private void save_close () {
if (bool.parse (get_dbsetting (DBSettings.ONBACKGROUND)) != hide_on_close) {
hide_on_close = bool.parse (get_dbsetting (DBSettings.ONBACKGROUND));
}
if (bool.parse (get_dbsetting (DBSettings.DBUSMENU)) != dbmenu) {
dbmenu = bool.parse (get_dbsetting (DBSettings.DBUSMENU));
}
menulabel = int.parse (get_dbsetting (DBSettings.LABELMODE));
if (bool.parse (get_dbsetting (DBSettings.MENUINDICATOR)) != indmenu) {
indmenu = bool.parse (get_dbsetting (DBSettings.MENUINDICATOR));
}
preferences = null;
}

private Gtk.CenterBox bottom_action () {
var actionbar = new Gtk.CenterBox () {
hexpand = true,
Expand Down Expand Up @@ -853,7 +873,7 @@ namespace Gabut {
var activedmapp = int64.parse (infol.fetch (2));
labelall.label = @"Active: $(activedmapp) Download: $(GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (1)) : 0)) Upload: $(GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (6)) : 0))";
if (menulabel == 2 && indmenu) {
dbusindicator.updateLabel = @" $(GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (1)) : 0))";
dbusindicator.updateLabel = @" $(GLib.format_size (activedmapp > 0? int64.parse (infol.fetch (6)) + int64.parse (infol.fetch (1)) : 0))";
dbusindicator.x_ayatana_new_label (dbusindicator.updateLabel, "");
}
}
Expand Down Expand Up @@ -931,7 +951,7 @@ namespace Gabut {
menudbus.child_append (rowbus);
}
if (dbmenu) {
open_quicklist_dbus.begin (dbusserver, menudbus);
yield open_quicklist_dbus (dbusserver, menudbus);
}
}

Expand All @@ -940,7 +960,13 @@ namespace Gabut {
menudbus.child_delete (rowbus);
}
if (dbmenu) {
open_quicklist_dbus.begin (dbusserver, menudbus);
yield open_quicklist_dbus (dbusserver, menudbus);
}
}

private async void update_quicklist () throws GLib.Error {
if (dbmenu) {
yield open_quicklist_dbus (dbusserver, menudbus);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Preferences.vala
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ namespace Gabut {
var label_mode = new ModeTogle ();
label_mode.add_item (new ModeTogle.with_label (_("None")));
label_mode.add_item (new ModeTogle.with_label (_("App Name")));
label_mode.add_item (new ModeTogle.with_label (_("Download Speed")));
label_mode.add_item (new ModeTogle.with_label (_("Total Speed")));
label_mode.id = int.parse (get_dbsetting (DBSettings.LABELMODE));
menuindicator.toggled.connect (()=> {
label_mode.sensitive_box (dbusmenu.active && menuindicator.active);
Expand Down
8 changes: 4 additions & 4 deletions src/UnityLauncherEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace Gabut {
[DBus (name = "com.canonical.Unity.LauncherEntry")]
private class UnityLauncherEntry : GLib.Object {
public signal void update (string app_uri, GLib.HashTable<string, GLib.Variant> properties);
private GLib.HashTable<string, GLib.Variant> properties;
private static string app_uri = get_app_id ();
private static uint removebus = 0;
private static UnityLauncherEntry instance;
internal GLib.HashTable<string, GLib.Variant> properties;
internal static string app_uri = get_app_id ();
internal static uint removebus = 0;
internal static UnityLauncherEntry instance;

internal static async unowned UnityLauncherEntry get_instance () throws GLib.Error {
var local_instance = new UnityLauncherEntry ();
Expand Down

0 comments on commit 12a89b8

Please sign in to comment.