Merge pull request #758 from lbryio/issue/752

Integrate React and Redux devtools into Electron
This commit is contained in:
Liam Cardenas 2017-11-21 13:28:09 -05:00 committed by GitHub
commit 3d8524d287
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 22 deletions

View file

@ -1,21 +1,7 @@
module.exports = { safeQuit } // Module imports
const {app, BrowserWindow, ipcMain, Menu, Tray, globalShortcut} = require('electron'); const {app, BrowserWindow, ipcMain, Menu, Tray, globalShortcut} = require('electron');
const url = require('url');
const isDebug = process.env.NODE_ENV === 'development';
const setMenu = require('./menu/main-menu.js');
if (isDebug) {
try
{
require('electron-debug')({showDevTools: true});
}
catch (err) // electron-debug is in devDependencies, but some
{
console.error(err)
}
}
const path = require('path'); const path = require('path');
const url = require('url');
const jayson = require('jayson'); const jayson = require('jayson');
const semver = require('semver'); const semver = require('semver');
const https = require('https'); const https = require('https');
@ -26,8 +12,31 @@ const kill = require('tree-kill');
const child_process = require('child_process'); const child_process = require('child_process');
const assert = require('assert'); const assert = require('assert');
const {version: localVersion} = require(app.getAppPath() + '/package.json'); const {version: localVersion} = require(app.getAppPath() + '/package.json');
const setMenu = require('./menu/main-menu.js');
const VERSION_CHECK_INTERVAL = 30 * 60 * 1000; // Debug configs
const isDebug = process.env.NODE_ENV === 'development';
if (isDebug) {
try
{
require('electron-debug')({showDevTools: true});
const { default: installExtension, REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS } = require('electron-devtools-installer');
app.on('ready', () => {
[REACT_DEVELOPER_TOOLS, REDUX_DEVTOOLS].forEach(extension => {
installExtension(extension)
.then((name) => console.log(`Added Extension: ${name}`))
.catch((err) => console.log('An error occurred: ', err));
});
});
}
catch (err) // electron-debug is in devDependencies, but some
{
console.error(err)
}
}
// Misc constants
const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest'; const LATEST_RELEASE_API_URL = 'https://api.github.com/repos/lbryio/lbry-app/releases/latest';
const DAEMON_PATH = process.env.LBRY_DAEMON || path.join(__dirname, 'dist', 'lbrynet-daemon'); const DAEMON_PATH = process.env.LBRY_DAEMON || path.join(__dirname, 'dist', 'lbrynet-daemon');
@ -283,7 +292,7 @@ function handleOpenUriRequested(uri) {
// Window not created yet, so store up requested URI for when it is // Window not created yet, so store up requested URI for when it is
openUri = processRequestedUri(uri); openUri = processRequestedUri(uri);
} else { } else {
if (win.isMinimized()) { if (win.isMinimized()) {
win.restore() win.restore()
} else if (!win.isVisible()) { } else if (!win.isVisible()) {
@ -365,7 +374,7 @@ if (isSecondaryInstance) { // We're not in the original process, so quit
return; return;
} }
app.on('ready', function(){ app.on('ready', function() {
launchDaemonIfNotRunning(); launchDaemonIfNotRunning();
if (process.platform === "linux") { if (process.platform === "linux") {
checkLinuxTraySupport( err => { checkLinuxTraySupport( err => {
@ -545,3 +554,5 @@ ipcMain.on('get-auth-token', (event) => {
ipcMain.on('set-auth-token', (event, token) => { ipcMain.on('set-auth-token', (event, token) => {
keytar.setPassword("LBRY", "auth_token", token ? token.toString().trim() : null); keytar.setPassword("LBRY", "auth_token", token ? token.toString().trim() : null);
}); });
module.exports = { safeQuit };

View file

@ -70,7 +70,8 @@
"devtron": "^1.4.0", "devtron": "^1.4.0",
"electron": "^1.7.9", "electron": "^1.7.9",
"electron-builder": "^11.7.0", "electron-builder": "^11.7.0",
"electron-debug": "^1.4.0" "electron-debug": "^1.4.0",
"electron-devtools-installer": "^2.2.1"
}, },
"license": "MIT" "license": "MIT"
} }

View file

@ -80,8 +80,9 @@ if (env === "development") {
} }
// middleware.push(createActionBuffer(REHYDRATE)); // was causing issues with authentication reducers not firing // middleware.push(createActionBuffer(REHYDRATE)); // was causing issues with authentication reducers not firing
const composeEnhancers =
const createStoreWithMiddleware = redux.compose( window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || redux.compose;
const createStoreWithMiddleware = composeEnhancers(
autoRehydrate(), autoRehydrate(),
redux.applyMiddleware(...middleware) redux.applyMiddleware(...middleware)
)(redux.createStore); )(redux.createStore);