     expose.launchDropBoxChooser = () ->
         slog 'launchDropBoxChooser'
         # Get access token first so we can convert the link to a path later
-        if not dbx.accessToken
-            window.location = dbx.getAuthenticationUrl(location.href.split("#")[0], 'CHOOSE')
-        else
+        ensureDropboxToken(CHOOSE).then () ->
             Dropbox.choose options =
                 extensions: ['text', '.taskpaper', '.txt', '.ft']
                 success: (files) ->

    authenticationUrl = dbx.getAuthenticationUrl(location.href.split("#")[0], path)
    authenticationLink = "<a href='#{authenticationUrl}'>#{authenticationUrl}</a>"

    # User chose not to give access to Dropbox account
    dropboxAccessDenied = hashKeys.error is 'access_denied'
    if dropboxAccessDenied

# To temporarily introspect variables during development.
spy = window
slog = console.log # spy + log

spy.resolveCb = (data) ->
    window.d = data
    console.log 'Resolved'
    console.log data

spy.rejectCb = (error) ->
    window.e = error
    console.log 'Rejected'
    console.log error

import { DockPanel }                 from 'phosphor-dockpanel'
import { CodeMirrorWidget }          from 'phosphor-codemirror'
