forked from cromer/pamac-classic
v2.4, new preferences dialog
This commit is contained in:
@@ -32,12 +32,15 @@ namespace Pamac {
|
||||
[DBus (no_reply = true)]
|
||||
public abstract void quit () throws IOError;
|
||||
public signal void refresh_finished (ErrorInfos error);
|
||||
public signal void write_pamac_config_finished (int refresh_period, bool aur_enabled, bool recurse,
|
||||
bool no_update_hide_icon, bool check_aur_updates,
|
||||
bool no_confirm_build);
|
||||
public signal void write_alpm_config_finished (bool checkspace);
|
||||
}
|
||||
|
||||
public class TrayIcon: Gtk.Application {
|
||||
Notify.Notification notification;
|
||||
Daemon daemon;
|
||||
bool intern_lock;
|
||||
bool extern_lock;
|
||||
uint refresh_timeout_id;
|
||||
Gtk.StatusIcon status_icon;
|
||||
@@ -53,8 +56,9 @@ namespace Pamac {
|
||||
try {
|
||||
daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac",
|
||||
"/org/manjaro/pamac");
|
||||
// Connecting to signal
|
||||
daemon.refresh_finished.connect (on_refresh_finished);
|
||||
// Connecting to signals
|
||||
daemon.write_pamac_config_finished.connect (on_write_pamac_config_finished);
|
||||
daemon.write_alpm_config_finished.connect (on_write_alpm_config_finished);
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
@@ -62,7 +66,6 @@ namespace Pamac {
|
||||
|
||||
void stop_daemon () {
|
||||
if (check_pamac_running () == false) {
|
||||
daemon.refresh_finished.disconnect (on_refresh_finished);
|
||||
try {
|
||||
daemon.quit ();
|
||||
} catch (IOError e) {
|
||||
@@ -120,11 +123,12 @@ namespace Pamac {
|
||||
}
|
||||
|
||||
bool start_refresh () {
|
||||
if (check_pamac_running () == false) {
|
||||
start_daemon ();
|
||||
// if pamac is not running start refresh else just check updates
|
||||
if (check_pamac_running ()) {
|
||||
check_updates ();
|
||||
} else {
|
||||
try {
|
||||
daemon.start_refresh (0);
|
||||
intern_lock = true;
|
||||
} catch (IOError e) {
|
||||
stderr.printf ("IOError: %s\n", e.message);
|
||||
}
|
||||
@@ -132,14 +136,25 @@ namespace Pamac {
|
||||
return true;
|
||||
}
|
||||
|
||||
void on_refresh_finished () {
|
||||
intern_lock = false;
|
||||
void on_write_pamac_config_finished (int refresh_period) {
|
||||
launch_refresh_timeout ((uint) refresh_period);
|
||||
if (refresh_period == 0) {
|
||||
status_icon.visible = false;
|
||||
} else {
|
||||
check_updates ();
|
||||
}
|
||||
}
|
||||
|
||||
void on_write_alpm_config_finished (bool checkspace) {
|
||||
check_updates ();
|
||||
}
|
||||
|
||||
void check_updates () {
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
daemon.get_updates.begin (pamac_config.enable_aur, (obj, res) => {
|
||||
if (pamac_config.refresh_period == 0) {
|
||||
return;
|
||||
}
|
||||
daemon.get_updates.begin ((pamac_config.enable_aur && pamac_config.check_aur_updates), (obj, res) => {
|
||||
var updates = Updates ();
|
||||
try {
|
||||
updates = daemon.get_updates.end (res);
|
||||
@@ -149,9 +164,15 @@ namespace Pamac {
|
||||
uint updates_nb = updates.repos_updates.length + updates.aur_updates.length;
|
||||
if (updates_nb == 0) {
|
||||
this.update_icon (noupdate_icon_name, noupdate_info);
|
||||
if (pamac_config.no_update_hide_icon) {
|
||||
status_icon.visible = false;
|
||||
} else {
|
||||
status_icon.visible = true;
|
||||
}
|
||||
} else {
|
||||
string info = ngettext ("%u available update", "%u available updates", updates_nb).printf (updates_nb);
|
||||
this.update_icon (update_icon_name, info);
|
||||
status_icon.visible = true;
|
||||
if (check_pamac_running () == false) {
|
||||
show_notification (info);
|
||||
}
|
||||
@@ -225,9 +246,7 @@ namespace Pamac {
|
||||
}
|
||||
} else {
|
||||
if (lockfile.query_exists () == true) {
|
||||
if (intern_lock == false) {
|
||||
extern_lock = true;
|
||||
}
|
||||
extern_lock = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -236,8 +255,11 @@ namespace Pamac {
|
||||
void launch_refresh_timeout (uint refresh_period_in_hours) {
|
||||
if (refresh_timeout_id != 0) {
|
||||
Source.remove (refresh_timeout_id);
|
||||
refresh_timeout_id = 0;
|
||||
}
|
||||
if (refresh_period_in_hours != 0) {
|
||||
refresh_timeout_id = Timeout.add_seconds (refresh_period_in_hours*3600, start_refresh);
|
||||
}
|
||||
refresh_timeout_id = Timeout.add_seconds (refresh_period_in_hours*3600, start_refresh);
|
||||
}
|
||||
|
||||
public override void startup () {
|
||||
@@ -245,14 +267,19 @@ namespace Pamac {
|
||||
Intl.textdomain ("pamac");
|
||||
Intl.setlocale (LocaleCategory.ALL, "");
|
||||
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
// if refresh period is 0, just return so tray will exit
|
||||
if (pamac_config.refresh_period == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
base.startup ();
|
||||
|
||||
intern_lock = false;
|
||||
extern_lock = false;
|
||||
refresh_timeout_id = 0;
|
||||
|
||||
status_icon = new Gtk.StatusIcon ();
|
||||
status_icon.set_visible (true);
|
||||
status_icon.visible = !(pamac_config.no_update_hide_icon);
|
||||
this.update_icon (noupdate_icon_name, noupdate_info);
|
||||
status_icon.activate.connect (left_clicked);
|
||||
create_menu ();
|
||||
@@ -263,9 +290,9 @@ namespace Pamac {
|
||||
var alpm_config = new Alpm.Config ("/etc/pacman.conf");
|
||||
alpm_config.get_handle ();
|
||||
lockfile = GLib.File.new_for_path (alpm_config.handle.lockfile);
|
||||
start_daemon ();
|
||||
Timeout.add (500, check_pacman_running);
|
||||
start_refresh ();
|
||||
var pamac_config = new Pamac.Config ("/etc/pamac.conf");
|
||||
launch_refresh_timeout ((uint) pamac_config.refresh_period);
|
||||
|
||||
this.hold ();
|
||||
|
||||
Reference in New Issue
Block a user