1
0
Fork 0
mirror of https://gitlab.com/futo-org/fcast.git synced 2025-06-24 21:25:23 +00:00

Updated behavior for main window sizing, fullscreen, and system tray visibility

This commit is contained in:
Michael Hollister 2024-11-14 01:04:00 -06:00
parent 6fdf1869d7
commit 6cafca5412

View file

@ -16,6 +16,7 @@ import { hideBin } from 'yargs/helpers';
export default class Main { export default class Main {
static shouldOpenMainWindow = true; static shouldOpenMainWindow = true;
static startFullscreen = false;
static playerWindow: Electron.BrowserWindow; static playerWindow: Electron.BrowserWindow;
static mainWindow: Electron.BrowserWindow; static mainWindow: Electron.BrowserWindow;
static application: Electron.App; static application: Electron.App;
@ -29,14 +30,23 @@ export default class Main {
static proxyServerAddress: AddressInfo; static proxyServerAddress: AddressInfo;
static proxiedFiles: Map<string, { url: string, headers: { [key: string]: string } }> = new Map(); static proxiedFiles: Map<string, { url: string, headers: { [key: string]: string } }> = new Map();
private static toggleMainWindow() {
if (Main.mainWindow) {
Main.mainWindow.close();
}
else {
Main.openMainWindow();
}
}
private static createTray() { private static createTray() {
const icon = (process.platform === 'win32') ? path.join(__dirname, 'icon.ico') : path.join(__dirname, 'icon.png'); const icon = (process.platform === 'win32') ? path.join(__dirname, 'icon.ico') : path.join(__dirname, 'icon.png');
const trayicon = nativeImage.createFromPath(icon) const trayicon = nativeImage.createFromPath(icon)
const tray = new Tray(trayicon.resize({ width: 16 })); const tray = new Tray(trayicon.resize({ width: 16 }));
const contextMenu = Menu.buildFromTemplate([ const contextMenu = Menu.buildFromTemplate([
{ {
label: 'Open window', label: 'Toggle window',
click: () => Main.openMainWindow() click: () => { Main.toggleMainWindow(); }
}, },
{ {
label: 'Check for updates', label: 'Check for updates',
@ -100,6 +110,7 @@ export default class Main {
]) ])
tray.setContextMenu(contextMenu); tray.setContextMenu(contextMenu);
tray.on('click', () => { Main.toggleMainWindow(); } );
this.tray = tray; this.tray = tray;
} }
@ -317,11 +328,11 @@ export default class Main {
} }
Main.mainWindow = new BrowserWindow({ Main.mainWindow = new BrowserWindow({
fullscreen: true, fullscreen: Main.startFullscreen,
autoHideMenuBar: true, autoHideMenuBar: true,
icon: path.join(__dirname, 'icon512.png'), icon: path.join(__dirname, 'icon512.png'),
minWidth: 500, minWidth: 1100,
minHeight: 920, minHeight: 800,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'main/preload.js') preload: path.join(__dirname, 'main/preload.js')
} }
@ -332,6 +343,7 @@ export default class Main {
Main.mainWindow = null; Main.mainWindow = null;
}); });
Main.mainWindow.maximize();
Main.mainWindow.show(); Main.mainWindow.show();
Main.mainWindow.on('ready-to-show', () => { Main.mainWindow.on('ready-to-show', () => {
@ -346,10 +358,12 @@ export default class Main {
'boolean-negation': false 'boolean-negation': false
}) })
.options({ .options({
'no-main-window': { type: 'boolean', default: false, desc: "Start minimized to tray" } 'no-main-window': { type: 'boolean', default: false, desc: "Start minimized to tray" },
'fullscreen': { type: 'boolean', default: false, desc: "Start application in fullscreen" }
}) })
.parseSync(); .parseSync();
Main.startFullscreen = argv.fullscreen;
Main.shouldOpenMainWindow = !argv.noMainWindow; Main.shouldOpenMainWindow = !argv.noMainWindow;
Main.application.on('ready', Main.onReady); Main.application.on('ready', Main.onReady);
Main.application.on('window-all-closed', () => { }); Main.application.on('window-all-closed', () => { });