initial state refactor
This commit is contained in:
parent
8cde99d2a2
commit
793dfb4f42
|
@ -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();
|
||||||
|
|
24
app/main.js
24
app/main.js
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue