mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-07-20 18:08:55 +00:00
* fix(window): restore maximized window state from startup/minimized/tray Changes: Call `win.restore()` before `win.show()` to ensure the window returns to its previous state when restored from startup/minimized/tray. Fixes #5466 * fix(window): add manual tracking of maximized window state before hide Changes: add wasMaximizedBeforeHide flag to manually track and handle maximized window state reliably across all platforms * fix(window): add manual tracking of maximized window state before hide Changes: add wasMaximizedBeforeHide flag to manually track and handle maximized window state reliably across all platforms
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { app, BrowserWindow } from 'electron';
|
|
import { info } from 'electron-log/main';
|
|
import { getWin, wasMaximizedBeforeHide } from './main-window';
|
|
import { hideOverlayWindow } from './overlay-indicator/overlay-indicator';
|
|
import { setIsQuiting } from './shared-state';
|
|
|
|
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
export function quitApp(): void {
|
|
setIsQuiting(true);
|
|
app.quit();
|
|
}
|
|
|
|
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
|
|
export function showOrFocus(passedWin: BrowserWindow): void {
|
|
// default to main winpc
|
|
const win = passedWin || getWin();
|
|
|
|
// sometimes when starting a second instance we get here although we don't want to
|
|
if (!win) {
|
|
info(
|
|
'special case occurred when showOrFocus is called even though, this is a second instance of the app',
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (win.isVisible()) {
|
|
win.focus();
|
|
} else {
|
|
// restore explicitly
|
|
if (win.isMinimized()) win.restore();
|
|
win.show();
|
|
if (wasMaximizedBeforeHide) win.maximize();
|
|
}
|
|
|
|
// Hide overlay when main window is shown
|
|
hideOverlayWindow();
|
|
|
|
// focus window afterwards always
|
|
setTimeout(() => {
|
|
win.focus();
|
|
}, 60);
|
|
}
|