From cbabc0c38eca953134e7ea3df9882bfd928ab2e2 Mon Sep 17 00:00:00 2001 From: Shawn Date: Mon, 18 Mar 2019 22:33:46 -0500 Subject: [PATCH] Fix Linux dev mode and updater --- package.json | 2 +- src/platforms/electron/index.js | 44 ++++++++++++++++++++++++--------- webpack.electron.config.js | 4 +++ yarn.lock | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 4a8a417f1..6a72cd3c3 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "dom-scroll-into-view": "^1.2.1", "electron": "4.1.0", "electron-builder": "^20.38.4", - "electron-devtools-installer": "^2.2.3", + "electron-devtools-installer": "^2.2.4", "electron-is-dev": "^0.3.0", "electron-publisher-s3": "^20.8.1", "electron-webpack": "^2.6.2", diff --git a/src/platforms/electron/index.js b/src/platforms/electron/index.js index 8f3b8fa04..3eeb743b2 100644 --- a/src/platforms/electron/index.js +++ b/src/platforms/electron/index.js @@ -86,7 +86,24 @@ app.on('ready', async() => { startSandbox(); if (isDev) { - await installExtensions(); + //await installExtensions(); + const { + default: installExtension, + REACT_DEVELOPER_TOOLS, + REDUX_DEVTOOLS, REACT_PERF, + } = require('electron-devtools-installer'); + + await installExtension(REACT_DEVELOPER_TOOLS) + .then((name) => console.log(`Added Extension: ${name}`)) + .catch((err) => console.log('An error occurred: ', err)); + + await installExtension(REDUX_DEVTOOLS) + .then((name) => console.log(`Added Extension: ${name}`)) + .catch((err) => console.log('An error occurred: ', err)); + + await installExtension(REACT_PERF) + .then((name) => console.log(`Added Extension: ${name}`)) + .catch((err) => console.log('An error occurred: ', err)); } rendererWindow = createWindow(appState); @@ -208,12 +225,6 @@ ipcMain.on('version-info-requested', () => { } const localVersion = pjson.version; - const latestReleaseAPIURL = 'https://api.github.com/repos/lbryio/lbry-desktop/releases/latest'; - const opts = { - headers: { - 'User-Agent': `LBRY/${localVersion}`, - }, - }; let result = ''; const onSuccess = res => { res.on('data', data => { @@ -221,7 +232,13 @@ ipcMain.on('version-info-requested', () => { }); res.on('end', () => { - const tagName = JSON.parse(result).tag_name; + let json; + try { + json = JSON.parse(result); + } catch(e) { + return; + } + const tagName = json.tag_name; if (tagName) { const [, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/); if (!remoteVersion) { @@ -244,8 +261,12 @@ ipcMain.on('version-info-requested', () => { }); }; - const requestLatestRelease = (apiUrl, alreadyRedirected = false) => { - const req = https.get(Object.assign(opts, new url.URL(apiUrl)), res => { + const requestLatestRelease = (alreadyRedirected = false) => { + const req = https.get({ + hostname: 'api.github.com', + path: '/repos/lbryio/lbry-desktop/releases/latest', + headers: { 'user-agent': 'LBRY/0.29.4' }, + }, res => { if (res.statusCode === 301 || res.statusCode === 302) { requestLatestRelease(res.headers.location, true); } else { @@ -262,7 +283,7 @@ ipcMain.on('version-info-requested', () => { }); }; - requestLatestRelease(latestReleaseAPIURL); + requestLatestRelease(); }); ipcMain.on('get-auth-token', event => { @@ -276,6 +297,7 @@ ipcMain.on('set-auth-token', (event, token) => { }); process.on('uncaughtException', error => { + console.log(error); dialog.showErrorBox('Error Encountered', `Caught error: ${error}`); appState.isQuitting = true; if (daemon) daemon.quit(); diff --git a/webpack.electron.config.js b/webpack.electron.config.js index 8a43294ff..8f1bd6b09 100644 --- a/webpack.electron.config.js +++ b/webpack.electron.config.js @@ -55,6 +55,8 @@ if (process.env.NODE_ENV === 'production') { externals: { keytar: 'require("keytar")', electron: 'require("electron")', + express: 'require("express")', + 'electron-updater': 'require("electron-updater")', }, }); } else { @@ -64,6 +66,8 @@ if (process.env.NODE_ENV === 'production') { externals: { keytar: 'require("keytar")', electron: 'require("electron")', + express: 'require("express")', + 'electron-updater': 'require("electron-updater")', }, }); } diff --git a/yarn.lock b/yarn.lock index ee78e0c9e..8ae0fbba4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3378,7 +3378,7 @@ electron-builder@^20.38.4: update-notifier "^2.5.0" yargs "^12.0.5" -electron-devtools-installer@^2.2.3, electron-devtools-installer@^2.2.4: +electron-devtools-installer@^2.2.4: version "2.2.4" resolved "https://registry.yarnpkg.com/electron-devtools-installer/-/electron-devtools-installer-2.2.4.tgz#261a50337e37121d338b966f07922eb4939a8763" integrity sha512-b5kcM3hmUqn64+RUcHjjr8ZMpHS2WJ5YO0pnG9+P/RTdx46of/JrEjuciHWux6pE+On6ynWhHJF53j/EDJN0PA==