[gnome-todo] todoist: hold todo until request queue is empty



commit 10e854eecfe19e01b4f13bab5db3d6317fbddff1
Author: Rohit Kaushik <kaushikrohit325 gmail com>
Date:   Tue Sep 5 22:00:35 2017 +0530

    todoist: hold todo until request queue is empty
    
    This patch introduces a hold-state which should
    be active when todoist request queue is not empty.
    User can accidently close the app when there are
    requests yet to be dispatched, this can cause lose
    of request. With this patch todo continues to run
    in background until all the post requests are
    dispatched.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772278

 plugins/todoist/gtd-provider-todoist.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/plugins/todoist/gtd-provider-todoist.c b/plugins/todoist/gtd-provider-todoist.c
index 713db8c..b0e6fbc 100644
--- a/plugins/todoist/gtd-provider-todoist.c
+++ b/plugins/todoist/gtd-provider-todoist.c
@@ -569,6 +569,13 @@ push_post_request (GtdProviderTodoist *self,
 {
   g_queue_push_head (self->queue, data);
 
+  /*
+   * When the queue holds post request, the application should
+   * not quit till the time queue gets empty. This hold is released
+   * in post_generic_cb where requests are dispatched.
+   */
+  g_application_hold (g_application_get_default ());
+
   if (!self->dispatch_id)
     self->dispatch_id = g_timeout_add_seconds (5, (GSourceFunc) dispatch_requests, self);
 }
@@ -631,6 +638,9 @@ post_generic_cb (RestProxyCall       *call,
       data = g_queue_pop_tail (self->queue);
       post (data->params, (RestProxyCallAsyncCallback) post_generic_cb, data);
     }
+
+  /* Release the hold since queue is empty */
+       g_application_release (g_application_get_default ());
 }
 
 static gboolean


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]