use appindicator for tray icon if in KDE
This commit is contained in:
parent
8d08f87610
commit
d840b05e91
@ -59,6 +59,7 @@ pamac-tray: $(COMMON_SOURCES) alpm_config.vala tray.vala
|
|||||||
valac -o pamac-tray \
|
valac -o pamac-tray \
|
||||||
$(COMMON_VALA_FLAGS) \
|
$(COMMON_VALA_FLAGS) \
|
||||||
--pkg=gtk+-3.0 \
|
--pkg=gtk+-3.0 \
|
||||||
|
--pkg=appindicator3-0.1 \
|
||||||
--pkg=libnotify \
|
--pkg=libnotify \
|
||||||
$(COMMON_SOURCES) \
|
$(COMMON_SOURCES) \
|
||||||
tray.vala
|
tray.vala
|
||||||
|
@ -46,12 +46,15 @@ namespace Pamac {
|
|||||||
bool extern_lock;
|
bool extern_lock;
|
||||||
uint refresh_timeout_id;
|
uint refresh_timeout_id;
|
||||||
Gtk.StatusIcon status_icon;
|
Gtk.StatusIcon status_icon;
|
||||||
|
AppIndicator.Indicator indicator_status_icon;
|
||||||
Gtk.Menu menu;
|
Gtk.Menu menu;
|
||||||
GLib.File lockfile;
|
GLib.File lockfile;
|
||||||
|
bool use_indicator;
|
||||||
|
|
||||||
public TrayIcon () {
|
public TrayIcon () {
|
||||||
application_id = "org.manjaro.pamac.tray";
|
application_id = "org.manjaro.pamac.tray";
|
||||||
flags = ApplicationFlags.FLAGS_NONE;
|
flags = ApplicationFlags.FLAGS_NONE;
|
||||||
|
use_indicator = Environment.get_variable ("XDG_CURRENT_DESKTOP") == "KDE";
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_daemon () {
|
void start_daemon () {
|
||||||
@ -79,8 +82,7 @@ namespace Pamac {
|
|||||||
// Create menu for right button
|
// Create menu for right button
|
||||||
void create_menu () {
|
void create_menu () {
|
||||||
menu = new Gtk.Menu ();
|
menu = new Gtk.Menu ();
|
||||||
Gtk.MenuItem item;
|
var item = new Gtk.MenuItem.with_label (_("Update Manager"));
|
||||||
item = new Gtk.MenuItem.with_label (_("Update Manager"));
|
|
||||||
item.activate.connect (execute_updater);
|
item.activate.connect (execute_updater);
|
||||||
menu.append (item);
|
menu.append (item);
|
||||||
item = new Gtk.MenuItem.with_label (_("Package Manager"));
|
item = new Gtk.MenuItem.with_label (_("Package Manager"));
|
||||||
@ -90,6 +92,9 @@ namespace Pamac {
|
|||||||
item.activate.connect (this.release);
|
item.activate.connect (this.release);
|
||||||
menu.append (item);
|
menu.append (item);
|
||||||
menu.show_all ();
|
menu.show_all ();
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_menu (menu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show popup menu on right button
|
// Show popup menu on right button
|
||||||
@ -120,9 +125,13 @@ namespace Pamac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update_icon (string icon, string info) {
|
public void update_icon (string icon, string info) {
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_icon_full (icon, icon);
|
||||||
|
} else {
|
||||||
status_icon.set_from_icon_name (icon);
|
status_icon.set_from_icon_name (icon);
|
||||||
status_icon.set_tooltip_markup (info);
|
status_icon.set_tooltip_markup (info);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool start_refresh () {
|
bool start_refresh () {
|
||||||
// if pamac is not running start refresh else just check updates
|
// if pamac is not running start refresh else just check updates
|
||||||
@ -141,7 +150,11 @@ namespace Pamac {
|
|||||||
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period) {
|
void on_write_pamac_config_finished (bool recurse, uint64 refresh_period) {
|
||||||
launch_refresh_timeout (refresh_period);
|
launch_refresh_timeout (refresh_period);
|
||||||
if (refresh_period == 0) {
|
if (refresh_period == 0) {
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||||
|
} else {
|
||||||
status_icon.visible = false;
|
status_icon.visible = false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
check_updates ();
|
check_updates ();
|
||||||
}
|
}
|
||||||
@ -154,18 +167,30 @@ namespace Pamac {
|
|||||||
void on_get_updates_finished (Updates updates) {
|
void on_get_updates_finished (Updates updates) {
|
||||||
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
|
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
|
||||||
if (updates_nb == 0) {
|
if (updates_nb == 0) {
|
||||||
this.update_icon (noupdate_icon_name, noupdate_info);
|
update_icon (noupdate_icon_name, noupdate_info);
|
||||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||||
if (pamac_config.no_update_hide_icon) {
|
if (pamac_config.no_update_hide_icon) {
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||||
|
} else {
|
||||||
status_icon.visible = false;
|
status_icon.visible = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||||
} else {
|
} else {
|
||||||
status_icon.visible = true;
|
status_icon.visible = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
close_notification();
|
close_notification();
|
||||||
} else {
|
} else {
|
||||||
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
|
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
|
||||||
this.update_icon (update_icon_name, info);
|
this.update_icon (update_icon_name, info);
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||||
|
} else {
|
||||||
status_icon.visible = true;
|
status_icon.visible = true;
|
||||||
|
}
|
||||||
if (check_pamac_running ()) {
|
if (check_pamac_running ()) {
|
||||||
update_notification (info);
|
update_notification (info);
|
||||||
} else {
|
} else {
|
||||||
@ -312,12 +337,22 @@ namespace Pamac {
|
|||||||
extern_lock = false;
|
extern_lock = false;
|
||||||
refresh_timeout_id = 0;
|
refresh_timeout_id = 0;
|
||||||
|
|
||||||
|
if (use_indicator) {
|
||||||
|
indicator_status_icon = new AppIndicator.Indicator ("Update Manager", noupdate_icon_name, AppIndicator.IndicatorCategory.APPLICATION_STATUS);
|
||||||
|
indicator_status_icon.set_title (_("Update Manager"));
|
||||||
|
if (pamac_config.no_update_hide_icon) {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.PASSIVE);
|
||||||
|
} else {
|
||||||
|
indicator_status_icon.set_status (AppIndicator.IndicatorStatus.ACTIVE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
status_icon = new Gtk.StatusIcon ();
|
status_icon = new Gtk.StatusIcon ();
|
||||||
status_icon.visible = !(pamac_config.no_update_hide_icon);
|
status_icon.visible = !(pamac_config.no_update_hide_icon);
|
||||||
update_icon (noupdate_icon_name, noupdate_info);
|
|
||||||
status_icon.activate.connect (left_clicked);
|
status_icon.activate.connect (left_clicked);
|
||||||
create_menu ();
|
|
||||||
status_icon.popup_menu.connect (menu_popup);
|
status_icon.popup_menu.connect (menu_popup);
|
||||||
|
}
|
||||||
|
update_icon (noupdate_icon_name, noupdate_info);
|
||||||
|
create_menu ();
|
||||||
|
|
||||||
Notify.init (_("Update Manager"));
|
Notify.init (_("Update Manager"));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user