Skip to content

fix(desktop): resolve window maximize, titlebar interactions, and keyboard shortcut leaks#154

Open
AI-fullcup wants to merge 1 commit into
Sherlockouo:devfrom
AI-fullcup:fix-window-maximize-and-shortcuts
Open

fix(desktop): resolve window maximize, titlebar interactions, and keyboard shortcut leaks#154
AI-fullcup wants to merge 1 commit into
Sherlockouo:devfrom
AI-fullcup:fix-window-maximize-and-shortcuts

Conversation

@AI-fullcup

Copy link
Copy Markdown
Contributor

This PR bundles three closely related fixes in the Electron main process and window interactions.

Fixes #99: Titlebar double-click maximize behavior

Problem:

  • Double-clicking interactive buttons (navigation, search, settings, avatar) in the topbar accidentally toggles window maximize because the event bubbles up to TopbarDesktop's onDoubleClick handler.
  • Conversely, double-clicking the empty titlebar area was often unresponsive because app-region-drag swallows events on Windows frameless windows, while the fallback onDoubleClick only fires on app-region-no-drag children.
  • Under the hood, the restore logic in ipcMain.ts had the width/height swapped and passed width twice to setSize().

Changes:

  • TopbarDesktop.tsx: Added e.stopPropagation() on the left and right interactive containers so button double-clicks no longer maximize the window.
  • ipcMain.ts: Fixed unMaximizeSize = { width: size[0], height: size[1] } (was size[1], size[0]) and corrected win.setSize(width, height).

Fixes implicit bug: Broken maximize state synchronization

Problem:
ipcMain.ts manually tracked isMaximized with a local boolean. This easily desynchronizes when the user maximizes the window via OS shortcuts (e.g. Win+↑) or edge snapping. The stale state then caused wrong restore behavior and confusing IPC replies.

Changes:

  • Replaced the manual isMaximized variable with win.isMaximized() everywhere.
  • Removed the erroneous isMaximized = !isMaximized inside MinimizeOrUnminimize; minimizing a window has nothing to do with its maximized state and was corrupting the UI.

Fixes #74: Global keyboard shortcuts failing and leaking memory

Problem:

  • keyboardShortcuts.ts added focus/blur listeners on win but attempted to remove them from webContexts, so they were never unregistered. Every window recreate leaks two listeners on the main process, eventually making shortcuts sluggish or dead.
  • formatForAccelerator() can return null, but the code used a non-null assertion (!) and fed it straight into globalShortcut.register(null), which throws an uncaught exception and can kill the shortcut subsystem.

Changes:

  • Corrected removeListener target from webContexts to win.
  • Introduced safeRegister() with explicit null checks and try/catch around every globalShortcut.register call.

Testing notes:

  • Window maximize/restore via titlebar double-click and window controls works correctly on Windows.
  • Restored window dimensions match the pre-maximize size.
  • Global shortcuts can be toggled and rebound without leaking listeners or crashing the main process.

…board shortcut leaks

- Fix Sherlockouo#99: titlebar double-click maximize behavior
  - Stop propagation of double-click events on interactive buttons in TopbarDesktop
    to prevent accidental maximize when double-clicking navigation/search/avatar.
  - Fix swapped width/height in ipcMain.ts when saving/restoring unmaximize size.
  - Remove erroneous second width argument in win.setSize().

- Fix implicit bug: remove manual isMaximized state in main process
  - Use win.isMaximized() directly so the renderer always sees the real window state.
  - This also fixes minimize/unminimize incorrectly toggling the maximized flag.

- Fix Sherlockouo#74: global keyboard shortcuts failing and leaking memory
  - Correct removeListener target from webContexts to win in keyboardShortcuts.ts.
  - Add safeRegister wrapper with null-check and try-catch to prevent crashes
    when formatForAccelerator returns null or the shortcut is invalid.

Fixes Sherlockouo#99
Fixes Sherlockouo#74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

标题栏双击最大化问题 快捷键失效

1 participant