From 863f7dc23b0341a70f7bbe1bf47dedc8eb87f6f6 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 17 Jan 2018 05:50:02 -0500 Subject: [PATCH] Make new dialogs behave correctly when video is playing --- src/renderer/constants/action_types.js | 1 + .../modal/modalAutoUpdateConfirm/index.js | 3 +- .../modal/modalAutoUpdateConfirm/view.jsx | 3 +- .../modal/modalAutoUpdateDownloaded/index.js | 3 +- .../modal/modalAutoUpdateDownloaded/view.jsx | 3 +- src/renderer/modal/modalRouter/index.js | 3 +- src/renderer/modal/modalRouter/view.jsx | 2 +- src/renderer/redux/actions/app.js | 29 ++++++++-- src/renderer/redux/reducers/app.js | 54 ++++++++++++++++--- src/renderer/redux/selectors/app.js | 4 ++ 10 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/renderer/constants/action_types.js b/src/renderer/constants/action_types.js index 4a952d780..425955815 100644 --- a/src/renderer/constants/action_types.js +++ b/src/renderer/constants/action_types.js @@ -28,6 +28,7 @@ export const UPDATE_VERSION = 'UPDATE_VERSION'; export const UPDATE_REMOTE_VERSION = 'UPDATE_REMOTE_VERSION'; export const SKIP_UPGRADE = 'SKIP_UPGRADE'; export const START_UPGRADE = 'START_UPGRADE'; +export const AUTO_UPDATE_DECLINED = 'AUTO_UPDATE_DECLINED'; export const AUTO_UPDATE_DOWNLOADED = 'AUTO_UPDATE_DOWNLOADED'; // Wallet diff --git a/src/renderer/modal/modalAutoUpdateConfirm/index.js b/src/renderer/modal/modalAutoUpdateConfirm/index.js index 52b3bca01..a00df7e2f 100644 --- a/src/renderer/modal/modalAutoUpdateConfirm/index.js +++ b/src/renderer/modal/modalAutoUpdateConfirm/index.js @@ -1,10 +1,11 @@ import React from "react"; import { connect } from "react-redux"; -import { doCloseModal } from "redux/actions/app"; +import { doCloseModal, doAutoUpdateDeclined } from "redux/actions/app"; import ModalAutoUpdateConfirm from "./view"; const perform = dispatch => ({ closeModal: () => dispatch(doCloseModal()), + declineAutoUpdate: () => dispatch(doAutoUpdateDeclined()), }); export default connect(null, perform)(ModalAutoUpdateConfirm); diff --git a/src/renderer/modal/modalAutoUpdateConfirm/view.jsx b/src/renderer/modal/modalAutoUpdateConfirm/view.jsx index a96458e09..88218c4da 100644 --- a/src/renderer/modal/modalAutoUpdateConfirm/view.jsx +++ b/src/renderer/modal/modalAutoUpdateConfirm/view.jsx @@ -7,7 +7,7 @@ const { ipcRenderer } = require("electron"); class ModalAutoUpdateConfirm extends React.PureComponent { render() { - const { closeModal } = this.props; + const { closeModal, declineAutoUpdate } = this.props; return ( { + declineAutoUpdate(); closeModal(); }} > diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/index.js b/src/renderer/modal/modalAutoUpdateDownloaded/index.js index 740a2dca2..7283489aa 100644 --- a/src/renderer/modal/modalAutoUpdateDownloaded/index.js +++ b/src/renderer/modal/modalAutoUpdateDownloaded/index.js @@ -1,10 +1,11 @@ import React from "react"; import { connect } from "react-redux"; -import { doCloseModal } from "redux/actions/app"; +import { doCloseModal, doAutoUpdateDeclined } from "redux/actions/app"; import ModalAutoUpdateDownloaded from "./view"; const perform = dispatch => ({ closeModal: () => dispatch(doCloseModal()), + declineAutoUpdate: () => dispatch(doAutoUpdateDeclined()), }); export default connect(null, perform)(ModalAutoUpdateDownloaded); diff --git a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx index 12aa2d819..5a1b69885 100644 --- a/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx +++ b/src/renderer/modal/modalAutoUpdateDownloaded/view.jsx @@ -7,7 +7,7 @@ const { ipcRenderer } = require("electron"); class ModalAutoUpdateDownloaded extends React.PureComponent { render() { - const { closeModal } = this.props; + const { closeModal, declineAutoUpdate } = this.props; return ( { + declineAutoUpdate(); ipcRenderer.send("autoUpdateDeclined"); closeModal(); }} diff --git a/src/renderer/modal/modalRouter/index.js b/src/renderer/modal/modalRouter/index.js index 313c82528..cea033096 100644 --- a/src/renderer/modal/modalRouter/index.js +++ b/src/renderer/modal/modalRouter/index.js @@ -2,7 +2,7 @@ import React from 'react'; import { connect } from 'react-redux'; import { doOpenModal } from 'redux/actions/app'; import * as settings from 'constants/settings'; -import { selectCurrentModal, selectModalProps } from 'redux/selectors/app'; +import { selectCurrentModal, selectModalProps, selectModalsAllowed } from 'redux/selectors/app'; import { selectCurrentPage } from 'redux/selectors/navigation'; import { selectCostForCurrentPageUri } from 'redux/selectors/cost_info'; import { makeSelectClientSetting } from 'redux/selectors/settings'; @@ -24,6 +24,7 @@ const select = (state, props) => ({ ), isWelcomeAcknowledged: makeSelectClientSetting(settings.NEW_USER_ACKNOWLEDGED)(state), user: selectUser(state), + modalsAllowed: selectModalsAllowed(state), }); const perform = dispatch => ({ diff --git a/src/renderer/modal/modalRouter/view.jsx b/src/renderer/modal/modalRouter/view.jsx index 8dd7e4bc6..924444687 100644 --- a/src/renderer/modal/modalRouter/view.jsx +++ b/src/renderer/modal/modalRouter/view.jsx @@ -97,7 +97,7 @@ class ModalRouter extends React.PureComponent { } render() { - const { modal, modalProps } = this.props; + const { modal, modalsAllowed, modalProps } = this.props; switch (modal) { case modals.UPGRADE: diff --git a/src/renderer/redux/actions/app.js b/src/renderer/redux/actions/app.js index 92dc52c66..45d99b364 100644 --- a/src/renderer/redux/actions/app.js +++ b/src/renderer/redux/actions/app.js @@ -18,6 +18,7 @@ import { selectUpgradeDownloadItem, selectUpgradeDownloadPath, selectUpgradeFilename, + selectAutoUpdateDeclined, } from 'redux/selectors/app'; const { autoUpdater } = remote.require('electron-updater'); @@ -75,12 +76,23 @@ export function doDownloadUpgradeRequested() { return (dispatch, getState) => { const state = getState(); + const autoUpdateDeclined = selectAutoUpdateDeclined(state); if (['win32', 'darwin'].includes(process.platform)) { // electron-updater behavior - dispatch({ - type: ACTIONS.OPEN_MODAL, - data: { modal: MODALS.AUTO_UPDATE_CONFIRM }, - }); + if (autoUpdateDeclined) { + // The user declined an update before, so show the "confirm" dialog + dispatch({ + type: ACTIONS.OPEN_MODAL, + data: { modal: MODALS.AUTO_UPDATE_CONFIRM }, + }); + } else { + // The user was never shown the original update dialog (e.g. because they were + // watching a video). So show the inital "update downloaded" dialog. + dispatch({ + type: ACTIONS.OPEN_MODAL, + data: { modal: MODALS.AUTO_UPDATE_DOWNLOADED }, + }); + } } else { // Old behavior for Linux doDownloadUpgrade(); } @@ -140,6 +152,15 @@ export function doAutoUpdate() { }; } +export function doAutoUpdateDeclined() { + return function(dispatch, getState) { + const state = getState(); + dispatch({ + type: ACTIONS.AUTO_UPDATE_DECLINED, + }); + } +} + export function doCancelUpgrade() { return (dispatch, getState) => { const state = getState(); diff --git a/src/renderer/redux/reducers/app.js b/src/renderer/redux/reducers/app.js index 7e478597d..f1899a021 100644 --- a/src/renderer/redux/reducers/app.js +++ b/src/renderer/redux/reducers/app.js @@ -26,6 +26,8 @@ export type AppState = { hasSignature: boolean, badgeNumber: number, volume: number, + autoUpdateDeclined: boolean, + modalsAllowed: boolean, downloadProgress: ?number, upgradeDownloading: ?boolean, upgradeDownloadComplete: ?boolean, @@ -47,6 +49,8 @@ const defaultState: AppState = { badgeNumber: 0, volume: Number(sessionStorage.getItem('volume')) || 1, autoUpdateDownloaded: false, + autoUpdateDeclined: false, + modalsAllowed: true, downloadProgress: undefined, upgradeDownloading: undefined, @@ -85,6 +89,13 @@ reducers[ACTIONS.AUTO_UPDATE_DOWNLOADED] = state => autoUpdateDownloaded: true, }); +reducers[ACTIONS.AUTO_UPDATE_DECLINED] = state => { + console.log('in AUTO_UPDATE_DECLINED reducer') + return Object.assign({}, state, { + autoUpdateDeclined: true, + }); +} + reducers[ACTIONS.UPGRADE_DOWNLOAD_COMPLETED] = (state, action) => Object.assign({}, state, { downloadPath: action.data.path, @@ -97,6 +108,11 @@ reducers[ACTIONS.UPGRADE_DOWNLOAD_STARTED] = state => upgradeDownloading: true, }); +reducers[ACTIONS.CHANGE_MODALS_ALLOWED] = (state, action) => + Object.assign({}, state, { + modalsAllowed: action.data.modalsAllowed, + }); + reducers[ACTIONS.SKIP_UPGRADE] = state => { sessionStorage.setItem('upgradeSkipped', 'true'); @@ -106,6 +122,28 @@ reducers[ACTIONS.SKIP_UPGRADE] = state => { }); }; +reducers[ACTIONS.MEDIA_PLAY] = state => { + return Object.assign({}, state, { + modalsAllowed: false, + }); +}; + +reducers[ACTIONS.MEDIA_PAUSE] = state => { + return Object.assign({}, state, { + modalsAllowed: true, + }); +}; + +reducers[ACTIONS.SET_PLAYING_URI] = (state, action) => { + if (action.data.uri === null) { + return Object.assign({}, state, { + modalsAllowed: true, + }); + } else { + return state; + } +}; + reducers[ACTIONS.UPDATE_VERSION] = (state, action) => Object.assign({}, state, { version: action.data.version, @@ -122,12 +160,16 @@ reducers[ACTIONS.CHECK_UPGRADE_SUBSCRIBE] = (state, action) => checkUpgradeTimer: action.data.checkUpgradeTimer, }); -reducers[ACTIONS.OPEN_MODAL] = (state, action) => - Object.assign({}, state, { - modal: action.data.modal, - modalProps: action.data.modalProps || {}, - }); - +reducers[ACTIONS.OPEN_MODAL] = (state, action) => { + if (!state.modalsAllowed) { + return state; + } else { + return Object.assign({}, state, { + modal: action.data.modal, + modalProps: action.data.modalProps || {}, + }); + } +}; reducers[ACTIONS.CLOSE_MODAL] = state => Object.assign({}, state, { modal: undefined, diff --git a/src/renderer/redux/selectors/app.js b/src/renderer/redux/selectors/app.js index 04c04baa9..283e46f51 100644 --- a/src/renderer/redux/selectors/app.js +++ b/src/renderer/redux/selectors/app.js @@ -58,6 +58,10 @@ export const selectUpgradeDownloadItem = createSelector(selectState, state => st export const selectAutoUpdateDownloaded = createSelector(selectState, state => state.autoUpdateDownloaded); +export const selectAutoUpdateDeclined = createSelector(selectState, state => state.autoUpdateDeclined); + +export const selectModalsAllowed = createSelector(selectState, state => state.modalsAllowed); + export const selectModalProps = createSelector(selectState, state => state.modalProps); export const selectDaemonVersionMatched = createSelector(