Handle window/tray according to user preferences

This commit is contained in:
TheThomaas 2024-12-24 17:36:00 +01:00
parent 43492a7ff4
commit b1060f859f

View file

@ -12,7 +12,8 @@ import {
deleteGame,
getAllGames,
getGame
} from './services/Database.service';
} from './services/Database.service.js';
import { appSettings } from './settings.js';
let mainWindow: BrowserWindow;
let splash: BrowserWindow;
@ -44,10 +45,19 @@ function createWindow(): void {
splash.center();
splash.show();
// TODO show window according to the app settings
mainWindow.on('ready-to-show', () => {
splash.close();
// 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) => {
@ -89,16 +99,25 @@ app.whenReady().then(() => {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// TODO close/hide window according to the app settings
// Prevent window from closing and quitting app
// Instead make close simply hide main window
// Clicking on tray icon will bring back main window
mainWindow.on('close', event => {
if (appSettings.get('enableTray') && appSettings.get('closeToTray')) {
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
if (appSettings.get('enableTray')) {
const icon = nativeImage.createFromPath('./resources/icon.png')
tray = new Tray(icon.resize({ width: 16, height: 16 }))
tray.setIgnoreDoubleClickEvents(true)
@ -134,6 +153,8 @@ app.whenReady().then(() => {
mainWindow.show()
})
}
}
ipcMain.handle('game:insert', async (_, game: Game) => {