From a0f1bf3a8886578c8184e32bd8e8f0304356cd12 Mon Sep 17 00:00:00 2001 From: guinux Date: Fri, 19 Jun 2015 17:48:34 +0200 Subject: [PATCH] fix this annoying #54 --- src/daemon.vala | 22 +++++++++------------- src/refresh.vala | 29 +++++++++++++++++++++++++---- src/tray.vala | 16 +++++++++++----- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/daemon.vala b/src/daemon.vala index 49b52f3..c6eb532 100644 --- a/src/daemon.vala +++ b/src/daemon.vala @@ -1099,20 +1099,16 @@ namespace Pamac { [DBus (no_reply = true)] public void quit () { - try { - new Thread.try ("quit thread", () => { - databases_lock_mutex.lock (); - // be sure to not quit with locked databases - alpm_config.handle.trans_release (); - if (lockfile.query_exists () == false) { - loop.quit (); - } - databases_lock_mutex.unlock (); - return 0; - }); - } catch (GLib.Error e) { - stderr.printf ("%s\n", e.message); + // be sure to not quit with locked databases + alpm_config.handle.trans_release (); + if (lockfile.query_exists () == true) { + try { + lockfile.delete (); + } catch (GLib.Error e) { + GLib.stderr.printf("%s\n", e.message); + } } + loop.quit (); } // End of Daemon Object } diff --git a/src/refresh.vala b/src/refresh.vala index a3c240a..4ede9a1 100644 --- a/src/refresh.vala +++ b/src/refresh.vala @@ -18,12 +18,22 @@ */ namespace Pamac { + public struct ErrorInfos { + public string message; + public string[] details; + } [DBus (name = "org.manjaro.pamac")] public interface Daemon : Object { public abstract void start_refresh (int force) throws IOError; + [DBus (no_reply = true)] + public abstract void quit () throws IOError; + public signal void refresh_finished (ErrorInfos error); } } +Pamac.Daemon pamac_daemon; +MainLoop loop; + bool check_pamac_running () { Application app; bool run = false; @@ -57,16 +67,27 @@ bool check_pamac_running () { return run; } -int main (string[] args) { - Pamac.Daemon daemon; +void on_refresh_finished () { + try { + pamac_daemon.quit (); + } catch (IOError e) { + stderr.printf ("IOError: %s\n", e.message); + } + loop.quit (); +} + +int main () { if (check_pamac_running () == false) { try { - daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", + pamac_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac"); - daemon.start_refresh (0); + pamac_daemon.refresh_finished.connect (on_refresh_finished); + pamac_daemon.start_refresh (0); } catch (IOError e) { stderr.printf ("IOError: %s\n", e.message); } } + loop = new MainLoop (); + loop.run (); return 0; } diff --git a/src/tray.vala b/src/tray.vala index d4a448a..52cb2ec 100644 --- a/src/tray.vala +++ b/src/tray.vala @@ -29,7 +29,8 @@ namespace Pamac { public interface Daemon : Object { public abstract void start_refresh (int force) throws IOError; public abstract async Updates get_updates (bool enable_aur) throws IOError; - public abstract async void quit () throws IOError; + [DBus (no_reply = true)] + public abstract void quit () throws IOError; public signal void refresh_finished (ErrorInfos error); } @@ -52,16 +53,21 @@ 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); } catch (IOError e) { stderr.printf ("IOError: %s\n", e.message); } - // Connecting to signal - daemon.refresh_finished.connect (on_refresh_finished); } void stop_daemon () { - if (check_pamac_running () == false && lockfile.query_exists () == false) { - daemon.quit.begin (); + if (check_pamac_running () == false) { + daemon.refresh_finished.disconnect (on_refresh_finished); + try { + daemon.quit (); + } catch (IOError e) { + stderr.printf ("IOError: %s\n", e.message); + } } }