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();
|
||||||
|
|
||||||
|
// 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.show()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
|
|
@ -89,16 +99,25 @@ 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 => {
|
||||||
|
if (appSettings.get('enableTray') && appSettings.get('closeToTray')) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
mainWindow.hide()
|
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
|
||||||
|
if (appSettings.get('enableTray')) {
|
||||||
const icon = nativeImage.createFromPath('./resources/icon.png')
|
const icon = nativeImage.createFromPath('./resources/icon.png')
|
||||||
tray = new Tray(icon.resize({ width: 16, height: 16 }))
|
tray = new Tray(icon.resize({ width: 16, height: 16 }))
|
||||||
tray.setIgnoreDoubleClickEvents(true)
|
tray.setIgnoreDoubleClickEvents(true)
|
||||||
|
|
@ -134,6 +153,8 @@ app.whenReady().then(() => {
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ipcMain.handle('game:insert', async (_, game: Game) => {
|
ipcMain.handle('game:insert', async (_, game: Game) => {
|
||||||
|
|
|
||||||
Reference in a new issue