diff --git a/src/main/index.js b/src/main/index.js index e880d562c..c5aed361f 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -8,7 +8,7 @@ import Https from 'https'; import Keytar from 'keytar'; import ChildProcess from 'child_process'; import Assert from 'assert'; -import { app, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } from 'electron'; +import { app, dialog, BrowserWindow, globalShortcut, ipcMain, Menu, Tray } from 'electron'; import { autoUpdater } from 'electron-updater'; import log from 'electron-log'; import mainMenu from './menu/mainMenu'; @@ -48,18 +48,14 @@ let daemonSubprocess; // if it dies when we didn't ask it to shut down, we want to alert the user. let daemonStopRequested = false; -// This keeps track of whether a new file has been downloaded. We mostly -// handle auto-update stuff in the render process, but need to know this -// in order to display the extra confirmation dialog we show on close -// on Windows. -let updateDownloaded; -if (process.platform === 'win32') { - updateDownloaded = false; -} +// This keeps track of whether the user has declined an update that was downloaded +// through the Electron auto-update system. When the user declines an update on Windows, +// they will get a confusing dialog, so we show our own dialog first. +let autoUpdateDeclined = false; // This is used to keep track of whether we are showing he special dialog // that we show on Windows after you decline an upgrade and close the app later. -let showingUpdateCloseAlert = false; +let showingAutoUpdateCloseAlert = false; // When a quit is attempted, we cancel the quit, do some preparations, then @@ -420,10 +416,6 @@ if (isDevelopment) { }); } -autoUpdater.on('update-downloaded', () => { - updateDownloaded = true; -}); - app.setAsDefaultProtocolClient('lbry'); app.on('ready', () => { @@ -449,18 +441,25 @@ app.on('window-all-closed', () => { }); app.on('before-quit', event => { - if (process.platform === 'darwin' && updateDownloaded && !showingUpdateCloseAlert) { - // We haven't shown the special dialog that we show on Windows - // if the user declines an update and then quits later - rendererWindow.webContents.send('quitRequested'); - showingUpdateCloseAlert = true; - } else if (!readyToQuit) { + if (!readyToQuit) { // We need to shutdown the daemon before we're ready to actually quit. This // event will be triggered re-entrantly once preparation is done. event.preventDefault(); shutdownDaemonAndQuit(); - } else { - console.log('Quitting.'); + } else if (process.platform == 'win32' && autoUpdateDeclined && !showingAutoUpdateCloseAlert) { + // On Windows, if the user declined an update and closes the app later, + // they get a confusing permission escalation dialog, so we display a + // dialog to warn them. + event.preventDefault(); + showingAutoUpdateCloseAlert = true; + dialog.showMessageBox({ + type: "info", + title: "LBRY Will Upgrade", + message: "Please select \"Yes\" at the upgrade prompt shown after the app closes.", + }, () => { + // After the user approves the dialog, we can quit once and for all. + quitNow(); + }); } }); @@ -549,7 +548,11 @@ ipcMain.on('version-info-requested', () => { ipcMain.on('autoUpdate', () => { minimize = false; - autoUpdater.quitAndInstall(); + app.quit(); +}); + +ipcMain.on('autoUpdateDeclined', () => { + autoUpdateDeclined = true; }); ipcMain.on('get-auth-token', event => { diff --git a/src/renderer/constants/modal_types.js b/src/renderer/constants/modal_types.js index aba7e21aa..8e56e8237 100644 --- a/src/renderer/constants/modal_types.js +++ b/src/renderer/constants/modal_types.js @@ -3,7 +3,6 @@ export const INCOMPATIBLE_DAEMON = 'incompatibleDaemon'; export const FILE_TIMEOUT = 'file_timeout'; export const DOWNLOADING = 'downloading'; export const AUTO_UPDATE_DOWNLOADED = "auto_update_downloaded"; -export const UPDATE_CLOSE_ALERT = "updateCloseAlert"; export const ERROR = 'error'; export const INSUFFICIENT_CREDITS = 'insufficient_credits'; export const UPGRADE = 'upgrade'; diff --git a/src/renderer/index.js b/src/renderer/index.js index cd9ab98ff..cafd41c35 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -9,7 +9,7 @@ import lbry from 'lbry'; import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; -import { doConditionalAuthNavigate, doOpenModal, doDaemonReady, doShowSnackBar, doAutoUpdate } from 'redux/actions/app'; +import { doConditionalAuthNavigate, doDaemonReady, doShowSnackBar, doAutoUpdate } from 'redux/actions/app'; import { doNavigate } from 'redux/actions/navigation'; import { doDownloadLanguages } from 'redux/actions/settings'; import { doUserEmailVerify } from 'redux/actions/user'; @@ -62,7 +62,7 @@ ipcRenderer.on('window-is-focused', () => { dock.setBadge(''); }); -(function(history, ...args) { +((history, ...args) => { const { replaceState } = history; const newHistory = history; newHistory.replaceState = (_, __, path) => { diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/index.js b/src/renderer/modal/modalAutoUpdateDownloaded/index.js index 0ce6cdcbe..740a2dca2 100644 --- a/src/renderer/modal/modalAutoUpdateDownloaded/index.js +++ b/src/renderer/modal/modalAutoUpdateDownloaded/index.js @@ -2,7 +2,6 @@ import React from "react"; import { connect } from "react-redux"; import { doCloseModal } from "redux/actions/app"; import ModalAutoUpdateDownloaded from "./view"; -import { doCloseModal } from "redux/actions/app"; const perform = dispatch => ({ closeModal: () => dispatch(doCloseModal()), diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx index 39971118a..ac347d7c5 100644 --- a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx +++ b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx @@ -19,7 +19,10 @@ class ModalAutoUpdateDownloaded extends React.PureComponent { onConfirmed={() => { ipcRenderer.send("autoUpdate"); }} - onAborted={closeModal} + onAborted={() => { + ipcRenderer.send("autoUpdateDeclined"); + closeModal(); + }} >

{__("LBRY Leveled Up")}

diff --git a/src/renderer/modal/modalRouter/view.jsx b/src/renderer/modal/modalRouter/view.jsx index a8fa1dfbf..81925c966 100644 --- a/src/renderer/modal/modalRouter/view.jsx +++ b/src/renderer/modal/modalRouter/view.jsx @@ -3,7 +3,6 @@ import ModalError from 'modal/modalError'; import ModalAuthFailure from 'modal/modalAuthFailure'; import ModalDownloading from 'modal/modalDownloading'; import ModalAutoUpdateDownloaded from "modal/modalAutoUpdateDownloaded"; -import ModalUpdateCloseAlert from "modal/modalUpdateCloseAlert"; import ModalUpgrade from 'modal/modalUpgrade'; import ModalWelcome from 'modal/modalWelcome'; import ModalFirstReward from 'modal/modalFirstReward'; @@ -106,8 +105,6 @@ class ModalRouter extends React.PureComponent { return ; case modals.AUTO_UPDATE_DOWNLOADED: return ; - case modals.UPDATE_CLOSE_ALERT: - return ; case modals.ERROR: return ; case modals.FILE_TIMEOUT: diff --git a/src/renderer/modal/modalUpdateCloseAlert/index.js b/src/renderer/modal/modalUpdateCloseAlert/index.js deleted file mode 100644 index caff049a6..000000000 --- a/src/renderer/modal/modalUpdateCloseAlert/index.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { connect } from 'react-redux'; -import { doQuit } from 'redux/actions/app'; -import ModalUpdateCloseAlert from './view'; - -const select = state => ({}); - -const perform = dispatch => ({ - quit: () => dispatch(doSkipUpgrade()), -}); - -export default connect(select, perform)(ModalUpdateCloseAlert); diff --git a/src/renderer/modal/modalUpdateCloseAlert/view.jsx b/src/renderer/modal/modalUpdateCloseAlert/view.jsx deleted file mode 100644 index 9f0b28c3a..000000000 --- a/src/renderer/modal/modalUpdateCloseAlert/view.jsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import { Modal } from 'modal/modal'; -import Link from 'component/link'; - -class ModalUpdateCloseAlert extends React.PureComponent { - render() { - const { quit } = this.props; - - return ( - -

{__('LBRY Will Upgrade')}

-

{__('Please select yes to the upgrade prompt shown after the app closes.')}

-
- ); - } -} - -export default ModalUpdateCloseAlert;