[Close to tray] [Unmount fixes]
This commit is contained in:
36
electron.js
36
electron.js
@@ -14,7 +14,7 @@ const AutoLaunch = require('auto-launch');
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainContextWindow;
|
||||
let trayContextMenu;
|
||||
let mainWindow;
|
||||
let mainWindowTray;
|
||||
let mountedPIDs = {};
|
||||
@@ -22,6 +22,11 @@ let mountedLocations = [];
|
||||
let expectedUnmount = {};
|
||||
let launchHidden = false;
|
||||
|
||||
let isQuiting = false;
|
||||
app.on('before-quit', function () {
|
||||
isQuiting = true;
|
||||
});
|
||||
|
||||
function closeApplication() {
|
||||
app.quit();
|
||||
}
|
||||
@@ -58,7 +63,6 @@ function createWindow() {
|
||||
mainWindow = null;
|
||||
|
||||
// Unmount all items
|
||||
console.log(mountedLocations);
|
||||
for (const i in mountedLocations) {
|
||||
helpers.stopMountProcess(mountedPIDs[mountedLocations[i]], mountedLocations[i]);
|
||||
}
|
||||
@@ -77,7 +81,7 @@ function createWindow() {
|
||||
});
|
||||
|
||||
const image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png'));
|
||||
mainContextWindow = Menu.buildFromTemplate([
|
||||
trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Visible', type: 'checkbox', click(item) {
|
||||
if (item.checked) {
|
||||
@@ -115,20 +119,32 @@ function createWindow() {
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Exit', click(item) {
|
||||
label: 'Exit and Unmount', click(item) {
|
||||
closeApplication();
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
mainWindow.on('close', function (event) {
|
||||
if (!isQuiting) {
|
||||
event.preventDefault();
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide();
|
||||
trayContextMenu.items[0].checked = false;
|
||||
mainWindowTray.setContextMenu(trayContextMenu);
|
||||
}
|
||||
event.returnValue = false;
|
||||
}
|
||||
});
|
||||
|
||||
autoLauncher
|
||||
.isEnabled()
|
||||
.then((enabled) => {
|
||||
mainContextWindow.items[1].checked = enabled;
|
||||
trayContextMenu.items[1].checked = enabled;
|
||||
|
||||
mainWindowTray = new Tray(image);
|
||||
mainWindowTray.setToolTip('Repertory UI');
|
||||
mainWindowTray.setContextMenu(mainContextWindow)
|
||||
mainWindowTray.setContextMenu(trayContextMenu)
|
||||
})
|
||||
.catch(() => {
|
||||
closeApplication();
|
||||
@@ -143,8 +159,9 @@ if (!instanceLock) {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
mainWindow.show();
|
||||
if (mainContextWindow) {
|
||||
mainContextWindow.items[0].checked = true;
|
||||
if (trayContextMenu && mainWindowTray) {
|
||||
trayContextMenu.items[0].checked = true;
|
||||
mainWindowTray.setContextMenu(trayContextMenu)
|
||||
}
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
@@ -589,7 +606,8 @@ ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
|
||||
expectedUnmount[data.StorageType] = true;
|
||||
helpers
|
||||
.stopMountProcess(data.PID, data.Location)
|
||||
.then(()=> {
|
||||
.then((result)=> {
|
||||
console.log(result);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log(e);
|
||||
|
||||
@@ -471,8 +471,11 @@ module.exports.stopMountProcess = (pid, location) => {
|
||||
process.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
process.on('exit', () => {
|
||||
setTimeout(()=>resolve(pid), 3000);
|
||||
process.on('exit', (code) => {
|
||||
resolve({
|
||||
PID: pid,
|
||||
Code: code,
|
||||
});
|
||||
});
|
||||
process.unref();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user