Linux / OS X changes
This commit is contained in:
119
electron.js
119
electron.js
@@ -17,10 +17,15 @@ const AutoLaunch = require('auto-launch');
|
||||
let mainContextWindow;
|
||||
let mainWindow;
|
||||
let mainWindowTray;
|
||||
let mountedPIDs = [];
|
||||
let mountedPIDs = {};
|
||||
let mountedLocations = [];
|
||||
let expectedUnmount = {};
|
||||
let launchHidden = false;
|
||||
|
||||
function closeApplication() {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
loadUiSettings();
|
||||
|
||||
@@ -50,7 +55,15 @@ function createWindow() {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null
|
||||
mainWindow = null;
|
||||
|
||||
// Unmount all items
|
||||
console.log(mountedLocations);
|
||||
for (const i in mountedLocations) {
|
||||
helpers.stopMountProcess(mountedPIDs[mountedLocations[i]], mountedLocations[i]);
|
||||
}
|
||||
mountedLocations = [];
|
||||
mountedPIDs = {};
|
||||
});
|
||||
|
||||
if ((os.platform() === 'win32') || (os.platform() === 'linux')) {
|
||||
@@ -103,7 +116,7 @@ function createWindow() {
|
||||
},
|
||||
{
|
||||
label: 'Exit', click(item) {
|
||||
app.quit();
|
||||
closeApplication();
|
||||
}
|
||||
}
|
||||
]);
|
||||
@@ -118,14 +131,14 @@ function createWindow() {
|
||||
mainWindowTray.setContextMenu(mainContextWindow)
|
||||
})
|
||||
.catch(() => {
|
||||
app.quit();
|
||||
closeApplication();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const instanceLock = app.requestSingleInstanceLock();
|
||||
if (!instanceLock) {
|
||||
app.quit()
|
||||
closeApplication();
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
@@ -146,7 +159,7 @@ if (!instanceLock) {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
closeApplication();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -181,13 +194,15 @@ const saveUiSettings = () => {
|
||||
};
|
||||
|
||||
const standardIPCReply = (event, channel, data, error) => {
|
||||
event.sender.send(channel, {
|
||||
data: {
|
||||
...data,
|
||||
Error: error,
|
||||
Success: !error,
|
||||
}
|
||||
});
|
||||
if (mainWindow) {
|
||||
event.sender.send(channel, {
|
||||
data: {
|
||||
...data,
|
||||
Error: error,
|
||||
Success: !error,
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
ipcMain.on(Constants.IPC_Check_Dependency_Installed, (event, data) => {
|
||||
@@ -237,11 +252,10 @@ ipcMain.on(Constants.IPC_Delete_File, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
let driveLetters = {
|
||||
Hyperspace: [],
|
||||
Sia: [],
|
||||
SiaPrime: [],
|
||||
};
|
||||
let driveLetters = {};
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
driveLetters[provider] = [];
|
||||
}
|
||||
|
||||
const grabDriveLetters = (hsLocation, siaLocation, siaPrimeLocation) => {
|
||||
for (let i = 'c'.charCodeAt(0); i <= 'z'.charCodeAt(0); i++) {
|
||||
@@ -503,30 +517,42 @@ ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
expectedUnmount[data.StorageType] = false;
|
||||
const dataDirectory = helpers.resolvePath(data.Directory);
|
||||
const errorHandler = (pid, error) => {
|
||||
mountedPIDs.splice(mountedPIDs.indexOf(pid), 1);
|
||||
standardIPCReply(event, Constants.IPC_Unmount_Drive_Reply, {
|
||||
Expected: expectedUnmount[data.StorageType],
|
||||
Location: data.Location,
|
||||
PID: -1,
|
||||
StorageType: data.StorageType,
|
||||
}, error || Error(data.StorageType + ' Unmounted'));
|
||||
};
|
||||
helpers.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, (error, pid) => {
|
||||
errorHandler(pid, error);
|
||||
})
|
||||
.then(pid => {
|
||||
if (pid !== -1) {
|
||||
mountedPIDs.push(pid);
|
||||
}
|
||||
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
|
||||
PID: pid,
|
||||
StorageType: data.StorageType,
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
errorHandler(-1, error);
|
||||
});
|
||||
|
||||
if (mountedLocations.indexOf(data.Location) !== -1) {
|
||||
console.log(data.StorageType + ' already mounted: ' + data.Location);
|
||||
} else {
|
||||
mountedLocations.push(data.Location);
|
||||
mountedPIDs[data.Location] = -1;
|
||||
const errorHandler = (pid, error) => {
|
||||
if (mountedLocations.indexOf(data.Location) !== -1) {
|
||||
mountedLocations.splice(mountedLocations.indexOf(data.Location), 1);
|
||||
delete mountedPIDs[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'));
|
||||
};
|
||||
helpers
|
||||
.executeMount(dataDirectory, data.Version, data.StorageType, data.Location, data.NoConsoleSupported, (error, pid) => {
|
||||
errorHandler(pid, error);
|
||||
})
|
||||
.then(pid => {
|
||||
if (pid !== -1) {
|
||||
mountedPIDs[data.Location] = pid;
|
||||
}
|
||||
standardIPCReply(event, Constants.IPC_Mount_Drive_Reply, {
|
||||
PID: pid,
|
||||
StorageType: data.StorageType,
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
errorHandler(-1, error);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
|
||||
@@ -556,17 +582,14 @@ ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Shutdown, () => {
|
||||
app.quit();
|
||||
closeApplication();
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
expectedUnmount[data.StorageType] = true;
|
||||
helpers
|
||||
.stopProcessByPID(data.PID)
|
||||
.then((pid)=> {
|
||||
if (mountedPIDs.indexOf(pid) === -1) {
|
||||
event.sender.send(Constants.IPC_Unmount_Drive_Reply);
|
||||
}
|
||||
.stopMountProcess(data.PID, data.Location)
|
||||
.then(()=> {
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user