Handle window/tray according to user preferences
This commit is contained in:
parent
43492a7ff4
commit
b1060f859f
|
|
@ -12,7 +12,8 @@ import {
|
||||||
deleteGame,
|
deleteGame,
|
||||||
getAllGames,
|
getAllGames,
|
||||||
getGame
|
getGame
|
||||||
} from './services/Database.service';
|
} from './services/Database.service.js';
|
||||||
|
import { appSettings } from './settings.js';
|
||||||
|
|
||||||
let mainWindow: BrowserWindow;
|
let mainWindow: BrowserWindow;
|
||||||
let splash: BrowserWindow;
|
let splash: BrowserWindow;
|
||||||
|
|
@ -44,10 +45,19 @@ function createWindow(): void {
|
||||||
splash.center();
|
splash.center();
|
||||||
splash.show();
|
splash.show();
|
||||||
|
|
||||||
// TODO show window according to the app settings
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
splash.close();
|
splash.close();
|
||||||
mainWindow.show()
|
|
||||||
|
// Show window according to user preferences
|
||||||
|
if (appSettings.get('startMinimized')) {
|
||||||
|
if (appSettings.get('enableTray') && appSettings.get('minimizeToTray')) {
|
||||||
|
mainWindow.hide()
|
||||||
|
} else {
|
||||||
|
mainWindow.minimize()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainWindow.show()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
|
|
@ -89,53 +99,64 @@ app.whenReady().then(() => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO close/hide window according to the app settings
|
|
||||||
// Prevent window from closing and quitting app
|
// Prevent window from closing and quitting app
|
||||||
// Instead make close simply hide main window
|
// Instead make close simply hide main window
|
||||||
// Clicking on tray icon will bring back main window
|
// Clicking on tray icon will bring back main window
|
||||||
mainWindow.on('close', event => {
|
mainWindow.on('close', event => {
|
||||||
event.preventDefault()
|
if (appSettings.get('enableTray') && appSettings.get('closeToTray')) {
|
||||||
mainWindow.hide()
|
event.preventDefault()
|
||||||
|
mainWindow.hide()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Minimizes window to the tray icon if it exists
|
||||||
|
mainWindow.on('minimize', () => {
|
||||||
|
if (appSettings.get('enableTray') && appSettings.get('minimizeToTray')) {
|
||||||
|
mainWindow.hide()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Creating the tray icon
|
// Creating the tray icon
|
||||||
const icon = nativeImage.createFromPath('./resources/icon.png')
|
if (appSettings.get('enableTray')) {
|
||||||
tray = new Tray(icon.resize({ width: 16, height: 16 }))
|
const icon = nativeImage.createFromPath('./resources/icon.png')
|
||||||
tray.setIgnoreDoubleClickEvents(true)
|
tray = new Tray(icon.resize({ width: 16, height: 16 }))
|
||||||
|
tray.setIgnoreDoubleClickEvents(true)
|
||||||
|
|
||||||
const contextMenu = Menu.buildFromTemplate([
|
const contextMenu = Menu.buildFromTemplate([
|
||||||
...(process.platform === 'darwin' ? [{
|
...(process.platform === 'darwin' ? [{
|
||||||
label: 'Show',
|
label: 'Show',
|
||||||
click: _ => {
|
click: _ => {
|
||||||
|
mainWindow.show()
|
||||||
|
}
|
||||||
|
}] : []),
|
||||||
|
{
|
||||||
|
label: 'Hide',
|
||||||
|
click: _ => {
|
||||||
|
mainWindow.hide()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Quit',
|
||||||
|
click: _ => {
|
||||||
|
console.log('Menu/Quit was clicked')
|
||||||
|
app.exit()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
])
|
||||||
|
tray.setToolTip(app.getName())
|
||||||
|
tray.setContextMenu(contextMenu)
|
||||||
|
|
||||||
|
// Prevent menu from being shown on left click
|
||||||
|
// Instead make main window visible (if it had been invisible)
|
||||||
|
if (process.platform !== 'darwin') {
|
||||||
|
tray.on('click', _ => {
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
}
|
})
|
||||||
}] : []),
|
}
|
||||||
{
|
|
||||||
label: 'Hide',
|
|
||||||
click: _ => {
|
|
||||||
mainWindow.hide()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Quit',
|
|
||||||
click: _ => {
|
|
||||||
console.log('Menu/Quit was clicked')
|
|
||||||
app.exit()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
])
|
|
||||||
tray.setToolTip(app.getName())
|
|
||||||
tray.setContextMenu(contextMenu)
|
|
||||||
|
|
||||||
// Prevent menu from being shown on left click
|
|
||||||
// Instead make main window visible (if it had been invisible)
|
|
||||||
if (process.platform !== 'darwin') {
|
|
||||||
tray.on('click', _ => {
|
|
||||||
mainWindow.show()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ipcMain.handle('game:insert', async (_, game: Game) => {
|
ipcMain.handle('game:insert', async (_, game: Game) => {
|
||||||
addGame(game);
|
addGame(game);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Reference in a new issue