From 37607bf1524a2188a3e980e85ab2428f03b459c0 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 24 Jul 2019 14:09:11 -0500 Subject: [PATCH] Handle release unavailable --- public/electron.js | 15 +++++++-- src/constants.js | 3 ++ src/redux/actions/mount_actions.js | 15 +++++++++ src/redux/actions/release_version_actions.js | 31 ++++++++++++++----- src/redux/reducers/release_version_reducer.js | 1 + 5 files changed, 56 insertions(+), 9 deletions(-) diff --git a/public/electron.js b/public/electron.js index d27c027..bf18446 100644 --- a/public/electron.js +++ b/public/electron.js @@ -72,6 +72,12 @@ function setWindowVisibility(show) { } const unmountAllDrives = () => { + // Reset mount states + for (const provider of Constants.PROVIDER_LIST) { + clearManualMountDetection(provider); + expectedUnmount[provider] = true; + } + // Unmount all items for (const i in mountedLocations) { const data = mountedData[mountedLocations[i]]; @@ -898,16 +904,21 @@ ipcMain.on(Constants.IPC_Show_Window + '_sync', event => { event.returnValue = true; }); +ipcMain.on(Constants.IPC_Unmount_All_Drives, (event, data) => { + unmountAllDrives(); + standardIPCReply(event, Constants.IPC_Unmount_All_Drives_Reply); +}); + ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => { clearManualMountDetection(data.Provider); expectedUnmount[data.Provider] = true; helpers .stopMountProcess(data.Version, data.Provider) - .then((result)=> { + .then(result => { console.log(result); }) - .catch((e) => { + .catch(e => { console.log(e); }); }); diff --git a/src/constants.js b/src/constants.js index b6cbc6a..e773a27 100644 --- a/src/constants.js +++ b/src/constants.js @@ -114,5 +114,8 @@ exports.IPC_Set_Config_Values_Reply = 'set_config_values_reply'; exports.IPC_Shutdown = 'shutdown'; +exports.IPC_Unmount_All_Drives = 'unmount_all'; +exports.IPC_Unmount_All_Drives_Reply = 'unmount_all_reply'; + exports.IPC_Unmount_Drive = 'unmount_drive'; exports.IPC_Unmount_Drive_Reply = 'unmount_drive_reply'; \ No newline at end of file diff --git a/src/redux/actions/mount_actions.js b/src/redux/actions/mount_actions.js index 37348a7..0539285 100644 --- a/src/redux/actions/mount_actions.js +++ b/src/redux/actions/mount_actions.js @@ -1,4 +1,6 @@ +import * as Constants from '../../constants'; import {createAction} from 'redux-starter-kit'; +import {getIPCRenderer} from '../../utils'; export const displayConfiguration = createAction('mounts/displayConfiguration'); @@ -9,6 +11,7 @@ export const resetMountsState = () => { payload: null, } }; + export const SET_ALLOW_MOUNT = 'mounts/setAllowMount'; export const setAllowMount = (provider, allow) => { return { @@ -54,4 +57,16 @@ export const setProviderState = (provider, state) => { state } } +}; + +export const unmountAll = completedCallback => { + return (dispatch, getState) => { + const ipcRenderer = getIPCRenderer(); + const unmountedCallback = () => { + dispatch(resetMountsState()); + completedCallback(); + }; + ipcRenderer.once(Constants.IPC_Unmount_All_Drives_Reply, unmountedCallback); + ipcRenderer.send(Constants.IPC_Unmount_All_Drives); + } }; \ No newline at end of file diff --git a/src/redux/actions/release_version_actions.js b/src/redux/actions/release_version_actions.js index a9bf704..ffc785c 100644 --- a/src/redux/actions/release_version_actions.js +++ b/src/redux/actions/release_version_actions.js @@ -3,9 +3,11 @@ import * as Constants from '../../constants'; import {createAction} from 'redux-starter-kit'; import {notifyError} from './error_actions'; import { + saveState, setApplicationReady, showWindow } from './common_actions'; +import {unmountAll} from './mount_actions'; export const CLEAR_UI_UPGRADE = 'relver/clearUIUpgrade'; export const clearUIUpgrade = () => { @@ -47,19 +49,34 @@ export const loadReleases = () => { return (dispatch, getState) => { const dispatchActions = (locationsLookup, versionLookup)=> { const state = getState().relver; - const latestVersion = versionLookup[Constants.RELEASE_TYPES[state.Release]].length - 1; + let latestVersion = versionLookup[Constants.RELEASE_TYPES[state.Release]].length - 1; + let release = state.Release; let version = state.Version; - if ((version === -1) || !versionLookup[Constants.RELEASE_TYPES[state.Release]][version]) { + if (versionLookup[Constants.RELEASE_TYPES[release]][0] === 'unavailable') { + release = state.ReleaseDefault; + latestVersion = version = 0; + } else if ((version === -1) || !versionLookup[Constants.RELEASE_TYPES[state.Release]][version]) { version = latestVersion; } dispatch(setReleaseData(locationsLookup, versionLookup)); - if (version !== state.Version) { - dispatch(setActiveRelease(state.Release, version)); + + const dispatchActions = () => { + dispatch(setReleaseUpgradeAvailable((version !== latestVersion))); + dispatch(setApplicationReady(true)); + dispatch(detectUIUpgrade()); + }; + + if ((version !== state.Version) || (release !== state.Release)) { + dispatch(unmountAll(() => { + dispatch(setActiveRelease(release, version)); + dispatchActions(); + dispatch(showWindow()); + dispatch(saveState()); + })); + } else { + dispatchActions(); } - dispatch(setReleaseUpgradeAvailable((version !== latestVersion))); - dispatch(setApplicationReady(true)); - dispatch(detectUIUpgrade()); }; axios diff --git a/src/redux/reducers/release_version_reducer.js b/src/redux/reducers/release_version_reducer.js index d0e3e4d..f106fa0 100644 --- a/src/redux/reducers/release_version_reducer.js +++ b/src/redux/reducers/release_version_reducer.js @@ -17,6 +17,7 @@ export const releaseVersionReducer = createReducer({ InstalledVersion: 'none', LocationsLookup: {}, Release: 0, + ReleaseDefault: 0, ReleaseUpgradeAvailable: false, UpgradeAvailable: false, UpgradeData: null,