mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
34f68dcc0d
Summary: - WIP: Need to fix tests and some errors! - Refactors Category class to hold information about its type - Refactors CategoryStore to rely on observables instead of local caches - Adds and updates Observables and helpers - Refactors ContactStore to hold entire cache of contacts instead of per current account - Same for ContactRankingStore and other stores - Refactors method names for AccountStore + some helpers - Updates MailViewFilter to hold an account - Adds basic Unified filter - Replaces AccountStore.current calls with either: - The account of the currently focused MailViewFilter - The account associated with a thread, message, file, etc... - A parameter to be passed in - Arbitrarily, the first account in the AccountsStore Test Plan: - Unit tests Reviewers: evan, bengotow Differential Revision: https://phab.nylas.com/D2423
90 lines
2.6 KiB
CoffeeScript
90 lines
2.6 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
OnboardingActions = require './onboarding-actions'
|
|
TokenAuthAPI = require './token-auth-api'
|
|
{AccountStore, Actions} = require 'nylas-exports'
|
|
{ipcRenderer} = require 'electron'
|
|
NylasStore = require 'nylas-store'
|
|
url = require 'url'
|
|
|
|
return unless NylasEnv.getWindowType() is "onboarding"
|
|
|
|
class PageRouterStore extends NylasStore
|
|
constructor: ->
|
|
NylasEnv.onWindowPropsReceived @_onWindowPropsChanged
|
|
|
|
@_page = NylasEnv.getWindowProps().page ? ''
|
|
@_pageData = NylasEnv.getWindowProps().pageData ? {}
|
|
@_pageStack = [{page: @_page, pageData: @_pageData}]
|
|
|
|
@_checkTokenAuthStatus()
|
|
@listenTo OnboardingActions.moveToPreviousPage, @_onMoveToPreviousPage
|
|
@listenTo OnboardingActions.moveToPage, @_onMoveToPage
|
|
@listenTo OnboardingActions.closeWindow, @_onCloseWindow
|
|
@listenTo OnboardingActions.accountJSONReceived, @_onAccountJSONReceived
|
|
@listenTo OnboardingActions.retryCheckTokenAuthStatus, @_checkTokenAuthStatus
|
|
|
|
_onAccountJSONReceived: (json) =>
|
|
isFirstAccount = AccountStore.accounts().length is 0
|
|
AccountStore.addAccountFromJSON(json)
|
|
ipcRenderer.send('new-account-added')
|
|
NylasEnv.displayWindow()
|
|
if isFirstAccount
|
|
@_onMoveToPage('initial-preferences', {account: json})
|
|
Actions.recordUserEvent('First Account Linked')
|
|
else
|
|
ipcRenderer.send('account-setup-successful')
|
|
|
|
_onWindowPropsChanged: ({page, pageData}={}) =>
|
|
@_onMoveToPage(page, pageData)
|
|
|
|
page: -> @_page
|
|
|
|
pageData: -> @_pageData
|
|
|
|
tokenAuthEnabled: -> @_tokenAuthEnabled
|
|
|
|
tokenAuthEnabledError: -> @_tokenAuthEnabledError
|
|
|
|
connectType: ->
|
|
@_connectType
|
|
|
|
_onMoveToPreviousPage: ->
|
|
current = @_pageStack.pop()
|
|
prev = @_pageStack.pop()
|
|
@_onMoveToPage(prev.page, prev.pageData)
|
|
|
|
_onMoveToPage: (page, pageData={}) ->
|
|
@_pageStack.push({page, pageData})
|
|
@_page = page
|
|
@_pageData = pageData
|
|
@trigger()
|
|
|
|
_onCloseWindow: ->
|
|
isFirstAccount = AccountStore.accounts().length is 0
|
|
if isFirstAccount
|
|
NylasEnv.quit()
|
|
else
|
|
NylasEnv.close()
|
|
|
|
_checkTokenAuthStatus: ->
|
|
@_tokenAuthEnabled = "unknown"
|
|
@_tokenAuthEnabledError = null
|
|
@trigger()
|
|
|
|
TokenAuthAPI.request
|
|
path: "/status/"
|
|
returnsModel: false
|
|
timeout: 10000
|
|
success: (json) =>
|
|
if json.restricted
|
|
@_tokenAuthEnabled = "yes"
|
|
else
|
|
@_tokenAuthEnabled = "no"
|
|
@trigger()
|
|
error: (err) =>
|
|
if err.statusCode is 404
|
|
err.message = "Sorry, we could not reach the Nylas API. Please try again."
|
|
@_tokenAuthEnabledError = err.message
|
|
@trigger()
|
|
|
|
module.exports = new PageRouterStore()
|