diff --git a/electron.js b/electron.js index a8d7d86..b5adbfa 100644 --- a/electron.js +++ b/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); }) diff --git a/helpers.js b/helpers.js index 2860a42..8f496e3 100644 --- a/helpers.js +++ b/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); }); diff --git a/src/components/MountItem/MountItem.js b/src/components/MountItem/MountItem.js index 5356a14..3f2742f 100644 --- a/src/components/MountItem/MountItem.js +++ b/src/components/MountItem/MountItem.js @@ -60,7 +60,7 @@ export default CSSModules((props) => { width='19px'/>; const actionsDisplay = ( -