[Close to tray] [Unmount fixes]

This commit is contained in:
Scott E. Graves
2018-12-09 20:06:01 -06:00
parent 3c007cdee0
commit ed91305763
2 changed files with 32 additions and 11 deletions

View File

@@ -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);

View File

@@ -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();
});