From 21b50d48b5028240325d1afbb1bd4115d50c558c Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Sat, 3 Nov 2018 12:29:31 -0500 Subject: [PATCH] SiaPrime support --- electron.js | 32 +++++++++----- src/App.js | 56 ++++++++++++++++++------- src/containers/MountItems/MountItems.js | 41 ++++++++++++++++++ 3 files changed, 104 insertions(+), 25 deletions(-) diff --git a/electron.js b/electron.js index 1cbcd7b..7bb3c63 100644 --- a/electron.js +++ b/electron.js @@ -21,7 +21,7 @@ let mountedPIDs = []; function createWindow() { // Create the browser window. - const height = process.env.ELECTRON_START_URL ? 324 : 304; + const height = process.env.ELECTRON_START_URL ? 404 : 384; mainWindow = new BrowserWindow({ width: 425, height: height, @@ -191,16 +191,18 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { let driveLetters = { Hyperspace: [], Sia: [], + SiaPrime: [], }; - const grabDriveLetters = (hsLocation, siaLocation) => { + const grabDriveLetters = (hsLocation, siaLocation, siaPrimeLocation) => { for (let i = 'c'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) { const drive = (String.fromCharCode(i) + ':').toUpperCase(); - if (!(hsLocation.startsWith(drive) || siaLocation.startsWith(drive))) { + if (!(hsLocation.startsWith(drive) || siaLocation.startsWith(drive) || siaPrimeLocation.startsWith(drive))) { try { if (!fs.existsSync(drive)) { driveLetters.Hyperspace.push(drive); driveLetters.Sia.push(drive); + driveLetters.SiaPrime.push(drive); } } catch (e) { } @@ -222,17 +224,21 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { driveLetters.Sia.push(siaLocation); } } + + if (siaPrimeLocation.length > 0) { + if (!driveLetters.SiaPrime.find((driveLetter) => { + return driveLetter === siaPrimeLocation; + })) { + driveLetters.SiaPrime.push(siaPrimeLocation); + } + } }; - const setImage = (hsLocation, siaLocation) => { + const setImage = (hsLocation, siaLocation, siaPrimeLocation) => { if (os.platform() === 'win32') { let image; - if ((siaLocation.length > 0) && (hsLocation.length > 0)) { + if ((siaLocation.length > 0) || (hsLocation.length > 0) || (siaPrimeLocation.length > 0)) { image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_both.png')); - } else if (hsLocation.length > 0) { - image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_hs.png')); - } else if (siaLocation.length > 0) { - image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_sia.png')); } else { image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png')); } @@ -247,21 +253,25 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { .then((results) => { let hsLocation = results.Hyperspace.Location; let siaLocation = results.Sia.Location; + let siaPrimeLocation = results.SiaPrime.Location; if (os.platform() === 'win32') { hsLocation = hsLocation.toUpperCase(); siaLocation = siaLocation.toUpperCase(); - grabDriveLetters(hsLocation, siaLocation); + siaPrimeLocation = siaPrimeLocation.toUpperCase(); + grabDriveLetters(hsLocation, siaLocation, siaPrimeLocation); } - setImage(hsLocation, siaLocation); + setImage(hsLocation, siaLocation, siaPrimeLocation); standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { DriveLetters: driveLetters, Locations: { Hyperspace: hsLocation, Sia: siaLocation, + SiaPrime: siaPrimeLocation, }, PIDS: { Hyperspace: results.Hyperspace.PID, Sia: results.Sia.PID, + SiaPrime: results.SiaPrime.PID, } }); }) diff --git a/src/App.js b/src/App.js index 06fded1..cb6a73b 100644 --- a/src/App.js +++ b/src/App.js @@ -80,6 +80,10 @@ class App extends Component { AutoMount: false, MountLocation: '', }, + SiaPrime: { + AutoMount: false, + MountLocation: '', + }, UpgradeAvailable: false, UpgradeData: {}, UpgradeDismissed: false, @@ -168,11 +172,15 @@ class App extends Component { ...this.state.Sia }; + let siaPrime = { + ...this.state.SiaPrime + }; + let hyperspace = { ...this.state.Hyperspace }; - this.saveState(this.state.Release, this.state.Version, sia, hyperspace); + this.saveState(this.state.Release, this.state.Version, sia, hyperspace, siaPrime); if (storageType === 'Hyperspace') { hyperspace.AutoMount = e.target.checked; @@ -184,6 +192,11 @@ class App extends Component { this.setState({ Sia: sia, }); + } else if (storageType === 'SiaPrime') { + siaPrime.AutoMount = e.target.checked; + this.setState({ + SiaPrime: siaPrime, + }); } }; @@ -230,8 +243,11 @@ class App extends Component { const sia = storageType === 'Sia' ? state : { ...this.state.Sia, }; + const siaPrime = storageType === 'SiaPrime' ? state : { + ...this.state.SiaPrime, + }; - this.saveState(this.state.Release, this.state.Version, sia, hyperspace); + this.saveState(this.state.Release, this.state.Version, sia, hyperspace, siaPrime); this.setState({ [storageType]: state, }); @@ -240,7 +256,7 @@ class App extends Component { handleReleaseChanged = (e) => { const val = parseInt(e.target.value, 10); const versionIndex = this.state.VersionLookup[this.state.ReleaseTypes[val]].length - 1; - this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace); + this.saveState(val, versionIndex, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); this.setState({ Release: val, Version: versionIndex @@ -287,7 +303,7 @@ class App extends Component { handleVersionChanged = (e) => { const val = parseInt(e.target.value, 10); - this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace); + this.saveState(this.state.Release, val, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); this.setState({ Version: val }, ()=> { @@ -406,16 +422,26 @@ class App extends Component { onGetStateReply = (event, arg) => { if (arg.data) { - if (arg.data.Hyperspace.AutoMount === undefined) { - arg.data.Hyperspace['AutoMount'] = false; + let hyperspace = arg.data.Hyperspace || this.state.Hyperspace; + if (hyperspace.AutoMount === undefined) { + hyperspace['AutoMount'] = false; } - if (arg.data.Sia.AutoMount === undefined) { - arg.data.Sia['AutoMount'] = false; + + let sia = arg.data.Sia || this.state.Sia; + if (sia.AutoMount === undefined) { + sia['AutoMount'] = false; } + + let siaPrime = arg.data.SiaPrime || this.state.SiaPrime; + if (siaPrime.AutoMount === undefined) { + siaPrime['AutoMount'] = false; + } + this.setState({ - Hyperspace: arg.data.Hyperspace, + Hyperspace: hyperspace, Release: arg.data.Release, - Sia: arg.data.Sia, + Sia: sia, + SiaPrime: siaPrime, Version: arg.data.Version, }, ()=> { this.grabReleases(); @@ -431,7 +457,7 @@ class App extends Component { let version = this.state.Version; if ((version === -1) || !versionLookup[this.state.ReleaseTypes[this.state.Release]][version]) { version = latestVersion; - this.saveState(this.state.Release, version, this.state.Sia, this.state.Hyperspace); + this.saveState(this.state.Release, version, this.state.Sia, this.state.Hyperspace, this.state.SiaPrime); } this.setState({ @@ -518,7 +544,7 @@ class App extends Component { }); }; - saveState = (release, version, sia, hyperspace)=> { + saveState = (release, version, sia, hyperspace, siaPrime)=> { if (ipcRenderer) { ipcRenderer.send(Constants.IPC_Save_State, { Directory: Constants.DATA_LOCATIONS[this.props.platform], @@ -526,6 +552,7 @@ class App extends Component { Hyperspace: hyperspace, Release: release, Sia: sia, + SiaPrime: siaPrime, Version: version, } }); @@ -637,7 +664,7 @@ class App extends Component { let key = 0; mainContent.push((
+ style={{height: '34%'}}> + style={{height: '28%'}}>
)); diff --git a/src/containers/MountItems/MountItems.js b/src/containers/MountItems/MountItems.js index f9c08e9..4af83ed 100644 --- a/src/containers/MountItems/MountItems.js +++ b/src/containers/MountItems/MountItems.js @@ -36,6 +36,12 @@ class MountItems extends Component { Mounted: false, PID: -1, }, + SiaPrime: { + AllowMount: false, + DriveLetters: [], + Mounted: false, + PID: -1, + }, }; componentWillUnmount = () => { @@ -104,6 +110,13 @@ class MountItems extends Component { Mounted: (arg.data.Locations.Sia.length > 0), PID: arg.data.PIDS.Sia, }; + const siaPrime = { + ...this.state.SiaPrime, + AllowMount: true, + DriveLetters: (arg.data.DriveLetters.SiaPrime), + Mounted: (arg.data.Locations.SiaPrime.length > 0), + PID: arg.data.PIDS.SiaPrime, + }; const hs = { ...this.state.Hyperspace, AllowMount: true, @@ -117,6 +130,7 @@ class MountItems extends Component { this.setState({ Hyperspace: hs, Sia: sia, + SiaPrime: siaPrime, }, () => { let hsLocation = arg.data.Locations.Hyperspace; if ((hsLocation.length === 0) && (this.props.platform === 'win32')) { @@ -134,6 +148,14 @@ class MountItems extends Component { this.props.changed('Sia', siaLocation); } + let siaPrimeLocation = arg.data.Locations.SiaPrime; + if ((siaPrimeLocation.length === 0) && (this.props.platform === 'win32')) { + siaPrimeLocation = this.props.siaprime.MountLocation || arg.data.DriveLetters.SiaPrime[0]; + } + if (siaPrimeLocation !== this.props.siaprime.MountLocation) { + this.props.changed('SiaPrime', siaPrimeLocation); + } + this.performAutoMount(); }); } else { @@ -171,6 +193,11 @@ class MountItems extends Component { (this.props.sia.MountLocation.length > 0)) { this.handleMountUnMount('Sia', true, this.props.sia.MountLocation); } + if (this.props.siaprime.AutoMount && + !this.state.SiaPrime.Mounted && + (this.props.siaprime.MountLocation.length > 0)) { + this.handleMountUnMount('SiaPrime', true, this.props.siaprime.MountLocation); + } } }; @@ -204,6 +231,20 @@ class MountItems extends Component { pid={this.state.Sia.PID} platform={this.props.platform} title={'Sia'}/> +
+ this.props.autoMountChanged('SiaPrime', e)} + changed={(e) => this.handleMountLocationChanged('SiaPrime', e.target.value)} + clicked={this.handleMountUnMount} + configClicked={()=>this.props.configClicked('SiaPrime')} + items={this.state.SiaPrime.DriveLetters} + location={this.props.siaprime.MountLocation} + mounted={this.state.SiaPrime.Mounted} + pid={this.state.SiaPrime.PID} + platform={this.props.platform} + title={'SiaPrime'}/>
); } }