-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
refactor: Decompose App.tsx and standardize frontend component architecture #1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 5 commits
c958fae
931c9f3
1ce4c22
126cbb8
fb265e3
8e38722
b9e50e4
c479467
bb83399
377df70
9c34bdf
6fdddb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { ipcMain, BrowserWindow } from 'electron'; | ||
| import { IPC_CHANNELS } from '../../shared/constants/ipc'; | ||
|
|
||
| export function registerWindowHandlers(getMainWindow: () => BrowserWindow | null): void { | ||
| ipcMain.handle(IPC_CHANNELS.WINDOW_MINIMIZE, () => { | ||
| getMainWindow()?.minimize(); | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.WINDOW_MAXIMIZE, () => { | ||
| const win = getMainWindow(); | ||
| if (!win) return false; | ||
| if (win.isMaximized()) win.unmaximize(); | ||
| else win.maximize(); | ||
| return win.isMaximized(); | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.WINDOW_CLOSE, () => { | ||
| getMainWindow()?.close(); | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.WINDOW_IS_MAXIMIZED, () => { | ||
| return getMainWindow()?.isMaximized() ?? false; | ||
| }); | ||
|
|
||
| ipcMain.handle(IPC_CHANNELS.WINDOW_GET_BOUNDS, () => { | ||
| return getMainWindow()?.getBounds() ?? null; | ||
| }); | ||
|
|
||
| // Uses ipcMain.on (fire-and-forget) instead of handle/invoke to avoid | ||
| // round-trip overhead during rapid resize/move events. | ||
| ipcMain.on(IPC_CHANNELS.WINDOW_SET_BOUNDS, (_event, bounds: { x: number; y: number; width: number; height: number }) => { | ||
| const win = getMainWindow(); | ||
| if (win) { | ||
| const [minW, minH] = win.getMinimumSize(); | ||
| win.setBounds({ | ||
| x: bounds.x, | ||
| y: bounds.y, | ||
| width: Math.max(bounds.width, minW), | ||
| height: Math.max(bounds.height, minH), | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| console.warn('[IPC] Window control handlers registered'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Use This is a normal startup event, not a warning. Per the ESLint config in this repo, Proposed fix- console.warn('[IPC] Window control handlers registered');
+ // If electron-log is available, use log.debug instead
+ console.debug('[IPC] Window control handlers registered');🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { ipcRenderer } from 'electron'; | ||
| import { IPC_CHANNELS } from '../../shared/constants/ipc'; | ||
|
|
||
| export interface WindowBounds { | ||
| x: number; | ||
| y: number; | ||
| width: number; | ||
| height: number; | ||
| } | ||
|
|
||
| export interface WindowAPI { | ||
| minimize: () => Promise<void>; | ||
| maximize: () => Promise<boolean>; | ||
| close: () => Promise<void>; | ||
| isMaximized: () => Promise<boolean>; | ||
| getBounds: () => Promise<WindowBounds | null>; | ||
| setBounds: (bounds: WindowBounds) => void; | ||
| onMaximizeChanged: (callback: (isMaximized: boolean) => void) => () => void; | ||
| } | ||
|
|
||
| export const createWindowAPI = (): WindowAPI => ({ | ||
| minimize: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_MINIMIZE), | ||
| maximize: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_MAXIMIZE), | ||
| close: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_CLOSE), | ||
| isMaximized: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_IS_MAXIMIZED), | ||
| getBounds: () => ipcRenderer.invoke(IPC_CHANNELS.WINDOW_GET_BOUNDS), | ||
| setBounds: (bounds) => ipcRenderer.send(IPC_CHANNELS.WINDOW_SET_BOUNDS, bounds), | ||
| onMaximizeChanged: (callback) => { | ||
| const handler = (_event: Electron.IpcRendererEvent, isMaximized: boolean) => callback(isMaximized); | ||
| ipcRenderer.on(IPC_CHANNELS.WINDOW_MAXIMIZE_CHANGED, handler); | ||
| return () => ipcRenderer.removeListener(IPC_CHANNELS.WINDOW_MAXIMIZE_CHANGED, handler); | ||
| } | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.