 globals = require 'globals'
 actionTypes = require './actiontypes'
 HomeGetters = require './getters'
+remote = require('app/remote').getInstance()
+
 { queryKites } = require 'app/providers/managed/helpers'
-
 { getters: EnvironmentGetters } = require 'app/flux/environment'
 
 markAsDone = (step) ->
   # set app state
-  kd.singletons.reactor.dispatch actionTypes.MARK_WELCOME_STEP_AS_DONE, { step }
+  { reactor, mainController, appStorageController } = kd.singletons
+  reactor.dispatch actionTypes.MARK_WELCOME_STEP_AS_DONE, { step }
+  if reactor.evaluate HomeGetters.areStepsFinished
+    mainController.emit 'AllWelcomeStepsDone'
 
   # persist state
-  { appStorageController } = kd.singletons
   appStorage = appStorageController.storage "WelcomeSteps-#{globals.currentGroup.slug}"
   appStorage.fetchValue 'finishedSteps', (finishedSteps = {}) ->
     finishedSteps[step] = yes

    Object.keys(welcomeSteps).forEach (step) ->
      markAsDone step  if finishedSteps[step]

  if groupsController.getCurrentGroup().counts?.members > 1
    markAsDone 'inviteTeam'

  return  if reactor.evaluate(HomeGetters.welcomeSteps).getIn [ 'common', 'installKd', 'isDone' ]

  queryKites().then (result) ->

    return markAsDone 'installKd'  if result?.length

    kiteTimer = kd.utils.repeat 30000, -> queryKites().then (result) ->



checkFinishedSteps = ->

  { appStorageController, groupsController
    reactor, mainController, computeController } = kd.singletons

  appStorage = appStorageController.storage "WelcomeSteps-#{globals.currentGroup.slug}"

  welcomeSteps = reactor.evaluate(HomeGetters.welcomeSteps).toJS()
