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)]
public void quit () {
try {
new Thread<int>.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
}

View File

@ -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;
}

View File

@ -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);
}
}
}