Refactoring
This commit is contained in:
49
electron.js
49
electron.js
@@ -33,6 +33,31 @@ function closeApplication() {
|
||||
app.quit();
|
||||
}
|
||||
|
||||
function setWindowVisibility(show) {
|
||||
if (show) {
|
||||
mainWindow.show();
|
||||
if (os.platform() === 'darwin') {
|
||||
app.dock.show();
|
||||
}
|
||||
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
|
||||
mainWindow.focus();
|
||||
} else {
|
||||
mainWindow.hide();
|
||||
if (os.platform() === 'darwin') {
|
||||
app.dock.hide();
|
||||
}
|
||||
}
|
||||
|
||||
if (trayContextMenu && mainWindowTray) {
|
||||
trayContextMenu.items[0].checked = show;
|
||||
mainWindowTray.setContextMenu(trayContextMenu)
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow() {
|
||||
loadUiSettings();
|
||||
|
||||
@@ -87,15 +112,7 @@ function createWindow() {
|
||||
trayContextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Visible', type: 'checkbox', click(item) {
|
||||
if (item.checked) {
|
||||
mainWindow.show();
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
mainWindow.focus()
|
||||
} else {
|
||||
mainWindow.hide();
|
||||
}
|
||||
setWindowVisibility(item.checked);
|
||||
},
|
||||
checked: !launchHidden,
|
||||
},
|
||||
@@ -132,9 +149,7 @@ function createWindow() {
|
||||
if (!isQuiting) {
|
||||
event.preventDefault();
|
||||
if (mainWindow.isVisible()) {
|
||||
mainWindow.hide();
|
||||
trayContextMenu.items[0].checked = false;
|
||||
mainWindowTray.setContextMenu(trayContextMenu);
|
||||
setWindowVisibility(false);
|
||||
}
|
||||
event.returnValue = false;
|
||||
}
|
||||
@@ -160,15 +175,7 @@ if (!instanceLock) {
|
||||
} else {
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
mainWindow.show();
|
||||
if (trayContextMenu && mainWindowTray) {
|
||||
trayContextMenu.items[0].checked = true;
|
||||
mainWindowTray.setContextMenu(trayContextMenu)
|
||||
}
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
mainWindow.focus()
|
||||
setWindowVisibility(true, true);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user