Added unmount
This commit is contained in:
30
electron.js
30
electron.js
@@ -17,7 +17,7 @@ const AutoLaunch = require('auto-launch');
|
||||
let trayContextMenu;
|
||||
let mainWindow;
|
||||
let mainWindowTray;
|
||||
let mountedPIDs = {};
|
||||
let mountedData = {};
|
||||
let mountedLocations = [];
|
||||
let expectedUnmount = {};
|
||||
let launchHidden = false;
|
||||
@@ -64,10 +64,11 @@ function createWindow() {
|
||||
|
||||
// Unmount all items
|
||||
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 = [];
|
||||
mountedPIDs = {};
|
||||
mountedData = {};
|
||||
});
|
||||
|
||||
if ((os.platform() === 'win32') || (os.platform() === 'linux')) {
|
||||
@@ -363,11 +364,6 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
Hyperspace: hsLocation,
|
||||
Sia: siaLocation,
|
||||
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);
|
||||
} else {
|
||||
mountedLocations.push(data.Location);
|
||||
mountedPIDs[data.Location] = -1;
|
||||
mountedData[data.Location] = {
|
||||
DataDirectory: dataDirectory,
|
||||
Version: data.Version,
|
||||
StorageType: data.StorageType,
|
||||
};
|
||||
const errorHandler = (pid, error) => {
|
||||
if (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, {
|
||||
Expected: expectedUnmount[data.StorageType],
|
||||
Location: data.Location,
|
||||
PID: -1,
|
||||
StorageType: data.StorageType,
|
||||
}, 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) => {
|
||||
errorHandler(pid, error);
|
||||
})
|
||||
.then(pid => {
|
||||
if (pid !== -1) {
|
||||
mountedPIDs[data.Location] = pid;
|
||||
}
|
||||
.then(() => {
|
||||
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
|
||||
PID: pid,
|
||||
StorageType: data.StorageType,
|
||||
});
|
||||
})
|
||||
@@ -603,9 +598,10 @@ ipcMain.on(Constants.IPC_Shutdown, () => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
expectedUnmount[data.StorageType] = true;
|
||||
helpers
|
||||
.stopMountProcess(data.PID, data.Location)
|
||||
.stopMountProcess(dataDirectory, data.Version, data.StorageType)
|
||||
.then((result)=> {
|
||||
console.log(result);
|
||||
})
|
||||
|
||||
29
helpers.js
29
helpers.js
@@ -159,7 +159,7 @@ module.exports.executeAsync = (command, args=[]) => {
|
||||
module.exports.executeMount = (directory, version, storageType, location, noConsoleSupported, exitCallback) => {
|
||||
return new Promise((resolve) => {
|
||||
const processOptions = {
|
||||
detached: os.platform() === 'win32',
|
||||
detached: false,
|
||||
shell: true,
|
||||
stdio: 'ignore',
|
||||
};
|
||||
@@ -199,9 +199,7 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
|
||||
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) => {
|
||||
const processOptions = {
|
||||
detached: true,
|
||||
detached: false,
|
||||
shell: true,
|
||||
windowsHide: true,
|
||||
};
|
||||
|
||||
let procName = 'kill';
|
||||
if (location && location.length > 0) {
|
||||
procName = 'fusermount';
|
||||
}
|
||||
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 command = path.join(directory, version, (os.platform() === 'win32') ? 'repertory.exe' : 'repertory');
|
||||
const args = ['-unmount'];
|
||||
if (Constants.PROVIDER_ARG[storageType.toLowerCase()].length > 0) {
|
||||
args.push(Constants.PROVIDER_ARG[storageType.toLowerCase()]);
|
||||
}
|
||||
|
||||
const process = new spawn(command, args, processOptions);
|
||||
const pid = process.pid;
|
||||
process.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ export default CSSModules((props) => {
|
||||
width='19px'/>;
|
||||
|
||||
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}
|
||||
colSpan={21}
|
||||
disabled={!props.allowMount || props.disabled}
|
||||
|
||||
@@ -19,7 +19,6 @@ class MountItems extends Component {
|
||||
AllowMount: false,
|
||||
DriveLetters: [],
|
||||
Mounted: false,
|
||||
PID: -1,
|
||||
};
|
||||
}
|
||||
if (ipcRenderer) {
|
||||
@@ -58,7 +57,7 @@ class MountItems extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
handleMountUnMount = (storageType, mount, location, pid) => {
|
||||
handleMountUnMount = (storageType, mount, location) => {
|
||||
if (ipcRenderer) {
|
||||
const state = {
|
||||
...this.state[storageType],
|
||||
@@ -82,7 +81,6 @@ class MountItems extends Component {
|
||||
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
|
||||
Directory: this.props.directory,
|
||||
Location: location,
|
||||
PID: pid,
|
||||
StorageType: storageType,
|
||||
Version: this.props.version,
|
||||
});
|
||||
@@ -101,7 +99,6 @@ class MountItems extends Component {
|
||||
AllowMount: true,
|
||||
DriveLetters: (arg.data.DriveLetters[provider]),
|
||||
Mounted: (arg.data.Locations[provider].length > 0),
|
||||
PID: arg.data.PIDS[provider],
|
||||
};
|
||||
mountsBusy = mountsBusy || state[provider].Mounted;
|
||||
}
|
||||
@@ -135,7 +132,6 @@ class MountItems extends Component {
|
||||
onMountDriveReply = (event, arg) => {
|
||||
const state = {
|
||||
...this.state[arg.data.StorageType],
|
||||
PID: arg.data.PID,
|
||||
Mounted: arg.data.Success,
|
||||
};
|
||||
this.setState({
|
||||
@@ -188,7 +184,6 @@ class MountItems extends Component {
|
||||
key={'mi_' + items.length}
|
||||
location={this.props[providerLower].MountLocation}
|
||||
mounted={this.state[provider].Mounted}
|
||||
pid={this.state[provider].PID}
|
||||
platform={this.props.platform}
|
||||
title={provider} />
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user