From 486b31fa0ec9872a18520d33fc0142f0e66fc090 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 6 Nov 2018 15:41:51 -0600 Subject: [PATCH] Auto-restart on unexpected failure --- electron.js | 14 ++++++ src/App.js | 60 +++++++++++++++++++++++-- src/components/MountItem/MountItem.js | 12 +++++ src/containers/MountItems/MountItems.js | 15 ++++++- 4 files changed, 96 insertions(+), 5 deletions(-) diff --git a/electron.js b/electron.js index 0a7a38b..24c3e51 100644 --- a/electron.js +++ b/electron.js @@ -18,6 +18,7 @@ let mainContextWindow; let mainWindow; let mainWindowTray; let mountedPIDs = []; +let expectedUnmount = {}; function createWindow() { // Create the browser window. @@ -260,6 +261,15 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { siaPrimeLocation = siaPrimeLocation.toUpperCase(); grabDriveLetters(hsLocation, siaLocation, siaPrimeLocation); } + if (results.Hyperspace.PID !== -1) { + expectedUnmount['Hyperspace'] = false; + } + if (results.Sia.PID !== -1) { + expectedUnmount['Sia'] = false; + } + if (results.SiaPrime.PID !== -1) { + expectedUnmount['SiaPrime'] = false; + } setImage(hsLocation, siaLocation, siaPrimeLocation); standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { DriveLetters: driveLetters, @@ -417,10 +427,13 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => { }); ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => { + expectedUnmount[data.StorageType] = false; const dataDirectory = helpers.resolvePath(data.Directory); const errorHandler = (pid, error) => { mountedPIDs.splice(mountedPIDs.indexOf(pid), 1); standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, { + Expected: expectedUnmount[data.StorageType], + Location: data.Location, PID: -1, StorageType: data.StorageType, }, error || Error(data.StorageType + ' Unmounted')); @@ -473,6 +486,7 @@ ipcMain.on(Constants.IPC_Shutdown, () => { }); ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => { + expectedUnmount[data.StorageType] = true; helpers .stopProcessByPID(data.PID) .then((pid)=> { diff --git a/src/App.js b/src/App.js index 6c6dc6b..d7339cf 100644 --- a/src/App.js +++ b/src/App.js @@ -62,6 +62,7 @@ class App extends Component { ExtractActive: false, Hyperspace: { AutoMount: false, + AutoRestart: false, MountLocation: '', }, LocationsLookup: {}, @@ -78,10 +79,12 @@ class App extends Component { InstalledVersion: 'none', Sia: { AutoMount: false, + AutoRestart: false, MountLocation: '', }, SiaPrime: { AutoMount: false, + AutoRestart: false, MountLocation: '', }, UpgradeAvailable: false, @@ -180,27 +183,68 @@ class App extends Component { ...this.state.Hyperspace }; - this.saveState(this.state.Release, this.state.Version, sia, hyperspace, siaPrime); - if (storageType === 'Hyperspace') { hyperspace.AutoMount = e.target.checked; this.setState({ Hyperspace: hyperspace, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); }); } else if (storageType === 'Sia') { sia.AutoMount = e.target.checked; this.setState({ Sia: sia, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); }); } else if (storageType === 'SiaPrime') { siaPrime.AutoMount = e.target.checked; this.setState({ SiaPrime: siaPrime, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); }); } }; + handleAutoRestartChanged = (storageType, e) => { + let sia = { + ...this.state.Sia + }; + + let siaPrime = { + ...this.state.SiaPrime + }; + + let hyperspace = { + ...this.state.Hyperspace + }; + + if (storageType === 'Hyperspace') { + hyperspace.AutoRestart = e.target.checked; + this.setState({ + Hyperspace: hyperspace, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); + }); + } else if (storageType === 'Sia') { + sia.AutoRestart = e.target.checked; + this.setState({ + Sia: sia, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); + }); + } else if (storageType === 'SiaPrime') { + siaPrime.AutoRestart = e.target.checked; + this.setState({ + SiaPrime: siaPrime, + }, ()=> { + this.saveState(this.state.Release, this.state.Version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); + }); + } + }; + handleConfigClicked = (storageType) => { this.setState({ ConfigStorageType: storageType, @@ -426,16 +470,25 @@ class App extends Component { if (hyperspace.AutoMount === undefined) { hyperspace['AutoMount'] = false; } + if (hyperspace.AutoRestart === undefined) { + hyperspace['AutoRestart'] = false; + } let sia = arg.data.Sia || this.state.Sia; if (sia.AutoMount === undefined) { sia['AutoMount'] = false; } + if (sia.AutoRestart === undefined) { + sia['AutoRestart'] = false; + } let siaPrime = arg.data.SiaPrime || this.state.SiaPrime; if (siaPrime.AutoMount === undefined) { siaPrime['AutoMount'] = false; } + if (siaPrime.AutoRestart === undefined) { + siaPrime['AutoRestart'] = false; + } this.setState({ Hyperspace: hyperspace, @@ -683,10 +736,11 @@ class App extends Component { if (allowMount) { mainContent.push((
+ style={{height: '69%'}}> { ); + const autoRestartControl = ( + + Restart + + ); + return ( {configButton} @@ -90,6 +101,7 @@ export default CSSModules((props) => { {inputControl} {actionsDisplay} {autoMountControl} + {autoRestartControl} ); }, styles, {allowMultiple: true}); \ No newline at end of file diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index dd3525e..10d0a96 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -177,7 +177,12 @@ class MountItems extends Component { }; onUnmountDriveReply = (event, arg) => { - this.detectMounts(); + console.log(arg); + if ((this.props.platform === 'win32') && arg && arg.data && !arg.data.Expected && arg.data.Location && this.props[arg.data.StorageType.toLowerCase()].AutoRestart) { + this.handleMountUnMount(arg.data.StorageType, true, arg.data.Location) + } else { + this.detectMounts(); + } }; performAutoMount = ()=> { @@ -208,6 +213,8 @@ class MountItems extends Component { allowMount={this.state.Hyperspace.AllowMount} autoMount={this.props.hyperspace.AutoMount} autoMountChanged={(e)=>this.props.autoMountChanged('Hyperspace', e)} + autoRestart={this.props.hyperspace.AutoRestart} + autoRestartChanged={(e)=>this.props.autoRestartChanged('Hyperspace', e)} changed={(e) => this.handleMountLocationChanged('Hyperspace', e.target.value)} clicked={this.handleMountUnMount} configClicked={()=>this.props.configClicked('Hyperspace')} @@ -222,6 +229,8 @@ class MountItems extends Component { allowMount={this.state.Sia.AllowMount} autoMount={this.props.sia.AutoMount} autoMountChanged={(e)=>this.props.autoMountChanged('Sia', e)} + autoRestart={this.props.sia.AutoRestart} + autoRestartChanged={(e)=>this.props.autoRestartChanged('Sia', e)} changed={(e) => this.handleMountLocationChanged('Sia', e.target.value)} clicked={this.handleMountUnMount} configClicked={()=>this.props.configClicked('Sia')} @@ -233,9 +242,11 @@ class MountItems extends Component { title={'Sia'}/>
this.props.autoMountChanged('SiaPrime', e)} + autoRestart={this.props.siaprime.AutoRestart} + autoRestartChanged={(e)=>this.props.autoRestartChanged('SiaPrime', e)} changed={(e) => this.handleMountLocationChanged('SiaPrime', e.target.value)} clicked={this.handleMountUnMount} configClicked={()=>this.props.configClicked('SiaPrime')}