Initial commit
This commit is contained in:
4
src/containers/MountItems/MountItems.css
Normal file
4
src/containers/MountItems/MountItems.css
Normal file
@@ -0,0 +1,4 @@
|
||||
.MountItems {
|
||||
margin-top: 10px;
|
||||
width: 100%;
|
||||
}
|
||||
184
src/containers/MountItems/MountItems.js
Normal file
184
src/containers/MountItems/MountItems.js
Normal file
@@ -0,0 +1,184 @@
|
||||
import React from 'react';
|
||||
import {Component} from 'react';
|
||||
import CSSModules from 'react-css-modules';
|
||||
import styles from './MountItems.css';
|
||||
import MountItem from '../../components/MountItem/MountItem';
|
||||
|
||||
let ipcRenderer = null;
|
||||
if (!process.versions.hasOwnProperty('electron')) {
|
||||
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
|
||||
}
|
||||
|
||||
class MountItems extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
if (ipcRenderer) {
|
||||
ipcRenderer.on('detect_mounts_reply', (event, arg) => {
|
||||
if (arg.data.Success) {
|
||||
const sia = {
|
||||
...this.state.Sia,
|
||||
AllowMount: true,
|
||||
DriveLetters: (arg.data.DriveLetters.Sia),
|
||||
Mounted: (arg.data.Locations.Sia.length > 0),
|
||||
PID: arg.data.PIDS.Sia,
|
||||
};
|
||||
const hs = {
|
||||
...this.state.Hyperspace,
|
||||
AllowMount: true,
|
||||
DriveLetters: (arg.data.DriveLetters.Hyperspace),
|
||||
Mounted: (arg.data.Locations.Hyperspace.length > 0),
|
||||
PID: arg.data.PIDS.Hyperspace,
|
||||
};
|
||||
|
||||
this.setState({
|
||||
Hyperspace: hs,
|
||||
Sia: sia,
|
||||
});
|
||||
|
||||
let hsLocation = arg.data.Locations.Hyperspace;
|
||||
if ((hsLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
hsLocation = this.props.hyperspace.MountLocation || arg.data.DriveLetters.Hyperspace[0];
|
||||
}
|
||||
if (hsLocation !== this.props.hyperspace.MountLocation) {
|
||||
this.props.changed('Hyperspace', hsLocation);
|
||||
}
|
||||
|
||||
let siaLocation = arg.data.Locations.Sia;
|
||||
if ((siaLocation.length === 0) && (this.props.platform === 'win32')) {
|
||||
siaLocation = this.props.sia.MountLocation || arg.data.DriveLetters.Sia[0];
|
||||
}
|
||||
if (siaLocation !== this.props.sia.MountLocation) {
|
||||
this.props.changed('Sia', siaLocation);
|
||||
}
|
||||
|
||||
this.performAutoMount();
|
||||
}
|
||||
});
|
||||
|
||||
ipcRenderer.on('mount_drive_reply', (event, arg) => {
|
||||
const state = {
|
||||
...this.state[arg.data.StorageType],
|
||||
PID: arg.data.PID,
|
||||
Mounted: arg.data.Success,
|
||||
};
|
||||
this.setState({
|
||||
[arg.data.StorageType]: state,
|
||||
});
|
||||
|
||||
this.detectMounts();
|
||||
});
|
||||
|
||||
ipcRenderer.on('unmount_drive_reply', (event, arg) => {
|
||||
this.detectMounts();
|
||||
});
|
||||
|
||||
this.detectMounts();
|
||||
}
|
||||
}
|
||||
|
||||
state = {
|
||||
Hyperspace: {
|
||||
AllowMount: false,
|
||||
DriveLetters: [],
|
||||
Mounted: false,
|
||||
PID: -1,
|
||||
},
|
||||
Sia: {
|
||||
AllowMount: false,
|
||||
DriveLetters: [],
|
||||
Mounted: false,
|
||||
PID: -1,
|
||||
},
|
||||
};
|
||||
|
||||
detectMounts = ()=> {
|
||||
ipcRenderer.send('detect_mounts', {
|
||||
Directory: this.props.directory,
|
||||
Version: this.props.version,
|
||||
});
|
||||
};
|
||||
|
||||
handleMountLocationChanged = (systemType, value) => {
|
||||
if (this.props.platform === 'win32') {
|
||||
this.props.changed(systemType, this.state[systemType].DriveLetters[value]);
|
||||
}
|
||||
else {
|
||||
this.props.changed(systemType, value);
|
||||
}
|
||||
};
|
||||
|
||||
handleMountUnMount = (storageType, mount, location, pid) => {
|
||||
if (ipcRenderer) {
|
||||
const state = {
|
||||
...this.state[storageType],
|
||||
AllowMount: false,
|
||||
};
|
||||
this.setState({
|
||||
[storageType]: state,
|
||||
});
|
||||
|
||||
if (mount) {
|
||||
ipcRenderer.send('mount_drive', {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
} else {
|
||||
ipcRenderer.send('unmount_drive', {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
PID: pid,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
performAutoMount = ()=> {
|
||||
if (this.props.processAutoMount) {
|
||||
this.props.autoMountProcessed();
|
||||
if (this.props.hyperspace.AutoMount &&
|
||||
!this.state.Hyperspace.Mounted &&
|
||||
(this.props.hyperspace.MountLocation.length > 0)) {
|
||||
this.handleMountUnMount('Hyperspace', true, this.props.hyperspace.MountLocation);
|
||||
}
|
||||
if (this.props.sia.AutoMount &&
|
||||
!this.state.Sia.Mounted &&
|
||||
(this.props.sia.MountLocation.length > 0)) {
|
||||
this.handleMountUnMount('Sia', true, this.props.sia.MountLocation);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div styleName='MountItems'>
|
||||
<MountItem allowMount={this.state.Hyperspace.AllowMount}
|
||||
autoMount={this.props.hyperspace.AutoMount}
|
||||
autoMountChanged={(e)=>this.props.autoMountChanged('Hyperspace', e)}
|
||||
mounted={this.state.Hyperspace.Mounted}
|
||||
items={this.state.Hyperspace.DriveLetters}
|
||||
platform={this.props.platform}
|
||||
title={'Hyperspace'}
|
||||
location={this.props.hyperspace.MountLocation}
|
||||
changed={(e) => this.handleMountLocationChanged('Hyperspace', e.target.value)}
|
||||
clicked={this.handleMountUnMount}
|
||||
pid={this.state.Hyperspace.PID}/>
|
||||
<MountItem allowMount={this.state.Sia.AllowMount}
|
||||
autoMount={this.props.sia.AutoMount}
|
||||
autoMountChanged={(e)=>this.props.autoMountChanged('Sia', e)}
|
||||
mounted={this.state.Sia.Mounted}
|
||||
items={this.state.Sia.DriveLetters}
|
||||
platform={this.props.platform}
|
||||
title={'Sia'}
|
||||
location={this.props.sia.MountLocation}
|
||||
changed={(e) => this.handleMountLocationChanged('Sia', e.target.value)}
|
||||
clicked={this.handleMountUnMount}
|
||||
pid={this.state.Sia.PID}/>
|
||||
</div>);
|
||||
}
|
||||
}
|
||||
|
||||
export default CSSModules(MountItems, styles, {allowMultiple: true});
|
||||
Reference in New Issue
Block a user