mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-06 20:54:26 +08:00
feat(sync): Resume sync worker action from sidebar
This commit is contained in:
parent
944d6a8e1e
commit
3908ba402d
4 changed files with 31 additions and 6 deletions
|
@ -105,7 +105,7 @@ class ActivitySidebar extends React.Component
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
_onTryAgain: =>
|
_onTryAgain: =>
|
||||||
# TODO
|
Actions.retryInitialSync()
|
||||||
|
|
||||||
_onDataChanged: =>
|
_onDataChanged: =>
|
||||||
@setState(@_getStateFromStores())
|
@setState(@_getStateFromStores())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
{DatabaseStore} = require 'nylas-exports'
|
{Actions, DatabaseStore} = require 'nylas-exports'
|
||||||
NylasLongConnection = require './nylas-long-connection'
|
NylasLongConnection = require './nylas-long-connection'
|
||||||
|
|
||||||
PAGE_SIZE = 250
|
PAGE_SIZE = 250
|
||||||
|
@ -45,6 +45,8 @@ class NylasSyncWorker
|
||||||
# indirection needed so resumeFetches can be spied on
|
# indirection needed so resumeFetches can be spied on
|
||||||
@resumeFetches()
|
@resumeFetches()
|
||||||
|
|
||||||
|
@_unlisten = Actions.retryInitialSync.listen(@_onRetryInitialSync, @)
|
||||||
|
|
||||||
@_state = null
|
@_state = null
|
||||||
DatabaseStore.findJSONObject("NylasSyncWorker:#{@_account.id}").then (json) =>
|
DatabaseStore.findJSONObject("NylasSyncWorker:#{@_account.id}").then (json) =>
|
||||||
@_state = json ? {}
|
@_state = json ? {}
|
||||||
|
@ -76,6 +78,7 @@ class NylasSyncWorker
|
||||||
@resumeFetches()
|
@resumeFetches()
|
||||||
|
|
||||||
cleanup: ->
|
cleanup: ->
|
||||||
|
@_unlisten?()
|
||||||
@_resumeTimer.cancel()
|
@_resumeTimer.cancel()
|
||||||
@_connection.end()
|
@_connection.end()
|
||||||
@_terminated = true
|
@_terminated = true
|
||||||
|
@ -160,4 +163,7 @@ class NylasSyncWorker
|
||||||
,100
|
,100
|
||||||
@_writeState()
|
@_writeState()
|
||||||
|
|
||||||
|
_onRetryInitialSync: =>
|
||||||
|
@resumeFetches()
|
||||||
|
|
||||||
NylasSyncWorker.BackoffTimer = BackoffTimer
|
NylasSyncWorker.BackoffTimer = BackoffTimer
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
{DatabaseStore, Account, Thread} = require 'nylas-exports'
|
{Actions, DatabaseStore, Account, Thread} = require 'nylas-exports'
|
||||||
NylasLongConnection = require '../lib/nylas-long-connection'
|
NylasLongConnection = require '../lib/nylas-long-connection'
|
||||||
NylasSyncWorker = require '../lib/nylas-sync-worker'
|
NylasSyncWorker = require '../lib/nylas-sync-worker'
|
||||||
|
|
||||||
|
@ -221,6 +221,18 @@ describe "NylasSyncWorker", ->
|
||||||
@request.requestOptions.error(new Error("Oh no a network error"))
|
@request.requestOptions.error(new Error("Oh no a network error"))
|
||||||
expect(@apiRequests.length).toBe(0)
|
expect(@apiRequests.length).toBe(0)
|
||||||
|
|
||||||
|
it "resumes when a action forces it to", ->
|
||||||
|
err = new Error("Oh no a network error")
|
||||||
|
@request.requestOptions.error(err)
|
||||||
|
expect(@worker.state().threads.busy).toEqual(false)
|
||||||
|
expect(@worker.state().threads.complete).toEqual(false)
|
||||||
|
spyOn(@worker, 'resumeFetches').andCallThrough()
|
||||||
|
Actions.retryInitialSync()
|
||||||
|
expect(@worker.resumeFetches).toHaveBeenCalled()
|
||||||
|
expect(@worker.resumeFetches.calls.length).toBe 1
|
||||||
|
expect(@worker.state().threads.busy).toEqual(true)
|
||||||
|
expect(@worker.state().threads.error).toBe(null)
|
||||||
|
|
||||||
describe "cleanup", ->
|
describe "cleanup", ->
|
||||||
it "should termiate the long polling connection", ->
|
it "should termiate the long polling connection", ->
|
||||||
spyOn(@connection, 'end')
|
spyOn(@connection, 'end')
|
||||||
|
|
|
@ -94,7 +94,7 @@ class Actions
|
||||||
###
|
###
|
||||||
Public: Queue a {Task} object to the {TaskQueue}.
|
Public: Queue a {Task} object to the {TaskQueue}.
|
||||||
|
|
||||||
*Scope: Main Window*
|
*Scope: Work Window*
|
||||||
###
|
###
|
||||||
@queueTask: ActionScopeWorkWindow
|
@queueTask: ActionScopeWorkWindow
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class Actions
|
||||||
###
|
###
|
||||||
Public: Dequeue all {Task}s from the {TaskQueue}. Use with care.
|
Public: Dequeue all {Task}s from the {TaskQueue}. Use with care.
|
||||||
|
|
||||||
*Scope: Main Window*
|
*Scope: Work Window*
|
||||||
###
|
###
|
||||||
@dequeueAllTasks: ActionScopeWorkWindow
|
@dequeueAllTasks: ActionScopeWorkWindow
|
||||||
@dequeueTask: ActionScopeWorkWindow
|
@dequeueTask: ActionScopeWorkWindow
|
||||||
|
@ -111,7 +111,7 @@ class Actions
|
||||||
###
|
###
|
||||||
Public: Dequeue a {Task} matching the description provided.
|
Public: Dequeue a {Task} matching the description provided.
|
||||||
|
|
||||||
*Scope: Main Window*
|
*Scope: Work Window*
|
||||||
###
|
###
|
||||||
@dequeueMatchingTask: ActionScopeWorkWindow
|
@dequeueMatchingTask: ActionScopeWorkWindow
|
||||||
|
|
||||||
|
@ -123,6 +123,13 @@ class Actions
|
||||||
@didMakeAPIRequest: ActionScopeWorkWindow
|
@didMakeAPIRequest: ActionScopeWorkWindow
|
||||||
@sendFeedback: ActionScopeWorkWindow
|
@sendFeedback: ActionScopeWorkWindow
|
||||||
|
|
||||||
|
###
|
||||||
|
Public: Retry the initial sync
|
||||||
|
|
||||||
|
*Scope: Work Window*
|
||||||
|
###
|
||||||
|
@retryInitialSync: ActionScopeWorkWindow
|
||||||
|
|
||||||
|
|
||||||
###
|
###
|
||||||
Public: Show the developer console for the current window.
|
Public: Show the developer console for the current window.
|
||||||
|
|
Loading…
Add table
Reference in a new issue