diff --git a/electron/createWindow.js b/electron/createWindow.js index 3191126c7..042fae9b1 100644 --- a/electron/createWindow.js +++ b/electron/createWindow.js @@ -54,6 +54,7 @@ export default appState => { webSecurity: !isDev, plugins: true, nodeIntegration: true, + enableRemoteModule: true, // see about removing this }, }; const lbryProto = 'lbry://'; diff --git a/electron/index.js b/electron/index.js index be4d11801..8f0428298 100644 --- a/electron/index.js +++ b/electron/index.js @@ -4,7 +4,7 @@ import '@babel/polyfill'; import SemVer from 'semver'; import https from 'https'; -import { app, dialog, ipcMain, session, shell } from 'electron'; +import { app, dialog, ipcMain, session, shell, BrowserWindow } from 'electron'; import { autoUpdater } from 'electron-updater'; import Lbry from 'lbry'; import LbryFirstInstance from './LbryFirstInstance'; @@ -17,6 +17,7 @@ import startSandbox from './startSandbox'; import installDevtools from './installDevtools'; import fs from 'fs'; import path from 'path'; +const { download } = require('electron-dl'); const filePath = path.join(process.resourcesPath, 'static', 'upgradeDisabled'); let upgradeDisabled; try { @@ -283,6 +284,20 @@ app.on('before-quit', () => { appState.isQuitting = true; }); +ipcMain.on('download-upgrade', async (event, params) => { + const { url, options } = params; + const dir = fs.mkdtempSync(app.getPath('temp') + path.sep); + options.onProgress = function(p) { + rendererWindow.webContents.send('download-progress-update', p); + }; + options.directory = dir; + options.onCompleted = function(c) { + rendererWindow.webContents.send('download-update-complete', c); + }; + const win = BrowserWindow.getFocusedWindow(); + await download(win, url, options).catch(e => console.log('e', e)); +}); + ipcMain.on('upgrade', (event, installerPath) => { app.on('quit', () => { console.log('Launching upgrade installer at', installerPath); @@ -297,6 +312,10 @@ ipcMain.on('upgrade', (event, installerPath) => { app.quit(); }); +ipcMain.on('check-for-updates', () => { + autoUpdater.checkForUpdates(); +}); + autoUpdater.on('update-downloaded', () => { autoUpdateDownloaded = true; }); diff --git a/package.json b/package.json index 1383dd3d3..08e13f5c1 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "dependencies": { "@ungap/from-entries": "^0.2.1", "auto-launch": "^5.0.5", - "electron-dl": "^1.11.0", + "electron-dl": "^3.2.0", "electron-log": "^2.2.12", "electron-notarize": "^1.0.0", "electron-updater": "^4.2.4", @@ -123,7 +123,7 @@ "dom-scroll-into-view": "^1.2.1", "dotenv-defaults": "^2.0.1", "dotenv-webpack": "^1.8.0", - "electron": "9.4.0", + "electron": "11.5.0", "electron-builder": "^22.9.1", "electron-devtools-installer": "^3.1.1", "electron-is-dev": "^0.3.0", diff --git a/ui/index.jsx b/ui/index.jsx index f9e3f9f52..93dd6435c 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -11,7 +11,14 @@ import * as MODALS from 'constants/modal_types'; import React, { Fragment, useState, useEffect } from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; -import { doDaemonReady, doAutoUpdate, doOpenModal, doHideModal, doToggle3PAnalytics } from 'redux/actions/app'; +import { + doDaemonReady, + doAutoUpdate, + doOpenModal, + doHideModal, + doToggle3PAnalytics, + doUpdateDownloadProgress, +} from 'redux/actions/app'; import { isURIValid } from 'util/lbryURI'; import { setSearchApi } from 'redux/actions/search'; import { doSetLanguage, doFetchLanguage, doUpdateIsNightAsync } from 'redux/actions/settings'; @@ -107,6 +114,19 @@ ipcRenderer.on('open-uri-requested', (event, url, newSession) => { handleError(); }); +ipcRenderer.on('download-progress-update', (e, p) => { + app.store.dispatch(doUpdateDownloadProgress(Math.round(p.percent * 100))); +}); + +ipcRenderer.on('download-update-complete', (e, c) => { + app.store.dispatch({ + type: ACTIONS.UPGRADE_DOWNLOAD_COMPLETED, + data: { + path: c.path, + }, + }); +}); + ipcRenderer.on('language-set', (event, language) => { app.store.dispatch(doSetLanguage(language)); }); diff --git a/ui/redux/actions/app.js b/ui/redux/actions/app.js index c8d3fe78c..3c8393fac 100644 --- a/ui/redux/actions/app.js +++ b/ui/redux/actions/app.js @@ -1,9 +1,6 @@ -// @if TARGET='app' import { execSync } from 'child_process'; import isDev from 'electron-is-dev'; import { ipcRenderer, remote } from 'electron'; -// @endif -import path from 'path'; import * as ACTIONS from 'constants/action_types'; import * as MODALS from 'constants/modal_types'; import * as SETTINGS from 'constants/settings'; @@ -33,7 +30,6 @@ import { selectUpdateUrl, selectUpgradeDownloadItem, selectUpgradeDownloadPath, - selectUpgradeFilename, selectAutoUpdateDeclined, selectRemoteVersion, selectUpgradeTimer, @@ -50,12 +46,6 @@ import { doSignOutCleanup } from 'util/saved-passwords'; import { doNotificationSocketConnect } from 'redux/actions/websocket'; import { stringifyServerParam, shouldSetSetting } from 'util/sync-settings'; -// @if TARGET='app' -const { autoUpdater } = remote.require('electron-updater'); -const { download } = remote.require('electron-dl'); -const Fs = remote.require('fs'); -// @endif - const CHECK_UPGRADE_INTERVAL = 10 * 60 * 1000; export function doOpenModal(id, modalProps = {}) { @@ -100,38 +90,14 @@ export function doStartUpgrade() { export function doDownloadUpgrade() { return (dispatch, getState) => { - // @if TARGET='app' const state = getState(); - // Make a new directory within temp directory so the filename is guaranteed to be available - const dir = Fs.mkdtempSync(remote.app.getPath('temp') + path.sep); - const upgradeFilename = selectUpgradeFilename(state); - - const options = { - onProgress: (p) => dispatch(doUpdateDownloadProgress(Math.round(p * 100))), - directory: dir, - }; - download(remote.getCurrentWindow(), selectUpdateUrl(state), options).then((downloadItem) => { - /** - * TODO: get the download path directly from the download object. It should just be - * downloadItem.getSavePath(), but the copy on the main process is being garbage collected - * too soon. - */ - - dispatch({ - type: ACTIONS.UPGRADE_DOWNLOAD_COMPLETED, - data: { - downloadItem, - path: path.join(dir, upgradeFilename), - }, - }); - }); - + const url = selectUpdateUrl(state); + ipcRenderer.send('download-upgrade', { url, options: {} }); dispatch({ type: ACTIONS.UPGRADE_DOWNLOAD_STARTED, }); dispatch(doHideModal()); dispatch(doOpenModal(MODALS.DOWNLOADING)); - // @endif }; } @@ -222,7 +188,7 @@ export function doCheckUpgradeAvailable() { const autoUpdateDeclined = selectAutoUpdateDeclined(state); if (!autoUpdateDeclined && !isDev) { - autoUpdater.checkForUpdates(); + ipcRenderer.send('check-for-updates'); } return; } diff --git a/yarn.lock b/yarn.lock index 27c13a1ee..37d887ff9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6005,13 +6005,14 @@ electron-devtools-installer@^3.1.1: semver "^7.2.1" unzip-crx-3 "^0.2.0" -electron-dl@^1.11.0: - version "1.14.0" - resolved "https://registry.yarnpkg.com/electron-dl/-/electron-dl-1.14.0.tgz#1466f1b945664ca3d784268307c2b935728177bf" +electron-dl@^3.2.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/electron-dl/-/electron-dl-3.3.0.tgz#4e422e276c627373ba61fcf3f92ffa088988db1a" + integrity sha512-Zwaz/OMGPIfBLV2SQH4sTsdDOs/U4y5AOHfremMBXEpjIxX+SiTx845DZAvJJwgb5hfowyWOBLiJhd/emBNLLQ== dependencies: ext-name "^5.0.0" - pupa "^1.0.0" - unused-filename "^1.0.0" + pupa "^2.0.1" + unused-filename "^2.1.0" electron-is-dev@^0.3.0: version "0.3.0" @@ -6120,10 +6121,10 @@ electron-window-state@^4.1.1: jsonfile "^2.2.3" mkdirp "^0.5.1" -electron@9.4.0: - version "9.4.0" - resolved "https://registry.yarnpkg.com/electron/-/electron-9.4.0.tgz#c3c607e3598226ddbaaff8babcdffa8bb2210936" - integrity sha512-hOC4q0jkb+UDYZRy8vrZ1IANnq+jznZnbkD62OEo06nU+hIbp2IrwDRBNuSLmQ3cwZMVir0WSIA1qEVK0PkzGA== +electron@11.5.0: + version "11.5.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-11.5.0.tgz#f1650543b9d8f2047d3807755bdb120153ed210f" + integrity sha512-WjNDd6lGpxyiNjE3LhnFCAk/D9GIj1rU3GSDealVShhkkkPR3Vh4q8ErXGDl1OAO/faomVa10KoFPUN/pLbNxg== dependencies: "@electron/get" "^1.0.1" "@types/node" "^12.0.12" @@ -13134,10 +13135,6 @@ punycode@^2.1.0, punycode@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" -pupa@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/pupa/-/pupa-1.0.0.tgz#9a9568a5af7e657b8462a6e9d5328743560ceff6" - pupa@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/pupa/-/pupa-2.0.1.tgz#dbdc9ff48ffbea4a26a069b6f9f7abb051008726" @@ -16278,12 +16275,13 @@ untildify@^4.0.0: resolved "https://registry.yarnpkg.com/untildify/-/untildify-4.0.0.tgz#2bc947b953652487e4600949fb091e3ae8cd919b" integrity sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw== -unused-filename@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/unused-filename/-/unused-filename-1.0.0.tgz#d340880f71ae2115ebaa1325bef05cc6684469c6" +unused-filename@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/unused-filename/-/unused-filename-2.1.0.tgz#33719c4e8d9644f32d2dec1bc8525c6aaeb4ba51" + integrity sha512-BMiNwJbuWmqCpAM1FqxCTD7lXF97AvfQC8Kr/DIeA6VtvhJaMDupZ82+inbjl5yVP44PcxOuCSxye1QMS0wZyg== dependencies: modify-filename "^1.1.0" - path-exists "^3.0.0" + path-exists "^4.0.0" unzip-crx-3@^0.2.0: version "0.2.0"