From d101a76962271ba3614fe4877c9711f58bb61498 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Fri, 8 Mar 2019 10:17:10 -0800 Subject: [PATCH] fixed android login. closes #1199 --- android/android.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/android/android.js b/android/android.js index 9d113776..4105bbbf 100644 --- a/android/android.js +++ b/android/android.js @@ -18,6 +18,7 @@ import share from './pages/share'; import preferences from './pages/preferences'; import error from './pages/error'; import { getTranslator } from '../app/locale'; +import { delay } from '../app/utils'; if (navigator.userAgent === 'Send Android') { setApiUrlPrefix('https://send2.dev.lcip.org'); @@ -28,6 +29,15 @@ const app = choo(); app.use(controller); app.use(intents); +window.finishLogin = async function(accountInfo) { + while (!(app.state && app.state.user)) { + await delay(); + } + await app.state.user.finishLogin(accountInfo); + await app.state.user.syncFileList(); + app.emitter.emit('replaceState', '/'); +}; + function body(main) { return function(state, emit) { /* @@ -59,7 +69,7 @@ function body(main) { (async function start() { const translate = await getTranslator('en-US'); const { LIMITS, DEFAULTS } = await getConstants(); - app.use((state, emitter) => { + app.use(state => { state.LIMITS = LIMITS; state.DEFAULTS = DEFAULTS; state.translate = translate; @@ -68,18 +78,10 @@ function body(main) { }; //TODO state.archive = new Archive([], DEFAULTS.EXPIRE_SECONDS); state.storage = storage; - state.user = new User(storage, LIMITS); + state.user = new User(storage, LIMITS, { + issuer: 'https://accounts.firefox.com' + }); state.raven = Raven; - - window.finishLogin = async function(accountInfo) { - await state.user.finishLogin(accountInfo); - await state.user.syncFileList(); - emitter.emit('replaceState', '/'); - }; - - // for debugging - window.appState = state; - window.appEmit = emitter.emit.bind(emitter); }); app.use(metrics); app.route('/', body(home)); @@ -91,3 +93,5 @@ function body(main) { // add /api/filelist app.mount('body'); })(); + +window.app = app;