     )
     cleanupOnUninstall()
     setupEventHandlers()
-    setApiKey()
-    pluginReady = true
+    setupConfigs()
     statusBarTileView?.setTitle('WakaTime initialized')
     statusBarTileView?.setStatus()
     @settingChangedObserver = atom.config.observe 'wakatime', @settingChangedHandler

    statusBarTileView?.destroy()
    @settingChangedObserver?.dispose()
  
  settingChangedHandler: (newValue) ->
    if newValue.showStatusBarIcon
      statusBarTileView?.show()
    else
      statusBarTileView?.hide()

getUserHome = ->
  process.env[if process.platform == 'win32' then 'USERPROFILE' else 'HOME'] || ''

setApiKey = ->
  loadApiKey (err, key) ->
    if err
      console.log err.message
    else
      apiKey = key

loadApiKey = (cb) ->
  key = atom.config.get('wakatime.apikey')
  return cb(null, key) if key? && key.length > 0
  wakatimeConfigFile = path.join getUserHome(), '.wakatime.cfg'
  fs.readFile wakatimeConfigFile, 'utf-8', (err, configContent) ->
    return cb(new Error('could not read wakatime config')) if err?
    wakatimeConfig = ini.parse configContent
    key = wakatimeConfig?.settings?.api_key
    if key?
      cb null, key
    else
      cb new Error('wakatime key not found')

enoughTimePassed = (time) ->
  return lastHeartbeat + 120000 < time

unloadHandler = null
lastHeartbeat = 0
lastFile = ''
statusBarTileView = null
pluginReady = false

