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);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user