fix this annoying #54

This commit is contained in:
guinux 2015-06-19 17:48:34 +02:00
parent e8c2ab079c
commit a0f1bf3a88
3 changed files with 45 additions and 22 deletions

View File

@ -1099,20 +1099,16 @@ namespace Pamac {
[DBus (no_reply = true)] [DBus (no_reply = true)]
public void quit () { public void quit () {
try { // be sure to not quit with locked databases
new Thread<int>.try ("quit thread", () => { alpm_config.handle.trans_release ();
databases_lock_mutex.lock (); if (lockfile.query_exists () == true) {
// be sure to not quit with locked databases try {
alpm_config.handle.trans_release (); lockfile.delete ();
if (lockfile.query_exists () == false) { } catch (GLib.Error e) {
loop.quit (); GLib.stderr.printf("%s\n", e.message);
} }
databases_lock_mutex.unlock ();
return 0;
});
} catch (GLib.Error e) {
stderr.printf ("%s\n", e.message);
} }
loop.quit ();
} }
// End of Daemon Object // End of Daemon Object
} }

View File

@ -18,12 +18,22 @@
*/ */
namespace Pamac { namespace Pamac {
public struct ErrorInfos {
public string message;
public string[] details;
}
[DBus (name = "org.manjaro.pamac")] [DBus (name = "org.manjaro.pamac")]
public interface Daemon : Object { public interface Daemon : Object {
public abstract void start_refresh (int force) throws IOError; 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 () { bool check_pamac_running () {
Application app; Application app;
bool run = false; bool run = false;
@ -57,16 +67,27 @@ bool check_pamac_running () {
return run; return run;
} }
int main (string[] args) { void on_refresh_finished () {
Pamac.Daemon daemon; try {
pamac_daemon.quit ();
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
loop.quit ();
}
int main () {
if (check_pamac_running () == false) { if (check_pamac_running () == false) {
try { 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"); "/org/manjaro/pamac");
daemon.start_refresh (0); pamac_daemon.refresh_finished.connect (on_refresh_finished);
pamac_daemon.start_refresh (0);
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
} }
} }
loop = new MainLoop ();
loop.run ();
return 0; return 0;
} }

View File

@ -29,7 +29,8 @@ namespace Pamac {
public interface Daemon : Object { public interface Daemon : Object {
public abstract void start_refresh (int force) throws IOError; public abstract void start_refresh (int force) throws IOError;
public abstract async Updates get_updates (bool enable_aur) 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); public signal void refresh_finished (ErrorInfos error);
} }
@ -52,16 +53,21 @@ namespace Pamac {
try { try {
daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac",
"/org/manjaro/pamac"); "/org/manjaro/pamac");
// Connecting to signal
daemon.refresh_finished.connect (on_refresh_finished);
} catch (IOError e) { } catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message); stderr.printf ("IOError: %s\n", e.message);
} }
// Connecting to signal
daemon.refresh_finished.connect (on_refresh_finished);
} }
void stop_daemon () { void stop_daemon () {
if (check_pamac_running () == false && lockfile.query_exists () == false) { if (check_pamac_running () == false) {
daemon.quit.begin (); daemon.refresh_finished.disconnect (on_refresh_finished);
try {
daemon.quit ();
} catch (IOError e) {
stderr.printf ("IOError: %s\n", e.message);
}
} }
} }