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((