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';
|
2017-05-26 02:16:25 +02:00
|
|
|
|
2017-05-28 16:09:56 +02:00
|
|
|
const i18n = require('y18n')({directory: 'app/locales'/*, locale: lbry.getClientSetting('language')*/});
|
2017-05-26 02:16:25 +02:00
|
|
|
window.__ = i18n.__;
|
|
|
|
window.__n = i18n.__n;
|
2017-05-28 16:09:56 +02:00
|
|
|
window.i18n = i18n;
|
2017-05-26 02:16:25 +02:00
|
|
|
|
2016-12-29 10:41:28 +01:00
|
|
|
import lighthouse from './lighthouse.js';
|
2017-05-19 18:17:19 +02:00
|
|
|
import App from 'component/app/index.js';
|
2017-05-23 09:21:21 +02:00
|
|
|
import SnackBar from 'component/snackBar';
|
2017-04-07 07:15:22 +02:00
|
|
|
import { Provider } from 'react-redux';
|
|
|
|
import store from 'store.js';
|
2017-05-26 02:16:25 +02:00
|
|
|
import SplashScreen from 'component/splash.js';
|
|
|
|
import {AuthOverlay} from 'component/auth.js';
|
2017-04-22 15:46:04 +02:00
|
|
|
import {
|
2017-05-06 09:25:14 +02:00
|
|
|
doChangePath,
|
2017-05-21 21:41:26 +02:00
|
|
|
doNavigate,
|
2017-05-25 20:29:28 +02:00
|
|
|
doDaemonReady
|
2017-04-22 15:46:04 +02:00
|
|
|
} from 'actions/app'
|
2017-05-17 23:52:45 +02:00
|
|
|
import {
|
|
|
|
doFetchDaemonSettings
|
|
|
|
} from 'actions/settings'
|
2017-05-18 19:58:28 +02:00
|
|
|
import {
|
|
|
|
doFileList
|
|
|
|
} from 'actions/file_info'
|
2017-05-23 10:46:52 +02:00
|
|
|
import {
|
|
|
|
toQueryString,
|
|
|
|
} from 'util/query_params'
|
2016-11-22 21:19:08 +01:00
|
|
|
|
2017-05-21 18:15:41 +02:00
|
|
|
const {remote, ipcRenderer, shell} = require('electron');
|
2017-03-17 12:41:01 +01:00
|
|
|
const contextMenu = remote.require('./menu/context-menu');
|
2017-04-07 07:15:22 +02:00
|
|
|
const app = require('./app')
|
2017-03-17 12:41:01 +01:00
|
|
|
|
2017-05-25 18:29:56 +02:00
|
|
|
|
2017-03-08 09:56:34 +01:00
|
|
|
lbry.showMenuIfNeeded();
|
2016-11-22 21:19:08 +01:00
|
|
|
|
2017-03-17 12:41:01 +01:00
|
|
|
window.addEventListener('contextmenu', (event) => {
|
|
|
|
contextMenu.showContextMenu(remote.getCurrentWindow(), event.x, event.y,
|
|
|
|
lbry.getClientSetting('showDeveloperMenu'));
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
|
2017-05-19 01:14:26 +02:00
|
|
|
window.addEventListener('popstate', (event, param) => {
|
2017-05-23 10:46:52 +02:00
|
|
|
const params = event.state
|
2017-05-17 23:52:45 +02:00
|
|
|
const pathParts = document.location.pathname.split('/')
|
|
|
|
const route = '/' + pathParts[pathParts.length - 1]
|
2017-05-23 10:46:52 +02:00
|
|
|
const queryString = toQueryString(params)
|
2017-05-17 23:52:45 +02:00
|
|
|
|
2017-05-22 17:58:33 +02:00
|
|
|
let action
|
|
|
|
if (route.match(/html$/)) {
|
|
|
|
action = doChangePath('/discover')
|
|
|
|
} else {
|
2017-05-23 10:46:52 +02:00
|
|
|
action = doChangePath(`${route}?${queryString}`)
|
2017-05-22 17:58:33 +02:00
|
|
|
}
|
2017-05-19 01:14:26 +02:00
|
|
|
|
2017-05-22 17:58:33 +02:00
|
|
|
app.store.dispatch(action)
|
2017-05-06 09:25:14 +02:00
|
|
|
})
|
|
|
|
|
2017-05-09 22:58:48 +02:00
|
|
|
ipcRenderer.on('open-uri-requested', (event, uri) => {
|
2017-05-21 21:41:26 +02:00
|
|
|
if (uri && uri.startsWith('lbry://')) {
|
2017-05-25 00:46:27 +02:00
|
|
|
app.store.dispatch(doNavigate('/show', { uri }))
|
2017-05-15 05:50:59 +02:00
|
|
|
}
|
2017-05-09 22:58:48 +02:00
|
|
|
});
|
2017-05-08 11:04:11 +02:00
|
|
|
|
2017-05-21 18:15:41 +02: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 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() {
|
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
|
2017-05-22 19:18:24 +02:00
|
|
|
const actions = []
|
|
|
|
|
2017-05-28 13:35:11 +02:00
|
|
|
app.store.dispatch(doDaemonReady())
|
|
|
|
app.store.dispatch(doChangePath('/discover'))
|
|
|
|
app.store.dispatch(doFetchDaemonSettings())
|
|
|
|
app.store.dispatch(doFileList())
|
2017-05-22 19:18:24 +02:00
|
|
|
|
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();
|
2017-01-25 04:20:41 +01:00
|
|
|
} else {
|
2017-05-31 01:56:48 +02:00
|
|
|
ReactDOM.render(<SplashScreen onLoadDone={onDaemonReady} />, canvas);
|
2017-01-25 04:20:41 +01:00
|
|
|
}
|
2016-03-14 23:05:24 +01:00
|
|
|
};
|
|
|
|
|
2017-04-01 08:36:45 +02:00
|
|
|
init();
|