diff --git a/electron.js b/electron.js index e0716cf..432b357 100644 --- a/electron.js +++ b/electron.js @@ -21,6 +21,8 @@ let mountedData = {}; let mountedLocations = []; let expectedUnmount = {}; let launchHidden = false; +let firstMountCheck = true; +let manualMountDetection = {}; let isQuiting = false; 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 settingFile = path.join(helpers.resolvePath(Constants.DATA_LOCATIONS[os.platform()]), 'ui.json'); try { @@ -349,18 +381,22 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { helpers .detectRepertoryMounts(dataDirectory, data.Version) .then((results) => { - let data = {}; + let storageData = {}; let locations = {}; for (const provider of Constants.PROVIDER_LIST) { - data[provider] = results[provider] ? results[provider] : { + storageData[provider] = results[provider] ? results[provider] : { Active: false, Location: '', PID: -1, }; - if (data[provider].PID !== -1) { + locations[provider] = storageData[provider].Location; + + if (storageData[provider].PID !== -1) { 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') { @@ -368,6 +404,9 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => { } setImage(locations); + if (firstMountCheck) { + firstMountCheck = false; + } standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { DriveLetters: driveLetters, Locations: locations, @@ -635,6 +674,11 @@ ipcMain.on(Constants.IPC_Shutdown, () => { }); 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); expectedUnmount[data.StorageType] = true; helpers