Windows fixes

This commit is contained in:
Scott E. Graves
2018-12-10 13:32:26 -06:00
parent 61b2f6e6f6
commit 29a72f4707
2 changed files with 60 additions and 56 deletions

View File

@@ -65,8 +65,9 @@ function createWindow() {
// Unmount all items // Unmount all items
for (const i in mountedLocations) { for (const i in mountedLocations) {
const data = mountedData[mountedLocations[i]]; const data = mountedData[mountedLocations[i]];
helpers.stopMountProcess(data.DataDirectory, data.Version, data.StorageType); helpers.stopMountProcessSync(data.DataDirectory, data.Version, data.StorageType);
} }
mountedLocations = []; mountedLocations = [];
mountedData = {}; mountedData = {};
}); });
@@ -275,50 +276,49 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
driveLetters[provider] = []; driveLetters[provider] = [];
} }
const grabDriveLetters = (hsLocation, siaLocation, siaPrimeLocation) => { const grabDriveLetters = (locations) => {
for (let i = 'c'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) { for (let i = 'c'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
const drive = (String.fromCharCode(i) + ':').toUpperCase(); const drive = (String.fromCharCode(i) + ':').toUpperCase();
if (!(hsLocation.startsWith(drive) || siaLocation.startsWith(drive) || siaPrimeLocation.startsWith(drive))) { let driveInUse = false;
for (const provider of Constants.PROVIDER_LIST) {
driveInUse = locations[provider].startsWith(drive);
if (driveInUse)
break;
}
if (!driveInUse) {
try { try {
if (!fs.existsSync(drive)) { if (!fs.existsSync(drive)) {
driveLetters.Hyperspace.push(drive); for (const provider of Constants.PROVIDER_LIST) {
driveLetters.Sia.push(drive); driveLetters[provider].push(drive);
driveLetters.SiaPrime.push(drive); }
} }
} catch (e) { } catch (e) {
} }
} }
} }
if (hsLocation.length > 0) { for (const provider of Constants.PROVIDER_LIST) {
if (!driveLetters.Hyperspace.find((driveLetter) => { if (locations[provider].length > 0) {
return driveLetter === hsLocation; if (!driveLetters[provider].find((driveLetter) => {
})) { return driveLetter === locations[provider];
driveLetters.Hyperspace.push(hsLocation); })) {
} driveLetters[provider].push(locations[provider]);
} }
if (siaLocation.length > 0) {
if (!driveLetters.Sia.find((driveLetter) => {
return driveLetter === siaLocation;
})) {
driveLetters.Sia.push(siaLocation);
}
}
if (siaPrimeLocation.length > 0) {
if (!driveLetters.SiaPrime.find((driveLetter) => {
return driveLetter === siaPrimeLocation;
})) {
driveLetters.SiaPrime.push(siaPrimeLocation);
} }
} }
}; };
const setImage = (hsLocation, siaLocation, siaPrimeLocation) => { const setImage = (locations) => {
if (os.platform() === 'win32' || os.platform() === 'linux') { if (os.platform() === 'win32' || os.platform() === 'linux') {
let driveInUse = false;
for (const provider of Constants.PROVIDER_LIST) {
driveInUse = locations[provider].length > 0;
if (driveInUse)
break;
}
let image; let image;
if ((siaLocation.length > 0) || (hsLocation.length > 0) || (siaPrimeLocation.length > 0)) { if (driveInUse) {
image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_both.png')); image = nativeImage.createFromPath(path.join(__dirname, '/build/logo_both.png'));
} else { } else {
image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png')); image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png'));
@@ -332,39 +332,28 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
helpers helpers
.detectRepertoryMounts(dataDirectory, data.Version) .detectRepertoryMounts(dataDirectory, data.Version)
.then((results) => { .then((results) => {
let hsLocation = results.Hyperspace.Location; let data = {};
let siaLocation = results.Sia.Location; let locations = {};
if (!results.SiaPrime) { for (const provider of Constants.PROVIDER_LIST) {
results.SiaPrime = { data[provider] = results[provider] ? results[provider] : {
Active: false, Active: false,
Location: '', Location: '',
PID: -1, PID: -1,
}; };
if (data[provider].PID !== -1) {
expectedUnmount[provider] = false;
}
locations[provider] = data[provider].Location;
} }
let siaPrimeLocation = results.SiaPrime.Location;
if (os.platform() === 'win32') { if (os.platform() === 'win32') {
hsLocation = hsLocation.toUpperCase(); grabDriveLetters(locations);
siaLocation = siaLocation.toUpperCase();
siaPrimeLocation = siaPrimeLocation.toUpperCase();
grabDriveLetters(hsLocation, siaLocation, siaPrimeLocation);
} }
if (results.Hyperspace.PID !== -1) {
expectedUnmount['Hyperspace'] = false; setImage(locations);
}
if (results.Sia.PID !== -1) {
expectedUnmount['Sia'] = false;
}
if (results.SiaPrime.PID !== -1) {
expectedUnmount['SiaPrime'] = false;
}
setImage(hsLocation, siaLocation, siaPrimeLocation);
standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, { standardIPCReply(event, Constants.IPC_Detect_Mounts_Reply, {
DriveLetters: driveLetters, DriveLetters: driveLetters,
Locations: { Locations: locations,
Hyperspace: hsLocation,
Sia: siaLocation,
SiaPrime: siaPrimeLocation,
}
}); });
}) })
.catch(error => { .catch(error => {
@@ -541,6 +530,7 @@ ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
StorageType: data.StorageType, StorageType: data.StorageType,
}; };
const errorHandler = (pid, error) => { const errorHandler = (pid, error) => {
console.log(pid, error);
if (mountedLocations.indexOf(data.Location) !== -1) { if (mountedLocations.indexOf(data.Location) !== -1) {
mountedLocations.splice(mountedLocations.indexOf(data.Location), 1); mountedLocations.splice(mountedLocations.indexOf(data.Location), 1);
delete mountedData[data.Location]; delete mountedData[data.Location];

View File

@@ -198,8 +198,6 @@ module.exports.executeMount = (directory, version, storageType, location, noCons
clearTimeout(timeout); clearTimeout(timeout);
exitCallback(code, pid); exitCallback(code, pid);
}); });
process.unref();
}); });
}; };
@@ -466,6 +464,22 @@ module.exports.stopMountProcess = (directory, version, storageType) => {
Code: code, Code: code,
}); });
}); });
process.unref();
}); });
};
module.exports.stopMountProcessSync = (directory, version, storageType) => {
const processOptions = {
detached: true,
shell: true,
windowsHide: true,
};
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);
process.unref();
}; };