[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 // 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. // be closed automatically when the JavaScript object is garbage collected.
let mainContextWindow; let trayContextMenu;
let mainWindow; let mainWindow;
let mainWindowTray; let mainWindowTray;
let mountedPIDs = {}; let mountedPIDs = {};
@@ -22,6 +22,11 @@ let mountedLocations = [];
let expectedUnmount = {}; let expectedUnmount = {};
let launchHidden = false; let launchHidden = false;
let isQuiting = false;
app.on('before-quit', function () {
isQuiting = true;
});
function closeApplication() { function closeApplication() {
app.quit(); app.quit();
} }
@@ -58,7 +63,6 @@ function createWindow() {
mainWindow = null; mainWindow = null;
// Unmount all items // Unmount all items
console.log(mountedLocations);
for (const i in mountedLocations) { for (const i in mountedLocations) {
helpers.stopMountProcess(mountedPIDs[mountedLocations[i]], mountedLocations[i]); helpers.stopMountProcess(mountedPIDs[mountedLocations[i]], mountedLocations[i]);
} }
@@ -77,7 +81,7 @@ function createWindow() {
}); });
const image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png')); const image = nativeImage.createFromPath(path.join(__dirname, '/build/logo.png'));
mainContextWindow = Menu.buildFromTemplate([ trayContextMenu = Menu.buildFromTemplate([
{ {
label: 'Visible', type: 'checkbox', click(item) { label: 'Visible', type: 'checkbox', click(item) {
if (item.checked) { if (item.checked) {
@@ -115,20 +119,32 @@ function createWindow() {
type: 'separator' type: 'separator'
}, },
{ {
label: 'Exit', click(item) { label: 'Exit and Unmount', click(item) {
closeApplication(); 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 autoLauncher
.isEnabled() .isEnabled()
.then((enabled) => { .then((enabled) => {
mainContextWindow.items[1].checked = enabled; trayContextMenu.items[1].checked = enabled;
mainWindowTray = new Tray(image); mainWindowTray = new Tray(image);
mainWindowTray.setToolTip('Repertory UI'); mainWindowTray.setToolTip('Repertory UI');
mainWindowTray.setContextMenu(mainContextWindow) mainWindowTray.setContextMenu(trayContextMenu)
}) })
.catch(() => { .catch(() => {
closeApplication(); closeApplication();
@@ -143,8 +159,9 @@ if (!instanceLock) {
app.on('second-instance', () => { app.on('second-instance', () => {
if (mainWindow) { if (mainWindow) {
mainWindow.show(); mainWindow.show();
if (mainContextWindow) { if (trayContextMenu && mainWindowTray) {
mainContextWindow.items[0].checked = true; trayContextMenu.items[0].checked = true;
mainWindowTray.setContextMenu(trayContextMenu)
} }
if (mainWindow.isMinimized()) { if (mainWindow.isMinimized()) {
mainWindow.restore(); mainWindow.restore();
@@ -589,7 +606,8 @@ ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
expectedUnmount[data.StorageType] = true; expectedUnmount[data.StorageType] = true;
helpers helpers
.stopMountProcess(data.PID, data.Location) .stopMountProcess(data.PID, data.Location)
.then(()=> { .then((result)=> {
console.log(result);
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);

View File

@@ -471,8 +471,11 @@ module.exports.stopMountProcess = (pid, location) => {
process.on('error', (err) => { process.on('error', (err) => {
reject(err); reject(err);
}); });
process.on('exit', () => { process.on('exit', (code) => {
setTimeout(()=>resolve(pid), 3000); resolve({
PID: pid,
Code: code,
});
}); });
process.unref(); process.unref();
}); });