lbry-desktop/ui/js/main.js

74 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-11-22 21:19:08 +01:00
import React from 'react';
import ReactDOM from 'react-dom';
import lbry from './lbry.js';
2017-03-31 01:00:33 +02:00
import lbryio from './lbryio.js';
import lighthouse from './lighthouse.js';
2017-04-07 07:15:22 +02:00
import App from './component/app/index.js';
2016-11-22 21:19:08 +01:00
import SplashScreen from './component/splash.js';
2017-04-10 14:32:40 +02:00
import SnackBar from './component/snack-bar.js';
2017-04-09 17:06:23 +02:00
import {AuthOverlay} from './component/auth.js';
2017-04-07 07:15:22 +02:00
import { Provider } from 'react-redux';
import store from 'store.js';
import {
2017-05-06 09:25:14 +02:00
doChangePath,
doDaemonReady,
doHistoryPush
} from 'actions/app'
import {
doFetchDaemonSettings
} from 'actions/settings'
import {
doFileList
} from 'actions/file_info'
2017-05-07 14:50:32 +02:00
import parseQueryParams from 'util/query_params'
2016-11-22 21:19:08 +01:00
const {remote, ipcRenderer} = require('electron');
const contextMenu = remote.require('./menu/context-menu');
2017-04-07 07:15:22 +02:00
const app = require('./app')
lbry.showMenuIfNeeded();
2016-11-22 21:19:08 +01:00
window.addEventListener('contextmenu', (event) => {
contextMenu.showContextMenu(remote.getCurrentWindow(), event.x, event.y,
lbry.getClientSetting('showDeveloperMenu'));
event.preventDefault();
});
2017-05-06 09:25:14 +02:00
window.addEventListener('popstate', (event) => {
2017-05-06 18:31:47 +02:00
const queryString = document.location.search
const pathParts = document.location.pathname.split('/')
const route = '/' + pathParts[pathParts.length - 1]
if (route.match(/html$/)) return
2017-05-06 09:25:14 +02:00
app.store.dispatch(doChangePath(`${route}${queryString}`))
2017-05-06 09:25:14 +02:00
})
ipcRenderer.on('open-uri-requested', (event, uri) => {
2017-05-15 05:50:59 +02:00
if (uri) {
console.log('FIX ME do magic dispatch: ' + uri);
}
});
2017-04-07 07:15:22 +02:00
const initialState = app.store.getState();
var init = function() {
2017-04-09 17:06:23 +02:00
2017-04-10 14:32:40 +02:00
function onDaemonReady() {
app.store.dispatch(doDaemonReady())
2017-04-09 17:06:23 +02:00
window.sessionStorage.setItem('loaded', 'y'); //once we've made it here once per session, we don't need to show splash again
app.store.dispatch(doHistoryPush({}, "Discover", "/discover"))
app.store.dispatch(doFetchDaemonSettings())
app.store.dispatch(doFileList())
2017-04-22 15:17:01 +02:00
ReactDOM.render(<Provider store={store}><div>{ lbryio.enabled ? <AuthOverlay/> : '' }<App /><SnackBar /></div></Provider>, canvas)
2017-04-09 17:06:23 +02:00
}
2017-04-10 14:32:40 +02:00
if (window.sessionStorage.getItem('loaded') == 'y') {
2017-04-09 17:06:23 +02:00
onDaemonReady();
} else {
2017-04-09 17:06:23 +02:00
ReactDOM.render(<SplashScreen message="Connecting" onLoadDone={onDaemonReady} />, canvas);
}
2016-03-14 23:05:24 +01:00
};
init();