diff --git a/src/main/index.js b/src/main/index.js index eb5d53b6a..e880d562c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -48,6 +48,20 @@ 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 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; + + // When a quit is attempted, we cancel the quit, do some preparations, then // this is set to true and app.quit() is called again to quit for real. let readyToQuit = false; @@ -406,6 +420,10 @@ if (isDevelopment) { }); } +autoUpdater.on('update-downloaded', () => { + updateDownloaded = true; +}); + app.setAsDefaultProtocolClient('lbry'); app.on('ready', () => { @@ -431,7 +449,12 @@ app.on('window-all-closed', () => { }); app.on('before-quit', event => { - if (!readyToQuit) { + 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) { // 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(); diff --git a/src/renderer/constants/modal_types.js b/src/renderer/constants/modal_types.js index 8e56e8237..aba7e21aa 100644 --- a/src/renderer/constants/modal_types.js +++ b/src/renderer/constants/modal_types.js @@ -3,6 +3,7 @@ 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 cafd41c35..cd9ab98ff 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, doDaemonReady, doShowSnackBar, doAutoUpdate } from 'redux/actions/app'; +import { doConditionalAuthNavigate, doOpenModal, 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(''); }); -((history, ...args) => { +(function(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 740a2dca2..0ce6cdcbe 100644 --- a/src/renderer/modal/modalAutoUpdateDownloaded/index.js +++ b/src/renderer/modal/modalAutoUpdateDownloaded/index.js @@ -2,6 +2,7 @@ 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/modalRouter/view.jsx b/src/renderer/modal/modalRouter/view.jsx index 81925c966..a8fa1dfbf 100644 --- a/src/renderer/modal/modalRouter/view.jsx +++ b/src/renderer/modal/modalRouter/view.jsx @@ -3,6 +3,7 @@ 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'; @@ -105,6 +106,8 @@ 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 new file mode 100644 index 000000000..caff049a6 --- /dev/null +++ b/src/renderer/modal/modalUpdateCloseAlert/index.js @@ -0,0 +1,12 @@ +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 new file mode 100644 index 000000000..9f0b28c3a --- /dev/null +++ b/src/renderer/modal/modalUpdateCloseAlert/view.jsx @@ -0,0 +1,23 @@ +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; diff --git a/src/renderer/redux/actions/app.js b/src/renderer/redux/actions/app.js index e2b36470b..8ae003bf7 100644 --- a/src/renderer/redux/actions/app.js +++ b/src/renderer/redux/actions/app.js @@ -110,8 +110,8 @@ export function doAutoUpdate() { return function(dispatch, getState) { const state = getState(); dispatch({ - type: types.OPEN_MODAL, - data: { modal: modals.AUTO_UPDATE_DOWNLOADED }, + type: ACTIONS.OPEN_MODAL, + data: { modal: MODALS.AUTO_UPDATE_DOWNLOADED }, }); }; }