diff --git a/src/App.js b/src/App.js index a14639d..b7ba90d 100644 --- a/src/App.js +++ b/src/App.js @@ -16,6 +16,7 @@ import Text from './components/UI/Text/Text'; import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon'; import UpgradeUI from './components/UpgradeUI/UpgradeUI'; import IPCContainer from './containers/IPCContainer/IPCContainer'; +import {detectUIUpgrade, setDismissUIUpgrade} from './redux/actions/release_version_actions'; const Constants = require('./constants'); const Scheduler = require('node-schedule'); @@ -38,7 +39,6 @@ class App extends IPCContainer { this.setRequestHandler(Constants.IPC_Extract_Release_Complete, this.onExtractReleaseComplete); this.setRequestHandler(Constants.IPC_Get_State_Reply, this.onGetStateReply); this.setRequestHandler(Constants.IPC_Grab_Releases_Reply, this.onGrabReleasesReply); - this.setRequestHandler(Constants.IPC_Grab_UI_Releases_Reply, this.onGrabUiReleasesReply); this.setRequestHandler(Constants.IPC_Install_Dependency_Reply, this.onInstallDependencyReply); this.setRequestHandler(Constants.IPC_Install_Upgrade_Reply, this.onInstallUpgradeReply); @@ -63,16 +63,7 @@ class App extends IPCContainer { LocationsLookup: {}, MissingDependencies: [], Release: 2, - ReleaseTypes: [ - 'Release', - 'RC', - 'Beta', - 'Alpha', - ], InstalledVersion: 'none', - UpgradeAvailable: false, - UpgradeData: {}, - UpgradeDismissed: false, Version: -1, VersionAvailable: false, VersionLookup: { @@ -149,13 +140,13 @@ class App extends IPCContainer { }; getSelectedVersion = () => { - return this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version]; + return this.state.VersionLookup[Constants.RELEASE_TYPES[this.state.Release]][this.state.Version]; }; grabReleases = () => { if (this.props.AppPlatform !== 'unknown') { this.sendRequest(Constants.IPC_Grab_Releases); - this.sendRequest(Constants.IPC_Grab_UI_Releases); + this.props.detectUIUpgrade(); } }; @@ -210,7 +201,7 @@ class App extends IPCContainer { handleReleaseChanged = (e) => { const val = parseInt(e.target.value, 10); - const versionIndex = this.state.VersionLookup[this.state.ReleaseTypes[val]].length - 1; + const versionIndex = this.state.VersionLookup[Constants.RELEASE_TYPES[val]].length - 1; this.setState({ Release: val, Version: versionIndex @@ -241,7 +232,7 @@ class App extends IPCContainer { DownloadingUpgrade: true, DownloadName: 'UI Upgrade', }, ()=> { - const url = this.state.UpgradeData.urls[0]; + const url = this.props.UpgradeData.urls[0]; this.sendRequest(Constants.IPC_Download_File, { Filename: this.props.Platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url), URL: url, @@ -300,7 +291,7 @@ class App extends IPCContainer { let versionAvailable = false; if (installedVersion !== 'none') { - const latestVersion = this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1; + const latestVersion = this.state.VersionLookup[Constants.RELEASE_TYPES[this.state.Release]].length - 1; let version = this.state.Version; if (version === -1) { version = latestVersion; @@ -386,9 +377,9 @@ class App extends IPCContainer { onGrabReleasesReply = ()=> { const doUpdate = (locationsLookup, versionLookup) => { - const latestVersion = versionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1; + const latestVersion = versionLookup[Constants.RELEASE_TYPES[this.state.Release]].length - 1; let version = this.state.Version; - if ((version === -1) || !versionLookup[this.state.ReleaseTypes[this.state.Release]][version]) { + if ((version === -1) || !versionLookup[Constants.RELEASE_TYPES[this.state.Release]][version]) { version = latestVersion; this.saveState(version); } @@ -437,29 +428,6 @@ class App extends IPCContainer { }); }; - onGrabUiReleasesReply = ()=> { - axios - .get(Constants.UI_RELEASES_URL) - .then(response => { - const data = response.data; - if (data.Versions && - data.Versions[this.props.AppPlatform] && - (data.Versions[this.props.AppPlatform].length > 0) && - (data.Versions[this.props.AppPlatform][0] !== this.props.version)) { - this.setState({ - UpgradeAvailable: true, - UpgradeDismissed: false, - UpgradeData: data.Locations[this.props.AppPlatform][data.Versions[this.props.AppPlatform][0]], - }); - } - }).catch(() => { - this.setState({ - UpgradeAvailable: false, - UpgradeData: {}, - }); - }); - }; - onInstallDependencyReply = (event, arg) => { if (arg.data.Success && arg.data.Source.toLowerCase().endsWith('.dmg')) { this.waitForDependencyInstall(arg.data.URL); @@ -572,11 +540,11 @@ class App extends IPCContainer { this.props.DisplayConfiguration && allowConfig; - const showUpgrade = this.state.UpgradeAvailable && + const showUpgrade = this.props.UpgradeAvailable && !this.state.DisplayError && !showConfig && !this.state.DownloadActive && - !this.state.UpgradeDismissed; + !this.props.UpgradeDismissed; const showDependencies = !showUpgrade && missingDependencies && @@ -628,8 +596,7 @@ class App extends IPCContainer { if (showUpgrade) { upgradeDisplay = ( - this.setState({UpgradeDismissed: true})} - upgrade={this.handleUIDownload}/> + ); } @@ -647,11 +614,10 @@ class App extends IPCContainer { release={this.state.Release} releaseChanged={this.handleReleaseChanged} releaseExtracting={this.state.ExtractActive} - releaseTypes={this.state.ReleaseTypes} version={this.state.Version} versionAvailable={this.state.VersionAvailable} versionChanged={this.handleVersionChanged} - versions={this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]]}/> + versions={this.state.VersionLookup[Constants.RELEASE_TYPES[this.state.Release]]}/> )); @@ -694,12 +660,12 @@ class App extends IPCContainer { colSpan={'remain'} row={0} rowSpan={'remain'} - text={'Repertory UI v' + this.props.version} + text={'Repertory UI v' + this.props.Version} textAlign={'center'} type={'Heading1'}/> this.setState({UpgradeDismissed: false})} + available={this.props.UpgradeAvailable} + clicked={()=>this.props.setDismissUIUpgrade(false)} col={dimensions => dimensions.columns - 6} colSpan={5} row={1} @@ -724,7 +690,18 @@ const mapStateToProps = state => { DisplayConfiguration: state.mounts.DisplayConfiguration, MountsBusy: state.mounts.MountsBusy, Platform: state.common.Platform, + UpgradeAvailable: state.relver.UpgradeAvailable, + UpgradeData: state.relver.UpgradeData, + UpgradeDismissed: state.relver.UpgradeDismissed, + Version: state.common.Version, }; }; -export default connect(mapStateToProps)(App); +const mapDispatchToProps = dispatch => { + return { + detectUIUpgrade: () => dispatch(detectUIUpgrade()), + setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)), + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(App); diff --git a/src/components/ReleaseVersionDisplay/ReleaseVersionDisplay.js b/src/components/ReleaseVersionDisplay/ReleaseVersionDisplay.js index c1fd0c9..0992e4a 100644 --- a/src/components/ReleaseVersionDisplay/ReleaseVersionDisplay.js +++ b/src/components/ReleaseVersionDisplay/ReleaseVersionDisplay.js @@ -1,5 +1,6 @@ import React from 'react'; import './ReleaseVersionDisplay.css'; +import * as Constants from '../../constants'; import DropDown from '../UI/DropDown/DropDown'; import Grid from '../UI/Grid/Grid'; import Text from '../UI/Text/Text'; @@ -70,7 +71,7 @@ export default props => { remain / 3 - 1} disabled={props.disabled} - items={props.releaseTypes} + items={Constants.RELEASE_TYPES} row={5} rowSpan={7} selected={props.release}/> diff --git a/src/components/UpgradeUI/UpgradeUI.js b/src/components/UpgradeUI/UpgradeUI.js index f143a17..f6b0325 100644 --- a/src/components/UpgradeUI/UpgradeUI.js +++ b/src/components/UpgradeUI/UpgradeUI.js @@ -1,9 +1,17 @@ +import {connect} from 'react-redux'; import Button from '../UI/Button/Button'; import Box from '../UI/Box/Box'; import React from 'react'; import './UpgradeUI.css'; +import {setDismissUIUpgrade} from '../../redux/actions/release_version_actions'; -export default props => { +const mapDispatchToProps = dispatch => { + return { + setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)), + }; +}; + +export default connect(null, mapDispatchToProps)(props => { return (
@@ -18,10 +26,10 @@ export default props => { + clicked={() => props.setDismissUIUpgrade(true)}>Cancel ); -}; \ No newline at end of file +}); \ No newline at end of file diff --git a/src/constants.js b/src/constants.js index de7603d..dabe650 100644 --- a/src/constants.js +++ b/src/constants.js @@ -58,6 +58,13 @@ exports.PROVIDER_ARG = { siaprime: '-sp' }; +exports.RELEASE_TYPES = [ + 'Release', + 'RC', + 'Beta', + 'Alpha', +]; + exports.IPC_Browse_Directory = 'browse_directory'; exports.IPC_Check_Daemon_Version = 'check_daemon_version'; @@ -98,9 +105,6 @@ exports.IPC_Get_State_Reply = 'get_state_reply'; exports.IPC_Grab_Releases = 'grab_releases'; exports.IPC_Grab_Releases_Reply = 'grab_releases_reply'; -exports.IPC_Grab_UI_Releases = 'grab_ui_releases'; -exports.IPC_Grab_UI_Releases_Reply = 'grab_ui_releases_reply'; - exports.IPC_Install_Dependency = 'install_dependency'; exports.IPC_Install_Dependency_Reply = 'install_dependency_reply'; diff --git a/src/index.js b/src/index.js index 24b4d61..b0a33b7 100644 --- a/src/index.js +++ b/src/index.js @@ -18,10 +18,10 @@ if (!process.versions.hasOwnProperty('electron')) { root.style.setProperty('--default_font_size', '15px'); } - const store = createAppStore(arg.Platform, arg.AppPlatform); + const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version); ReactDOM.render(( - + ), document.getElementById('root')); serviceWorker.unregister(); diff --git a/src/redux/actions/release_version_actions.js b/src/redux/actions/release_version_actions.js new file mode 100644 index 0000000..cac2990 --- /dev/null +++ b/src/redux/actions/release_version_actions.js @@ -0,0 +1,50 @@ +import axios from 'axios'; +import * as Constants from '../../constants'; +import {createAction} from 'redux-starter-kit'; + +export const CLEAR_UI_UPGRADE = 'relver/clearUIUpgrade'; +export const clearUIUpgrade = () => { + return { + type: CLEAR_UI_UPGRADE, + payload: null, + }; +}; + +export const detectUIUpgrade = () => { + return (dispatch, getState) => { + axios + .get(Constants.UI_RELEASES_URL) + .then(response => { + const state = getState(); + const appPlatform = state.common.AppPlatform; + const version = state.common.Version; + const data = response.data; + + if (data.Versions && + data.Versions[appPlatform] && + (data.Versions[appPlatform].length > 0) && + (data.Versions[appPlatform][0] !== version)) { + dispatch(setUIUpgradeData(data.Locations[appPlatform][data.Versions[appPlatform][0]])); + } else { + dispatch(clearUIUpgrade()); + } + }).catch(() => { + dispatch(clearUIUpgrade()); + //TODO Display error + }); + }; +}; + +export const SET_ACTIVE_RELEASE = 'relver/setActiveRelease'; +export const setActiveRelease = (release, version) => { + return { + type: SET_ACTIVE_RELEASE, + payload: { + release, + version + } + }; +}; + +export const setDismissUIUpgrade = createAction('relver/setDismissUIUpgrade'); +export const setUIUpgradeData = createAction('relver/setUIUpgradeData'); \ No newline at end of file diff --git a/src/redux/reducers/release_version_reducer.js b/src/redux/reducers/release_version_reducer.js new file mode 100644 index 0000000..b6e715c --- /dev/null +++ b/src/redux/reducers/release_version_reducer.js @@ -0,0 +1,53 @@ +import {createReducer} from 'redux-starter-kit'; +import * as Actions from '../actions/release_version_actions'; +import * as Constants from '../../constants'; + +const versionLookup = Constants.RELEASE_TYPES.map(k=> { + return { + [k]: ['unavailable'] + }; +}).reduce((map, obj) => { + return { + ...map, + ...obj, + }; +}); + +export const releaseVersionReducer = createReducer({ + LocationsLookup: {}, + Release: 2, + UpgradeAvailable: false, + UpgradeDismissed: false, + Version: -1, + VersionLookup: versionLookup, +}, { + [Actions.CLEAR_UI_UPGRADE]: state => { + return { + ...state, + UpgradeAvailable: false, + UpgradeDismissed: false, + UpgradeData: null, + }; + }, + [Actions.SET_ACTIVE_RELEASE]: (state, action) => { + return { + ...state, + Release: action.payload.release, + Version: action.payload.version + }; + }, + [Actions.setDismissUIUpgrade]: (state, action) => { + return { + ...state, + UpgradeDismissed: action.payload, + }; + }, + [Actions.setUIUpgradeData]: (state, action) => { + return { + ...state, + UpgradeAvailable: true, + UpgradeData: action.payload, + UpgradeDismissed: false, + }; + } +}); \ No newline at end of file diff --git a/src/redux/store/createAppStore.js b/src/redux/store/createAppStore.js index d663cef..6793173 100644 --- a/src/redux/store/createAppStore.js +++ b/src/redux/store/createAppStore.js @@ -1,17 +1,20 @@ import {configureStore, createReducer, getDefaultMiddleware} from 'redux-starter-kit'; import {mountReducer} from '../reducers/mount_reducer'; +import {releaseVersionReducer} from '../reducers/release_version_reducer'; -export default function createAppStore(platform, appPlatform) { +export default function createAppStore(platform, appPlatform, version) { const createCommonReducer = () => { return createReducer({ AppPlatform: appPlatform, Platform: platform, + Version: version, }, {}); }; const reducer = { - common: createCommonReducer(platform, appPlatform), + common: createCommonReducer(platform, appPlatform, version), mounts: mountReducer, + relver: releaseVersionReducer, }; const middleware = [...getDefaultMiddleware()];