fix(task-queue): Save the task queue before closing the window

Summary:
Save the final state of the TaskQueue to the database before window
gets unloaded

Test Plan: Manual

Reviewers: evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3408
This commit is contained in:
Juan Tejada 2016-11-04 15:30:26 -07:00
parent 5b1ee293dc
commit 7ac7fa58ec

View file

@ -73,6 +73,12 @@ class TaskQueue
@_restoreQueue()
NylasEnv.onBeforeUnload((finishUnload) =>
@_saveQueue()
.finally(finishUnload)
return false
)
@listenTo Actions.queueTask, @enqueue
@listenTo Actions.queueTasks, (tasks) =>
return unless tasks and tasks.length > 0
@ -325,10 +331,14 @@ class TaskQueue
@_queue = queue
@_updateSoon()
_saveQueue: =>
return DatabaseStore.inTransaction((t) =>
return t.persistJSONBlob(JSONBlobStorageKey, @_queue ? [])
)
_updateSoon: =>
@_updateSoonThrottled ?= _.throttle =>
DatabaseStore.inTransaction (t) =>
t.persistJSONBlob(JSONBlobStorageKey, @_queue ? [])
@_saveQueue()
_.defer =>
@_processQueue()
@_ensurePeriodicUpdates()