initial state refactor

This commit is contained in:
Danny Coates 2018-12-13 11:12:06 -08:00
parent 8cde99d2a2
commit 793dfb4f42
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
2 changed files with 14 additions and 12 deletions

View File

@ -74,7 +74,7 @@ async function polyfillStreams() {
} }
} }
export default async function capabilities() { export default async function getCapabilities() {
const serviceWorker = 'serviceWorker' in navigator; const serviceWorker = 'serviceWorker' in navigator;
let crypto = await checkCrypto(); let crypto = await checkCrypto();
const nativeStreams = checkStreams(); const nativeStreams = checkStreams();

View File

@ -5,7 +5,7 @@ import 'fluent-intl-polyfill';
import choo from 'choo'; import choo from 'choo';
import nanotiming from 'nanotiming'; import nanotiming from 'nanotiming';
import routes from './routes'; import routes from './routes';
import capabilities from './capabilities'; import getCapabilities from './capabilities';
import controller from './controller'; import controller from './controller';
import dragManager from './dragManager'; import dragManager from './dragManager';
import pasteManager from './pasteManager'; import pasteManager from './pasteManager';
@ -26,23 +26,25 @@ if (process.env.NODE_ENV === 'production') {
} }
(async function start() { (async function start() {
const app = routes(choo()); const capabilities = await getCapabilities();
const capa = await capabilities(); if (capabilities.serviceWorker) {
if (capa.serviceWorker) {
await navigator.serviceWorker.register('/serviceWorker.js'); await navigator.serviceWorker.register('/serviceWorker.js');
await navigator.serviceWorker.ready; await navigator.serviceWorker.ready;
} }
const translate = await getTranslator(LOCALE); const translate = await getTranslator(LOCALE);
window.initialState = {
capabilities,
translate,
storage,
raven: Raven,
user: new User(storage),
transfer: null,
fileInfo: null
};
const app = routes(choo());
app.use((state, emitter) => { app.use((state, emitter) => {
state.capabilities = capa;
state.transfer = null;
state.fileInfo = null;
state.translate = translate;
state.storage = storage;
state.raven = Raven;
state.user = new User(storage);
window.appState = state; window.appState = state;
window.appEmit = emitter.emit.bind(emitter); window.appEmit = emitter.emit.bind(emitter);
let unsupportedReason = null; let unsupportedReason = null;