d3ro-voice/apps/desktop/src/main/ipc/window-handlers.ts

53 lines
1.7 KiB
TypeScript

// src/main/ipc/window-handlers.ts
import { ipcMain } from 'electron'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
import { ErrorCode, ipcError, ipcSuccess } from '@d3ro/core/errors'
import { getMainWindow, hideResultPopup, hideRecordingTip } from '../windows/WindowManager'
import { isTrustedIpcSender, openExternalSafe } from '../windows/web-contents-hardening'
export function registerWindowHandlers(): void {
ipcMain.on(IPC_CHANNELS.WINDOW.MINIMIZE, () => {
getMainWindow()?.minimize()
})
ipcMain.on(IPC_CHANNELS.WINDOW.MAXIMIZE, () => {
const win = getMainWindow()
if (win) {
if (win.isMaximized()) {
win.unmaximize()
} else {
win.maximize()
}
}
})
ipcMain.on(IPC_CHANNELS.WINDOW.CLOSE, () => {
getMainWindow()?.close()
})
ipcMain.handle(IPC_CHANNELS.WINDOW.IS_MAXIMIZED, async () => {
return ipcSuccess(getMainWindow()?.isMaximized() ?? false)
})
// 팝업 윈도우 hide 요청 (렌더러 → 메인)
ipcMain.on(IPC_CHANNELS.WINDOW.HIDE_RESULT_POPUP, () => {
hideResultPopup()
})
ipcMain.on(IPC_CHANNELS.WINDOW.HIDE_RECORDING_TIP, () => {
hideRecordingTip()
})
// 외부 URL 열기 — 앱 페이지가 보낸 요청만, 허용 scheme(https/mailto)만 연다.
ipcMain.handle(IPC_CHANNELS.SYSTEM.OPEN_EXTERNAL, async (event, params: { url: string }) => {
if (!isTrustedIpcSender(event)) {
return ipcError(ErrorCode.ConfigInvalidValue, 'openExternal: untrusted sender')
}
const url = typeof params?.url === 'string' ? params.url : ''
if (!(await openExternalSafe(url))) {
return ipcError(ErrorCode.ConfigInvalidValue, 'openExternal: URL scheme not allowed')
}
return ipcSuccess(undefined)
})
}