Monitor detached mounts

This commit is contained in:
Scott E. Graves
2018-12-13 00:19:30 -06:00
parent 63d69f0b9e
commit b25062e466

View File

@@ -21,6 +21,8 @@ let mountedData = {};
let mountedLocations = []; let mountedLocations = [];
let expectedUnmount = {}; let expectedUnmount = {};
let launchHidden = false; let launchHidden = false;
let firstMountCheck = true;
let manualMountDetection = {};
let isQuiting = false; let isQuiting = false;
app.on('before-quit', function () { app.on('before-quit', function () {
@@ -190,6 +192,36 @@ const loadUiSettings = () => {
} }
}; };
const monitorMount = (sender, storageType, dataDirectory, version, pid, location) => {
manualMountDetection[storageType] = setInterval(() => {
helpers
.detectRepertoryMounts(dataDirectory, version)
.then(result => {
if (result[storageType].PID !== pid) {
if (result[storageType].PID === -1) {
clearTimeout(manualMountDetection[storageType]);
delete manualMountDetection[storageType];
sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
Expected: expectedUnmount[storageType],
Location: location,
StorageType: storageType,
Error: Error(storageType + ' Unmounted').toString(),
Success: false,
}
});
} else {
pid = result[storageType].PID;
}
}
})
.catch(e => {
console.log(e);
});
},6000);
};
const saveUiSettings = () => { const saveUiSettings = () => {
const settingFile = path.join(helpers.resolvePath(Constants.DATA_LOCATIONS[os.platform()]), 'ui.json'); const settingFile = path.join(helpers.resolvePath(Constants.DATA_LOCATIONS[os.platform()]), 'ui.json');
try { try {
@@ -349,18 +381,22 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
helpers helpers
.detectRepertoryMounts(dataDirectory, data.Version) .detectRepertoryMounts(dataDirectory, data.Version)
.then((results) => { .then((results) => {
let data = {}; let storageData = {};
let locations = {}; let locations = {};
for (const provider of Constants.PROVIDER_LIST) { for (const provider of Constants.PROVIDER_LIST) {
data[provider] = results[provider] ? results[provider] : { storageData[provider] = results[provider] ? results[provider] : {
Active: false, Active: false,
Location: '', Location: '',
PID: -1, PID: -1,
}; };
if (data[provider].PID !== -1) { locations[provider] = storageData[provider].Location;
if (storageData[provider].PID !== -1) {
expectedUnmount[provider] = false; expectedUnmount[provider] = false;
if (firstMountCheck) {
monitorMount(event.sender, provider, dataDirectory, data.Version, storageData[provider].PID, storageData[provider].Location);
}
} }
locations[provider] = data[provider].Location;
} }
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
@@ -368,6 +404,9 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
} }
setImage(locations); setImage(locations);
if (firstMountCheck) {
firstMountCheck = false;
}
standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, {
DriveLetters: driveLetters, DriveLetters: driveLetters,
Locations: locations, Locations: locations,
@@ -635,6 +674,11 @@ ipcMain.on(Constants.IPC_Shutdown, () => {
}); });
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => { ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
if (manualMountDetection[data.StorageType]) {
clearInterval(manualMountDetection[data.StorageType]);
delete manualMountDetection[data.StorageType];
}
const dataDirectory = helpers.resolvePath(data.Directory); const dataDirectory = helpers.resolvePath(data.Directory);
expectedUnmount[data.StorageType] = true; expectedUnmount[data.StorageType] = true;
helpers helpers