2016-11-22 14:19:08 -06:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import lbry from './lbry.js';
|
2017-03-30 19:00:33 -04:00
|
|
|
import lbryio from './lbryio.js';
|
2016-12-29 04:41:28 -05:00
|
|
|
import lighthouse from './lighthouse.js';
|
2017-05-19 12:17:19 -04:00
|
|
|
import App from 'component/app/index.js';
|
|
|
|
import SplashScreen from 'component/splash.js';
|
2017-05-23 11:21:21 +04:00
|
|
|
import SnackBar from 'component/snackBar';
|
2017-05-19 12:17:19 -04:00
|
|
|
import {AuthOverlay} from 'component/auth.js';
|
2017-04-07 12:15:22 +07:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import store from 'store.js';
|
2017-04-22 20:46:04 +07:00
|
|
|
import {
|
2017-05-06 14:25:14 +07:00
|
|
|
doChangePath,
|
2017-05-21 15:41:26 -04:00
|
|
|
doNavigate,
|
2017-05-25 14:29:28 -04:00
|
|
|
doDaemonReady
|
2017-04-22 20:46:04 +07:00
|
|
|
} from 'actions/app'
|
2017-05-17 17:52:45 -04:00
|
|
|
import {
|
|
|
|
doFetchDaemonSettings
|
|
|
|
} from 'actions/settings'
|
2017-05-18 13:58:28 -04:00
|
|
|
import {
|
|
|
|
doFileList
|
|
|
|
} from 'actions/file_info'
|
2017-05-23 12:46:52 +04:00
|
|
|
import {
|
|
|
|
toQueryString,
|
|
|
|
} from 'util/query_params'
|
2016-11-22 14:19:08 -06:00
|
|
|
|
2017-05-21 12:15:41 -04:00
|
|
|
const {remote, ipcRenderer, shell} = require('electron');
|
2017-03-17 07:41:01 -04:00
|
|
|
const contextMenu = remote.require('./menu/context-menu');
|
2017-04-07 12:15:22 +07:00
|
|
|
const app = require('./app')
|
2017-03-17 07:41:01 -04:00
|
|
|
|
2017-03-08 03:56:34 -05:00
|
|
|
lbry.showMenuIfNeeded();
|
2016-11-22 14:19:08 -06:00
|
|
|
|
2017-03-17 07:41:01 -04:00
|
|
|
window.addEventListener('contextmenu', (event) => {
|
|
|
|
contextMenu.showContextMenu(remote.getCurrentWindow(), event.x, event.y,
|
|
|
|
lbry.getClientSetting('showDeveloperMenu'));
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-05-18 19:14:26 -04:00
|
|
|
window.addEventListener('popstate', (event, param) => {
|
2017-05-23 12:46:52 +04:00
|
|
|
const params = event.state
|
2017-05-17 17:52:45 -04:00
|
|
|
const pathParts = document.location.pathname.split('/')
|
|
|
|
const route = '/' + pathParts[pathParts.length - 1]
|
2017-05-23 12:46:52 +04:00
|
|
|
const queryString = toQueryString(params)
|
2017-05-17 17:52:45 -04:00
|
|
|
|
2017-05-22 19:58:33 +04:00
|
|
|
let action
|
|
|
|
if (route.match(/html$/)) {
|
|
|
|
action = doChangePath('/discover')
|
|
|
|
} else {
|
2017-05-23 12:46:52 +04:00
|
|
|
action = doChangePath(`${route}?${queryString}`)
|
2017-05-22 19:58:33 +04:00
|
|
|
}
|
2017-05-18 19:14:26 -04:00
|
|
|
|
2017-05-22 19:58:33 +04:00
|
|
|
app.store.dispatch(action)
|
2017-05-06 14:25:14 +07:00
|
|
|
})
|
|
|
|
|
2017-05-09 16:58:48 -04:00
|
|
|
ipcRenderer.on('open-uri-requested', (event, uri) => {
|
2017-05-21 15:41:26 -04:00
|
|
|
if (uri && uri.startsWith('lbry://')) {
|
2017-05-24 18:46:27 -04:00
|
|
|
app.store.dispatch(doNavigate('/show', { uri }))
|
2017-05-14 23:50:59 -04:00
|
|
|
}
|
2017-05-09 16:58:48 -04:00
|
|
|
});
|
2017-05-08 05:04:11 -04:00
|
|
|
|
2017-05-21 12:15:41 -04:00
|
|
|
document.addEventListener('click', (event) => {
|
|
|
|
var target = event.target;
|
|
|
|
while (target && target !== document) {
|
|
|
|
if (target.matches('a[href^="http"]')) {
|
|
|
|
event.preventDefault();
|
|
|
|
shell.openExternal(target.href);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
target = target.parentNode;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-04-07 12:15:22 +07:00
|
|
|
const initialState = app.store.getState();
|
|
|
|
|
|
|
|
var init = function() {
|
2017-04-09 11:06:23 -04:00
|
|
|
|
2017-04-10 08:32:40 -04:00
|
|
|
function onDaemonReady() {
|
2017-04-09 11:06:23 -04:00
|
|
|
window.sessionStorage.setItem('loaded', 'y'); //once we've made it here once per session, we don't need to show splash again
|
2017-05-22 21:18:24 +04:00
|
|
|
const actions = []
|
|
|
|
|
2017-05-28 15:35:11 +04:00
|
|
|
app.store.dispatch(doDaemonReady())
|
|
|
|
app.store.dispatch(doChangePath('/discover'))
|
|
|
|
app.store.dispatch(doFetchDaemonSettings())
|
|
|
|
app.store.dispatch(doFileList())
|
2017-05-22 21:18:24 +04:00
|
|
|
|
2017-04-22 20:17:01 +07:00
|
|
|
ReactDOM.render(<Provider store={store}><div>{ lbryio.enabled ? <AuthOverlay/> : '' }<App /><SnackBar /></div></Provider>, canvas)
|
2017-04-09 11:06:23 -04:00
|
|
|
}
|
|
|
|
|
2017-04-10 08:32:40 -04:00
|
|
|
if (window.sessionStorage.getItem('loaded') == 'y') {
|
2017-04-09 11:06:23 -04:00
|
|
|
onDaemonReady();
|
2017-01-24 22:20:41 -05:00
|
|
|
} else {
|
2017-04-09 11:06:23 -04:00
|
|
|
ReactDOM.render(<SplashScreen message="Connecting" onLoadDone={onDaemonReady} />, canvas);
|
2017-01-24 22:20:41 -05:00
|
|
|
}
|
2016-03-14 18:05:24 -04:00
|
|
|
};
|
|
|
|
|
2017-04-01 02:36:45 -04:00
|
|
|
init();
|