A full-featured download manager.
fix(window): restore maximized state on relaunch (#2023)
Dr_rOot2d14b86d5b1e
diff --git a/src/core/settings/validators.test.ts b/src/core/settings/validators.test.tsindex 930ff89d..dadae283 100644--- a/src/core/settings/validators.test.ts+++ b/src/core/settings/validators.test.ts@@ -10,8 +10,27 @@ import {natSettingsSchema,validateAppSettings,validateEngineSettings,+ windowStateSchema,} from './validators'+describe('windowStateSchema', () => {+ it('migrates legacy bounds to a non-maximized saved state', () => {+ expect(+ windowStateSchema.parse({+ main: { x: 100, y: 100, width: 1024, height: 768 },+ })+ ).toEqual({+ main: {+ x: 100,+ y: 100,+ width: 1024,+ height: 768,+ maximized: false,+ },+ })+ })+})+describe('validateEngineSettings', () => {it('returns defaults for empty object', () => {const result = validateEngineSettings({} as EngineSettings)diff --git a/src/main/window/window-manager.test.ts b/src/main/window/window-manager.test.tsindex cf29e2f2..29ea7d8a 100644--- a/src/main/window/window-manager.test.ts+++ b/src/main/window/window-manager.test.ts@@ -54,6 +54,8 @@ vi.mock('electron', () => {isFocused = vi.fn(() => true)isMaximized = vi.fn(() => false)getBounds = vi.fn(() => ({ ...this._bounds }))+ getNormalBounds = vi.fn(() => ({ ...this._bounds }))+ maximize = vi.fn()setBounds = vi.fn((b: { x: number; y: number; width: number; height: number }) => {this._bounds = b@@ -705,6 +707,51 @@ describe('WindowManager', () => {expect(win.setBounds).toHaveBeenCalledWith(savedBounds)})+ it('saves normal bounds and maximized state for a maximized window', () => {+ const sm = createMockSettingsManager()+ const wm = new WindowManager({+ settingsManager: sm,+ preloadPath: '/fake/preload.cjs',+ loadUrl: vi.fn(),+ })+ const win = wm.open('main')+ const normalBounds = { x: 120, y: 80, width: 1100, height: 760 }+ vi.mocked(win.getNormalBounds).mockReturnValue(normalBounds)+ vi.mocked(win.isMaximized).mockReturnValue(true)++ wm.saveBounds('main')++ expect(sm.update).toHaveBeenCalledWith({+ windowState: { main: { ...normalBounds, maximized: true } },+ })+ expect(win.getBounds).not.toHaveBeenCalled()+ })++ it('restores normal bounds before re-maximizing a window', () => {+ const savedState = {+ x: 100,+ y: 100,+ width: 1024,+ height: 768,+ maximized: true,+ }+ const wm = new WindowManager({+ settingsManager: createMockSettingsManager({ main: savedState }),+ preloadPath: '/fake/preload.cjs',+ loadUrl: vi.fn(),+ })++ const win = wm.open('main')++ expect(win.setBounds).toHaveBeenCalledWith({+ x: 100,+ y: 100,+ width: 1024,+ height: 768,+ })+ expect(win.maximize).toHaveBeenCalledOnce()+ })+it('ignores saved bounds if outside all screens', () => {const savedBounds = { x: 5000, y: 5000, width: 1024, height: 768 }const sm = createMockSettingsManager({ main: savedBounds })diff --git a/src/main/window/window-manager.ts b/src/main/window/window-manager.tsindex 52b10cd8..d57b07c7 100644--- a/src/main/window/window-manager.ts+++ b/src/main/window/window-manager.ts@@ -5,7 +5,7 @@ import {type WindowMaximizedChangedPayload,} from '@shared/protocol/events'import type { AddTaskUrlParams } from '@shared/schemas/add-task'-import type { WindowBounds } from '@shared/types/settings'+import type { WindowBounds, WindowState } from '@shared/types/settings'import { BrowserWindow, screen, shell } from 'electron'import type { LiquidGlassController } from './liquid-glass'import { buildPlatformOptions } from './platform-options'@@ -291,9 +291,12 @@ export class WindowManager {const win = this.windows.get(id)if (!win || win.isDestroyed()) return- const bounds = win.getBounds()+ const state: WindowState = {+ ...win.getNormalBounds(),+ maximized: win.isMaximized(),+ }this.deps.settingsManager- .update({ windowState: { [id]: bounds } })+ .update({ windowState: { [id]: state } }).catch(() => {})}@@ -546,17 +549,22 @@ export class WindowManager {if (!config.persistBounds) returnconst settings = this.deps.settingsManager.get()- const saved = settings.windowState[id] as WindowBounds | undefined+ const saved = settings.windowState[id] as WindowState | undefinedif (!saved) {win.center()return}- if (this.isBoundsVisible(saved)) {- win.setBounds(saved)+ const { maximized = false, ...bounds } = saved+ if (this.isBoundsVisible(bounds)) {+ win.setBounds(bounds)} else {win.center()}++ if (maximized && config.maximizable) {+ win.maximize()+ }}private isBoundsVisible(bounds: WindowBounds): boolean {diff --git a/src/shared/schemas/window-bounds.ts b/src/shared/schemas/window-bounds.tsindex b8e1650b..df318850 100644--- a/src/shared/schemas/window-bounds.ts+++ b/src/shared/schemas/window-bounds.ts@@ -7,6 +7,10 @@ export const windowBoundsSchema = z.object({height: z.number().min(200),})+export const savedWindowStateSchema = windowBoundsSchema.extend({+ maximized: z.boolean().catch(false),+})+export const windowStateSchema = z- .record(z.string(), windowBoundsSchema)+ .record(z.string(), savedWindowStateSchema).catch({})diff --git a/src/shared/types/settings.ts b/src/shared/types/settings.tsindex 6fb1bddb..23b2d5ef 100644--- a/src/shared/types/settings.ts+++ b/src/shared/types/settings.ts@@ -13,6 +13,10 @@ export interface WindowBounds {height: number}+export interface WindowState extends WindowBounds {+ maximized: boolean+}+export interface TrackerSettings {autoSync: booleansyncIntervalHours: number@@ -144,7 +148,7 @@ export interface AppSettings {media: MediaSettingsdashboard: DashboardLayoutSettingsspeedLimit: SpeedLimitSettings- windowState: Record<string, WindowBounds>+ windowState: Record<string, WindowState>}export interface OnboardingState {