Added unmount

This commit is contained in:
Scott E. Graves
2018-12-10 00:04:18 -06:00
parent af836c305c
commit 61b2f6e6f6
4 changed files with 24 additions and 44 deletions

View File

@@ -17,7 +17,7 @@ const AutoLaunch = require('auto-launch');
let trayContextMenu; let trayContextMenu;
let mainWindow; let mainWindow;
let mainWindowTray; let mainWindowTray;
let mountedPIDs = {}; let mountedData = {};
let mountedLocations = []; let mountedLocations = [];
let expectedUnmount = {}; let expectedUnmount = {};
let launchHidden = false; let launchHidden = false;
@@ -64,10 +64,11 @@ function createWindow() {
// Unmount all items // Unmount all items
for (const i in mountedLocations) { for (const i in mountedLocations) {
helpers.stopMountProcess(mountedPIDs[mountedLocations[i]], mountedLocations[i]); const data = mountedData[mountedLocations[i]];
helpers.stopMountProcess(data.DataDirectory, data.Version, data.StorageType);
} }
mountedLocations = []; mountedLocations = [];
mountedPIDs = {}; mountedData = {};
}); });
if ((os.platform() === 'win32') || (os.platform() === 'linux')) { if ((os.platform() === 'win32') || (os.platform() === 'linux')) {
@@ -363,11 +364,6 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
Hyperspace: hsLocation, Hyperspace: hsLocation,
Sia: siaLocation, Sia: siaLocation,
SiaPrime: siaPrimeLocation, SiaPrime: siaPrimeLocation,
},
PIDS: {
Hyperspace: results.Hyperspace.PID,
Sia: results.Sia.PID,
SiaPrime: results.SiaPrime.PID,
} }
}); });
}) })
@@ -539,17 +535,20 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
console.log(data.StorageType + ' already mounted: ' + data.Location); console.log(data.StorageType + ' already mounted: ' + data.Location);
} else { } else {
mountedLocations.push(data.Location); mountedLocations.push(data.Location);
mountedPIDs[data.Location] = -1; mountedData[data.Location] = {
DataDirectory: dataDirectory,
Version: data.Version,
StorageType: data.StorageType,
};
const errorHandler = (pid, error) => { const errorHandler = (pid, error) => {
if (mountedLocations.indexOf(data.Location) !== -1) { if (mountedLocations.indexOf(data.Location) !== -1) {
mountedLocations.splice(mountedLocations.indexOf(data.Location), 1); mountedLocations.splice(mountedLocations.indexOf(data.Location), 1);
delete mountedPIDs[data.Location]; delete mountedData[data.Location];
} }
standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, { standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, {
Expected: expectedUnmount[data.StorageType], Expected: expectedUnmount[data.StorageType],
Location: data.Location, Location: data.Location,
PID: -1,
StorageType: data.StorageType, StorageType: data.StorageType,
}, error || Error(data.StorageType + ' Unmounted')); }, error || Error(data.StorageType + ' Unmounted'));
}; };
@@ -557,12 +556,8 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => { .executeMount(dataDirectory, data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
errorHandler(pid, error); errorHandler(pid, error);
}) })
.then(pid => { .then(() => {
if (pid !== -1) {
mountedPIDs[data.Location] = pid;
}
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, { standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
PID: pid,
StorageType: data.StorageType, StorageType: data.StorageType,
}); });
}) })
@@ -603,9 +598,10 @@ ipcMain.on(Constants.IPC_Shutdown, () => {
}); });
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => { ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
expectedUnmount[data.StorageType] = true; expectedUnmount[data.StorageType] = true;
helpers helpers
.stopMountProcess(data.PID, data.Location) .stopMountProcess(dataDirectory, data.Version, data.StorageType)
.then((result)=> { .then((result)=> {
console.log(result); console.log(result);
}) })

View File

@@ -159,7 +159,7 @@ module.exports.executeAsync = (command, args=[]) => {
module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => { module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => {
return new Promise((resolve) => { return new Promise((resolve) => {
const processOptions = { const processOptions = {
detached: os.platform() === 'win32', detached: false,
shell: true, shell: true,
stdio: 'ignore', stdio: 'ignore',
}; };
@@ -199,9 +199,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
exitCallback(code, pid); exitCallback(code, pid);
}); });
if (os.platform() === 'win32') { process.unref();
process.unref();
}
}); });
}; };
@@ -443,31 +441,22 @@ module.exports.setConfigValue = (name, value, directory, storageType, version) =
}); });
}; };
module.exports.stopMountProcess = (pid, location) => { module.exports.stopMountProcess = (directory, version, storageType) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const processOptions = { const processOptions = {
detached: true, detached: false,
shell: true, shell: true,
windowsHide: true, windowsHide: true,
}; };
let procName = 'kill'; const command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
if (location && location.length > 0) { const args = ['-unmount'];
procName = 'fusermount'; if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
} args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
const command = (os.platform() === 'win32') ? 'taskkill.exe' : procName;
const args = [];
if (os.platform() === 'win32') {
args.push('/PID');
}
if (procName === 'fusermount') {
args.push('-u');
args.push(location);
} else {
args.push(pid);
} }
const process = new spawn(command, args, processOptions); const process = new spawn(command, args, processOptions);
const pid = process.pid;
process.on('error', (err) => { process.on('error', (err) => {
reject(err); reject(err);
}); });

View File

@@ -60,7 +60,7 @@ export default CSSModules((props) => {
width='19px'/>; width='19px'/>;
const actionsDisplay = ( const actionsDisplay = (
<Button clicked={()=>props.clicked(props.title, !props.mounted, props.location, props.pid)} <Button clicked={()=>props.clicked(props.title, !props.mounted, props.location)}
col={inputColumnSpan + 2} col={inputColumnSpan + 2}
colSpan={21} colSpan={21}
disabled={!props.allowMount || props.disabled} disabled={!props.allowMount || props.disabled}

View File

@@ -19,7 +19,6 @@ class MountItems extends Component {
AllowMount: false, AllowMount: false,
DriveLetters: [], DriveLetters: [],
Mounted: false, Mounted: false,
PID: -1,
}; };
} }
if (ipcRenderer) { if (ipcRenderer) {
@@ -58,7 +57,7 @@ class MountItems extends Component {
} }
}; };
handleMountUnMount = (storageType, mount, location, pid) => { handleMountUnMount = (storageType, mount, location) => {
if (ipcRenderer) { if (ipcRenderer) {
const state = { const state = {
...this.state[storageType], ...this.state[storageType],
@@ -82,7 +81,6 @@ class MountItems extends Component {
ipcRenderer.send(Constants.IPC_Unmount_Drive, { ipcRenderer.send(Constants.IPC_Unmount_Drive, {
Directory: this.props.directory, Directory: this.props.directory,
Location: location, Location: location,
PID: pid,
StorageType: storageType, StorageType: storageType,
Version: this.props.version, Version: this.props.version,
}); });
@@ -101,7 +99,6 @@ class MountItems extends Component {
AllowMount: true, AllowMount: true,
DriveLetters: (arg.data.DriveLetters[provider]), DriveLetters: (arg.data.DriveLetters[provider]),
Mounted: (arg.data.Locations[provider].length > 0), Mounted: (arg.data.Locations[provider].length > 0),
PID: arg.data.PIDS[provider],
}; };
mountsBusy = mountsBusy || state[provider].Mounted; mountsBusy = mountsBusy || state[provider].Mounted;
} }
@@ -135,7 +132,6 @@ class MountItems extends Component {
onMountDriveReply = (event, arg) => { onMountDriveReply = (event, arg) => {
const state = { const state = {
...this.state[arg.data.StorageType], ...this.state[arg.data.StorageType],
PID: arg.data.PID,
Mounted: arg.data.Success, Mounted: arg.data.Success,
}; };
this.setState({ this.setState({
@@ -188,7 +184,6 @@ class MountItems extends Component {
key={'mi_' + items.length} key={'mi_' + items.length}
location={this.props[providerLower].MountLocation} location={this.props[providerLower].MountLocation}
mounted={this.state[provider].Mounted} mounted={this.state[provider].Mounted}
pid={this.state[provider].PID}
platform={this.props.platform} platform={this.props.platform}
title={provider} /> title={provider} />
)); ));