fix(suggestion): place overlay in DIPs, size it to content, and harden suggestion sessions
This commit is contained in:
parent
75e053d72f
commit
9e5b94ced2
18 changed files with 2178 additions and 558 deletions
|
|
@ -5,7 +5,17 @@ import { app, BrowserWindow, screen, ipcMain, Menu, clipboard } from 'electron'
|
|||
import { join } from 'path'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
import { WINDOW_SIZE } from '@d3ro/core/constants'
|
||||
import { anchorFloatingPanel, type AnchorKind } from '@d3ro/core/input-intelligence'
|
||||
import type { AnchorKind, PhysicalRect } from '@d3ro/core/input-intelligence'
|
||||
import {
|
||||
fitAnchoredPanel,
|
||||
placeAnchoredPanel,
|
||||
placeNearCursor,
|
||||
type AnchoredPanelPlacement,
|
||||
type DipPoint,
|
||||
type ScreenGeometryPort,
|
||||
type UiRect,
|
||||
type UiSize
|
||||
} from '@d3ro/core/popup-placement'
|
||||
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
|
||||
import {
|
||||
formatBindingSegments,
|
||||
|
|
@ -18,26 +28,22 @@ import { getLogger } from '../services/LoggerService'
|
|||
import { getIsQuitting, setIsQuitting } from '../lifecycle'
|
||||
import { hardenWebContents } from './web-contents-hardening'
|
||||
import { configGet, configSet } from '../services/ConfigService'
|
||||
import { buildPopupThemeCss } from '@d3ro/ui/theme-vars'
|
||||
import { getI18n } from '@d3ro/i18n'
|
||||
import {
|
||||
createPopupWindow,
|
||||
injectPopupTheme,
|
||||
presentPopup,
|
||||
sendToPopupWindow
|
||||
} from './popup-window-factory'
|
||||
import { createElectronScreenGeometry } from './screen-geometry'
|
||||
import {
|
||||
SUGGESTION_OVERLAY_MAX_HEIGHT,
|
||||
SUGGESTION_OVERLAY_WIDTH,
|
||||
suggestionPanelHeight
|
||||
} from './suggestion-overlay-geometry'
|
||||
|
||||
const logger = getLogger('WindowManager')
|
||||
|
||||
// ── 팝업 테마 주입 ────────────────────────────────────────
|
||||
/**
|
||||
* 팝업 BrowserWindow에 현재 설정 테마의 CSS 변수를 insertCSS로 주입.
|
||||
* did-finish-load 이후 호출해야 한다.
|
||||
*/
|
||||
function injectPopupTheme(win: BrowserWindow): void {
|
||||
const theme = configGet('theme') as string
|
||||
// 'system'은 'dark'로 폴백 (팝업은 시스템 다크모드 감지 불가)
|
||||
const resolvedTheme = theme === 'system' ? 'dark' : theme
|
||||
const css = buildPopupThemeCss(resolvedTheme)
|
||||
win.webContents.insertCSS(css).catch((err: unknown) => {
|
||||
logger.warn('팝업 테마 CSS 주입 실패', err)
|
||||
})
|
||||
}
|
||||
|
||||
// ── 팝업 i18n 문자열 가져오기 ─────────────────────────────
|
||||
/**
|
||||
* 팝업에 주입할 i18n 문자열 맵을 반환.
|
||||
|
|
@ -161,97 +167,25 @@ function buildSuggestionKeyHints(): SuggestionKeyHints {
|
|||
}
|
||||
}
|
||||
|
||||
// ── Popup window lifecycle ────────────────────────────
|
||||
// ── 화면 기하 (DIP) ───────────────────────────────────
|
||||
// 팝업 창 생성·수명주기·표시는 popup-window-factory, 배치 정책은 core popup-placement 가 정본이다.
|
||||
|
||||
/** Popup windows whose renderer finished loading and can receive IPC */
|
||||
const popupReady = new WeakSet<BrowserWindow>()
|
||||
/** IPC messages held back until the popup renderer is ready */
|
||||
const pendingPopupMessages = new WeakMap<BrowserWindow, Array<{ channel: string; data: unknown }>>()
|
||||
let screenGeometry: ScreenGeometryPort | null = null
|
||||
|
||||
/**
|
||||
* Promote popup renderer console output and load failures into the main log.
|
||||
* Popups have no renderer logging otherwise, so a missing asset or a script
|
||||
* exception stays invisible and the popup just renders static markup.
|
||||
*/
|
||||
function hookPopupDiagnostics(win: BrowserWindow, name: string): void {
|
||||
win.webContents.on('console-message', (_event, level, message, line, sourceId) => {
|
||||
logger.info(`[${name}] [Renderer] [${level}] ${message} (${sourceId}:${line})`)
|
||||
})
|
||||
win.webContents.on('did-fail-load', (_event, errorCode, errorDescription, validatedURL) => {
|
||||
logger.error(`[${name}] renderer load failed [${errorCode}] ${errorDescription} (${validatedURL})`)
|
||||
})
|
||||
win.webContents.on('render-process-gone', (_event, details) => {
|
||||
logger.error(`[${name}] renderer process gone: ${details.reason} (exitCode=${details.exitCode})`)
|
||||
})
|
||||
/** Electron screen 은 app ready 뒤에만 쓸 수 있다 — 처음 배치할 때 만든다. */
|
||||
function getScreenGeometry(): ScreenGeometryPort {
|
||||
if (!screenGeometry) screenGeometry = createElectronScreenGeometry(screen)
|
||||
return screenGeometry
|
||||
}
|
||||
|
||||
/**
|
||||
* Deliver IPC to a popup even while its renderer is still loading.
|
||||
* webContents.send before load is silently dropped, which leaves popups stuck
|
||||
* on their initial markup (for example a frozen 0:00 timer).
|
||||
*/
|
||||
function sendToPopupWindow(win: BrowserWindow, channel: string, data: unknown): void {
|
||||
if (win.isDestroyed() || win.webContents.isDestroyed()) return
|
||||
|
||||
if (popupReady.has(win)) {
|
||||
win.webContents.send(channel, data)
|
||||
return
|
||||
}
|
||||
|
||||
const queue = pendingPopupMessages.get(win) ?? []
|
||||
queue.push({ channel, data })
|
||||
if (queue.length > 32) {
|
||||
queue.splice(0, queue.length - 32)
|
||||
}
|
||||
pendingPopupMessages.set(win, queue)
|
||||
}
|
||||
|
||||
function flushPopupMessages(win: BrowserWindow): void {
|
||||
popupReady.add(win)
|
||||
|
||||
const queue = pendingPopupMessages.get(win)
|
||||
if (!queue || queue.length === 0) return
|
||||
|
||||
pendingPopupMessages.delete(win)
|
||||
for (const message of queue) {
|
||||
if (!win.isDestroyed() && !win.webContents.isDestroyed()) {
|
||||
win.webContents.send(message.channel, message.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Shared popup lifecycle: diagnostics + load tracking + theme injection */
|
||||
function attachPopupLifecycle(win: BrowserWindow, name: string): void {
|
||||
hookPopupDiagnostics(win, name)
|
||||
|
||||
win.webContents.on('did-start-loading', () => {
|
||||
popupReady.delete(win)
|
||||
})
|
||||
|
||||
win.webContents.on('did-finish-load', () => {
|
||||
injectPopupTheme(win)
|
||||
flushPopupMessages(win)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a popup without stealing focus, reliably on every call.
|
||||
* After hide(), showInactive() can lose z-order and repaint, so popups stopped
|
||||
* appearing from the second show onward: re-assert topmost and force a repaint.
|
||||
*/
|
||||
function presentPopup(win: BrowserWindow, level?: 'floating' | 'screen-saver'): void {
|
||||
if (!win.isVisible()) {
|
||||
win.showInactive()
|
||||
}
|
||||
|
||||
// Z-order/repaint adjustments must never break a capture session.
|
||||
try {
|
||||
win.setAlwaysOnTop(true, level)
|
||||
win.moveTop()
|
||||
win.webContents.invalidate()
|
||||
} catch (err) {
|
||||
logger.warn(`Popup present adjustment failed: ${err instanceof Error ? err.message : String(err)}`)
|
||||
}
|
||||
/** 커서 기준 배치 (녹음 팁 · 결과 · 기록 · 명령 팝업 공통) — 커서와 작업 영역 모두 DIP. */
|
||||
function placePopupNearCursor(
|
||||
win: BrowserWindow,
|
||||
size: UiSize,
|
||||
cursor: DipPoint = getScreenGeometry().cursor()
|
||||
): void {
|
||||
const position = placeNearCursor(cursor, size, getScreenGeometry().workAreaNear(cursor))
|
||||
win.setBounds({ x: position.x, y: position.y, width: size.width, height: size.height })
|
||||
}
|
||||
|
||||
// ── 윈도우 참조 ───────────────────────────────────────
|
||||
|
|
@ -392,39 +326,13 @@ export function createMainWindow(): BrowserWindow {
|
|||
// ── RecordingTip 팝업 ─────────────────────────────────
|
||||
|
||||
function createRecordingTipWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: WINDOW_SIZE.RECORDING_TIP.width,
|
||||
height: WINDOW_SIZE.RECORDING_TIP.height,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
backgroundThrottling: false
|
||||
return createPopupWindow({
|
||||
name: 'recording-tip',
|
||||
bounds: { width: WINDOW_SIZE.RECORDING_TIP.width, height: WINDOW_SIZE.RECORDING_TIP.height },
|
||||
onClosed: () => {
|
||||
recordingTipWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/recording-tip/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/recording-tip/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'recording-tip')
|
||||
|
||||
win.on('closed', () => {
|
||||
recordingTipWindow = null
|
||||
})
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
export function getRecordingTipWindow(): BrowserWindow {
|
||||
|
|
@ -451,23 +359,8 @@ export function showRecordingTip(
|
|||
): void {
|
||||
const win = getRecordingTipWindow()
|
||||
|
||||
// 커서 위치에 배치
|
||||
const cursorPos = screen.getCursorScreenPoint()
|
||||
const display = screen.getDisplayNearestPoint(cursorPos)
|
||||
|
||||
let x = cursorPos.x - Math.round(TIP_WIDTH / 2)
|
||||
let y = cursorPos.y - TIP_HEIGHT - 20
|
||||
|
||||
// 화면 밖 보정
|
||||
x = Math.max(display.workArea.x, Math.min(x, display.workArea.x + display.workArea.width - TIP_WIDTH))
|
||||
if (y < display.workArea.y) {
|
||||
y = cursorPos.y + 20
|
||||
}
|
||||
if (y + TIP_HEIGHT > display.workArea.y + display.workArea.height) {
|
||||
y = Math.max(display.workArea.y, display.workArea.y + display.workArea.height - TIP_HEIGHT)
|
||||
}
|
||||
|
||||
win.setBounds({ x, y, width: TIP_WIDTH, height: TIP_HEIGHT })
|
||||
// 커서 위치에 배치 (화면 밖 보정 포함)
|
||||
placePopupNearCursor(win, { width: TIP_WIDTH, height: TIP_HEIGHT })
|
||||
|
||||
// 상태 전송 후 즉시 show (2-phase 제거 — 숨겨진 윈도우의 렌더러 비활성 문제 방지)
|
||||
sendToPopupWindow(win, IPC_CHANNELS.WINDOW.TIP_STATE_CHANGED, { state, _i18n: getPopupI18nStrings(), ...params })
|
||||
|
|
@ -506,38 +399,14 @@ export function sendPartialTranscriptToTip(text: string): void {
|
|||
// ── ResultPopup 팝업 ──────────────────────────────────
|
||||
|
||||
function createResultPopupWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: WINDOW_SIZE.RESULT_POPUP.width,
|
||||
height: WINDOW_SIZE.RESULT_POPUP.height,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false
|
||||
return createPopupWindow({
|
||||
name: 'result-popup',
|
||||
bounds: { width: WINDOW_SIZE.RESULT_POPUP.width, height: WINDOW_SIZE.RESULT_POPUP.height },
|
||||
onClosed: () => {
|
||||
cancelPendingResultShow()
|
||||
resultPopupWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/result-popup/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/result-popup/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'result-popup')
|
||||
|
||||
win.on('closed', () => {
|
||||
resultPopupWindow = null
|
||||
})
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
export function getResultPopupWindow(): BrowserWindow {
|
||||
|
|
@ -548,39 +417,96 @@ export function getResultPopupWindow(): BrowserWindow {
|
|||
return resultPopupWindow
|
||||
}
|
||||
|
||||
/**
|
||||
* 측정이 오지 않을 때 기다리는 한도.
|
||||
*
|
||||
* 숨긴 창에서는 렌더러의 requestAnimationFrame 이 멈출 수 있어 측정(result:measured)이 영영
|
||||
* 오지 않았다 — 두 번째 삽입 실패부터 받아쓴 텍스트를 볼 방법이 없었다. 한도가 지나면 기본
|
||||
* 크기로 그대로 보여준다.
|
||||
*/
|
||||
const RESULT_MEASURE_TIMEOUT_MS = 400
|
||||
|
||||
interface PendingResultShow {
|
||||
autoHideMs: number
|
||||
cursor: DipPoint
|
||||
fallbackTimer: NodeJS.Timeout
|
||||
}
|
||||
|
||||
let pendingResultShow: PendingResultShow | null = null
|
||||
/** 마지막 표시의 커서 — 한도 뒤 늦게 도착한 측정으로 크기만 고칠 때 쓴다 */
|
||||
let lastResultCursor: DipPoint | null = null
|
||||
|
||||
function cancelPendingResultShow(): void {
|
||||
if (!pendingResultShow) return
|
||||
clearTimeout(pendingResultShow.fallbackTimer)
|
||||
pendingResultShow = null
|
||||
}
|
||||
|
||||
function isMeasuredSize(data: unknown): data is UiSize {
|
||||
if (data === null || typeof data !== 'object') return false
|
||||
const { width, height } = data as Record<string, unknown>
|
||||
return (
|
||||
typeof width === 'number' &&
|
||||
typeof height === 'number' &&
|
||||
Number.isFinite(width) &&
|
||||
Number.isFinite(height) &&
|
||||
width > 0 &&
|
||||
height > 0
|
||||
)
|
||||
}
|
||||
|
||||
/** Phase 2: 측정 크기(없으면 현재 크기)로 배치를 마무리하고 내용을 보인다. */
|
||||
function finishResultShow(measured: UiSize | null): void {
|
||||
const pending = pendingResultShow
|
||||
if (!pending) return
|
||||
cancelPendingResultShow()
|
||||
const win = resultPopupWindow
|
||||
if (!win || win.isDestroyed()) return
|
||||
if (measured) placePopupNearCursor(win, measured, pending.cursor)
|
||||
presentPopup(win)
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_RESULT.SHOW, { autoHideMs: pending.autoHideMs })
|
||||
}
|
||||
|
||||
/**
|
||||
* ResultPopup 표시 (2-phase 리사이즈)
|
||||
*
|
||||
* Phase 1: 기본 크기로 커서 곁에 먼저 띄운다 — 내용은 SHOW 전까지 투명하다. 창이 보여야
|
||||
* 렌더러가 측정 프레임을 돈다(숨긴 창의 rAF 정지 방지).
|
||||
* Phase 2: 측정이 오면(또는 한도가 지나면) 크기를 맞추고 내용을 보인다.
|
||||
* 측정 응답은 모듈 단일 리스너가 받는다 — 호출마다 ipcMain.once 를 쌓지 않는다.
|
||||
*/
|
||||
export function showResultPopup(text: string, autoHideMs = 5000): void {
|
||||
const win = getResultPopupWindow()
|
||||
cancelPendingResultShow()
|
||||
|
||||
const cursor = getScreenGeometry().cursor()
|
||||
lastResultCursor = cursor
|
||||
placePopupNearCursor(
|
||||
win,
|
||||
{ width: WINDOW_SIZE.RESULT_POPUP.width, height: WINDOW_SIZE.RESULT_POPUP.height },
|
||||
cursor
|
||||
)
|
||||
|
||||
// Phase 1: prepare
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_RESULT.PREPARE, { text, _i18n: getPopupI18nStrings() })
|
||||
presentPopup(win)
|
||||
|
||||
ipcMain.once(IPC_CHANNELS.POPUP_RESULT.MEASURED, (_event, data: { width: number; height: number }) => {
|
||||
const cursorPos = screen.getCursorScreenPoint()
|
||||
const display = screen.getDisplayNearestPoint(cursorPos)
|
||||
|
||||
let x = cursorPos.x - Math.round(data.width / 2)
|
||||
let y = cursorPos.y - data.height - 20
|
||||
|
||||
x = Math.max(display.workArea.x, Math.min(x, display.workArea.x + display.workArea.width - data.width))
|
||||
if (y < display.workArea.y) {
|
||||
y = cursorPos.y + 20
|
||||
}
|
||||
if (y + data.height > display.workArea.y + display.workArea.height) {
|
||||
y = Math.max(display.workArea.y, display.workArea.y + display.workArea.height - data.height)
|
||||
}
|
||||
|
||||
win.setBounds({ x, y, width: data.width, height: data.height })
|
||||
|
||||
presentPopup(win)
|
||||
|
||||
// Phase 2: show
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_RESULT.SHOW, { autoHideMs })
|
||||
})
|
||||
const fallbackTimer = setTimeout(() => finishResultShow(null), RESULT_MEASURE_TIMEOUT_MS)
|
||||
fallbackTimer.unref?.()
|
||||
pendingResultShow = { autoHideMs, cursor, fallbackTimer }
|
||||
}
|
||||
|
||||
ipcMain.on(IPC_CHANNELS.POPUP_RESULT.MEASURED, (event: Electron.IpcMainEvent, data: unknown) => {
|
||||
const win = resultPopupWindow
|
||||
if (!win || win.isDestroyed() || event.sender !== win.webContents) return
|
||||
if (!isMeasuredSize(data)) return
|
||||
if (pendingResultShow) {
|
||||
finishResultShow(data)
|
||||
return
|
||||
}
|
||||
// 한도 뒤에 늦게 도착한 측정 — 이미 보이는 팝업의 크기만 맞춘다.
|
||||
if (win.isVisible() && lastResultCursor) placePopupNearCursor(win, data, lastResultCursor)
|
||||
})
|
||||
|
||||
export function hideResultPopup(): void {
|
||||
if (resultPopupWindow && !resultPopupWindow.isDestroyed()) {
|
||||
resultPopupWindow.hide()
|
||||
|
|
@ -590,38 +516,13 @@ export function hideResultPopup(): void {
|
|||
// ── HistoryPopup 팝업 ─────────────────────────────────
|
||||
|
||||
function createHistoryPopupWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: 360,
|
||||
height: 400,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false
|
||||
return createPopupWindow({
|
||||
name: 'history-popup',
|
||||
bounds: { width: 360, height: 400 },
|
||||
onClosed: () => {
|
||||
historyPopupWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/history-popup/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/history-popup/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'history-popup')
|
||||
|
||||
win.on('closed', () => {
|
||||
historyPopupWindow = null
|
||||
})
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
export function getHistoryPopupWindow(): BrowserWindow {
|
||||
|
|
@ -636,21 +537,7 @@ export function showHistoryPopup(entries: Array<Record<string, unknown>>): void
|
|||
const win = getHistoryPopupWindow()
|
||||
|
||||
// 커서 위치에 즉시 배치+표시 (2-phase 제거 — 숨겨진 윈도우 렌더러 비활성 문제 방지)
|
||||
const cursorPos = screen.getCursorScreenPoint()
|
||||
const display = screen.getDisplayNearestPoint(cursorPos)
|
||||
|
||||
const popupWidth = 380
|
||||
const popupHeight = Math.min(60 + entries.length * 44, 500)
|
||||
|
||||
let x = cursorPos.x - Math.round(popupWidth / 2)
|
||||
let y = cursorPos.y - popupHeight - 20
|
||||
|
||||
x = Math.max(display.workArea.x, Math.min(x, display.workArea.x + display.workArea.width - popupWidth))
|
||||
if (y < display.workArea.y) {
|
||||
y = cursorPos.y + 20
|
||||
}
|
||||
|
||||
win.setBounds({ x, y, width: popupWidth, height: popupHeight })
|
||||
placePopupNearCursor(win, { width: 380, height: Math.min(60 + entries.length * 44, 500) })
|
||||
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_HISTORY.SHOW_ITEMS, { entries, _i18n: getPopupI18nStrings() })
|
||||
|
||||
|
|
@ -683,35 +570,13 @@ export function isHistoryPopupVisible(): boolean {
|
|||
// ── CommandPopup 팝업 ─────────────────────────────────
|
||||
|
||||
function createCommandPopupWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: 340,
|
||||
height: 300,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false
|
||||
return createPopupWindow({
|
||||
name: 'command-popup',
|
||||
bounds: { width: 340, height: 300 },
|
||||
onClosed: () => {
|
||||
commandPopupWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/command-popup/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/command-popup/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'command-popup')
|
||||
|
||||
win.on('closed', () => { commandPopupWindow = null })
|
||||
return win
|
||||
}
|
||||
|
||||
export function getCommandPopupWindow(): BrowserWindow {
|
||||
|
|
@ -723,19 +588,7 @@ export function getCommandPopupWindow(): BrowserWindow {
|
|||
|
||||
export function showCommandPopup(commands: Array<Record<string, unknown>>, activeId: string | null): void {
|
||||
const win = getCommandPopupWindow()
|
||||
const cursorPos = screen.getCursorScreenPoint()
|
||||
const display = screen.getDisplayNearestPoint(cursorPos)
|
||||
|
||||
const popupWidth = 340
|
||||
const popupHeight = Math.min(80 + commands.length * 48, 400)
|
||||
|
||||
let x = cursorPos.x - Math.round(popupWidth / 2)
|
||||
let y = cursorPos.y - popupHeight - 20
|
||||
|
||||
x = Math.max(display.workArea.x, Math.min(x, display.workArea.x + display.workArea.width - popupWidth))
|
||||
if (y < display.workArea.y) { y = cursorPos.y + 20 }
|
||||
|
||||
win.setBounds({ x, y, width: popupWidth, height: popupHeight })
|
||||
placePopupNearCursor(win, { width: 340, height: Math.min(80 + commands.length * 48, 400) })
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_COMMAND.SHOW_ITEMS, { commands, activeId, _i18n: getPopupI18nStrings() })
|
||||
|
||||
presentPopup(win)
|
||||
|
|
@ -793,42 +646,17 @@ function initialCaptionOverlayBounds(): Electron.Rectangle {
|
|||
}
|
||||
|
||||
function createCaptionOverlayWindow(): BrowserWindow {
|
||||
const bounds = initialCaptionOverlayBounds()
|
||||
|
||||
const win = new BrowserWindow({
|
||||
...bounds,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false
|
||||
return createPopupWindow({
|
||||
name: 'caption-overlay',
|
||||
bounds: initialCaptionOverlayBounds(),
|
||||
// 표시 중에는 항상 보이는 창이다 — 기존 기본값(늦춤)을 유지한다.
|
||||
backgroundThrottling: true,
|
||||
// 클릭 통과: 마우스 이벤트를 무시하되, CSS hover 등을 위해 forward 활성화
|
||||
beforeLoad: (win) => win.setIgnoreMouseEvents(true, { forward: true }),
|
||||
onClosed: () => {
|
||||
captionOverlayWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
// 클릭 통과: 마우스 이벤트를 무시하되, CSS hover 등을 위해 forward 활성화
|
||||
win.setIgnoreMouseEvents(true, { forward: true })
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/caption-overlay/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/caption-overlay/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'caption-overlay')
|
||||
|
||||
win.on('closed', () => {
|
||||
captionOverlayWindow = null
|
||||
})
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
export function getCaptionOverlayWindow(): BrowserWindow {
|
||||
|
|
@ -916,21 +744,18 @@ export function resetCaptionOverlayPosition(): void {
|
|||
if (win && !win.isDestroyed()) win.setBounds(defaultCaptionOverlayBounds())
|
||||
}
|
||||
|
||||
// ── SuggestionOverlay 업 (입력 인텔리전스) ──────────
|
||||
// ── SuggestionOverlay (입력 인텔리전스) ──────────────
|
||||
|
||||
/**
|
||||
* 다음 문장 제안 ghost text 오버레이.
|
||||
*
|
||||
* IME 후보창과 같은 관례를 따른다: 케어/포커스 요소 바로 아래에 붙고,
|
||||
* 포커스를 막지 않으며(focusable:false) 기본은 클릭 통과다.
|
||||
* IME 후보창과 같은 관례를 따른다: 캐럿/포커스 요소 바로 아래에 붙고,
|
||||
* 포커스를 막지 않는다(focusable:false).
|
||||
* (KeyType.Windows 의 WS_EX_TRANSPARENT|WS_EX_NOACTIVATE 오버레이와 동일한 전략)
|
||||
*
|
||||
* 창은 그려진 패널 높이만큼만 둔다(suggestionPanelHeight). 투명 영역도 클릭을 삼키므로,
|
||||
* 고정 높이 창은 "준비 중" 한 줄만 보일 때 캐럿 아래 줄의 클릭을 가로챘다.
|
||||
*/
|
||||
const SUGGESTION_OVERLAY_WIDTH = 460
|
||||
/**
|
||||
* 한 페이지(3개 × 고정 44px) + 진행률 줄 + 키 안내 줄이 스크롤 없이 들어가는 높이.
|
||||
* style.css 고정 치수로 렌더링해 잰 값(패널 하단 204 + root 패딩 4) — CSS 를 바꾸면 다시 잰다.
|
||||
*/
|
||||
const SUGGESTION_OVERLAY_HEIGHT = 208
|
||||
|
||||
function applySuggestionOverlayMouseMode(win: BrowserWindow): void {
|
||||
const interactive = configGet('suggestionOverlayInteractive') !== false
|
||||
|
|
@ -949,41 +774,16 @@ function applySuggestionOverlayMouseMode(win: BrowserWindow): void {
|
|||
}
|
||||
|
||||
function createSuggestionOverlayWindow(): BrowserWindow {
|
||||
const win = new BrowserWindow({
|
||||
width: SUGGESTION_OVERLAY_WIDTH,
|
||||
height: SUGGESTION_OVERLAY_HEIGHT,
|
||||
show: false,
|
||||
frame: false,
|
||||
transparent: true,
|
||||
resizable: false,
|
||||
alwaysOnTop: true,
|
||||
skipTaskbar: true,
|
||||
focusable: false,
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/popup.js'),
|
||||
sandbox: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegration: false,
|
||||
backgroundThrottling: false
|
||||
return createPopupWindow({
|
||||
name: 'suggestion-overlay',
|
||||
bounds: { width: SUGGESTION_OVERLAY_WIDTH, height: SUGGESTION_OVERLAY_MAX_HEIGHT },
|
||||
beforeLoad: applySuggestionOverlayMouseMode,
|
||||
onClosed: () => {
|
||||
suggestionOverlayPlacement = null
|
||||
suggestionOverlayBounds = null
|
||||
suggestionOverlayWindow = null
|
||||
}
|
||||
})
|
||||
hardenWebContents(win)
|
||||
|
||||
applySuggestionOverlayMouseMode(win)
|
||||
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
win.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/popups/suggestion-overlay/index.html`)
|
||||
} else {
|
||||
win.loadFile(join(__dirname, '../renderer/popups/suggestion-overlay/index.html'))
|
||||
}
|
||||
|
||||
attachPopupLifecycle(win, 'suggestion-overlay')
|
||||
|
||||
win.on('closed', () => {
|
||||
suggestionOverlayWindow = null
|
||||
})
|
||||
|
||||
return win
|
||||
}
|
||||
|
||||
export function getSuggestionOverlayWindow(): BrowserWindow {
|
||||
|
|
@ -1016,37 +816,72 @@ interface SuggestionOverlayContent {
|
|||
provenance?: SuggestionOverlayProvenance | null
|
||||
}
|
||||
|
||||
/** 제안 오버레이 표시 — 커(케어 → 요소 → 커서) 기준 배치. */
|
||||
/** 현재 세션의 배치(최대 높이 기준) — 내용이 바뀌면 이 자리에서 높이만 맞춘다. */
|
||||
let suggestionOverlayPlacement: AnchoredPanelPlacement | null = null
|
||||
let suggestionOverlayBounds: UiRect | null = null
|
||||
|
||||
function sameRect(a: UiRect | null, b: UiRect): boolean {
|
||||
return !!a && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height
|
||||
}
|
||||
|
||||
/**
|
||||
* 내용 높이에 맞춰 창 크기를 고친다. 늘어날 때는 내용보다 먼저(잘림 방지),
|
||||
* 줄어들 때는 내용 다음에(`deliver` 뒤) 적용한다.
|
||||
*/
|
||||
function fitSuggestionOverlay(win: BrowserWindow, content: SuggestionOverlayContent, deliver: () => void): void {
|
||||
const placement = suggestionOverlayPlacement
|
||||
if (!placement) {
|
||||
deliver()
|
||||
return
|
||||
}
|
||||
const bounds = fitAnchoredPanel(
|
||||
placement,
|
||||
suggestionPanelHeight({
|
||||
candidateCount: content.candidates.length,
|
||||
activeIndex: content.activeIndex,
|
||||
generating: content.generating === true,
|
||||
warmingUp: content.warmingUp === true,
|
||||
hasPartialText: !!content.partialText
|
||||
})
|
||||
)
|
||||
const previous = suggestionOverlayBounds
|
||||
const apply = (): void => {
|
||||
if (sameRect(suggestionOverlayBounds, bounds)) return
|
||||
suggestionOverlayBounds = bounds
|
||||
win.setBounds(bounds)
|
||||
}
|
||||
if (!previous || bounds.height >= previous.height) {
|
||||
apply()
|
||||
deliver()
|
||||
} else {
|
||||
deliver()
|
||||
apply()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 제안 오버레이 표시 — 캐럿 → 요소 → 커서 기준 배치.
|
||||
*
|
||||
* anchor 는 UIA 가 준 물리 픽셀이다. 화면 기하 포트로 한 번만 DIP 로 바꾼 뒤 모니터를 고르고
|
||||
* 배치한다(서비스에는 DIP 를 저장하지 않는다 — 이중 변환 방지).
|
||||
*/
|
||||
export function showSuggestionOverlay(
|
||||
payload: SuggestionOverlayContent & {
|
||||
anchor: { x: number; y: number; width: number; height: number } | null
|
||||
anchor: PhysicalRect | null
|
||||
anchorKind?: AnchorKind
|
||||
appName: string | null
|
||||
}
|
||||
): void {
|
||||
const win = getSuggestionOverlayWindow()
|
||||
const cursor = screen.getCursorScreenPoint()
|
||||
const anchorPoint = payload.anchor
|
||||
? { x: payload.anchor.x, y: payload.anchor.y + payload.anchor.height }
|
||||
: cursor
|
||||
const display = screen.getDisplayNearestPoint(anchorPoint)
|
||||
|
||||
const position = anchorFloatingPanel(
|
||||
suggestionOverlayPlacement = placeAnchoredPanel(
|
||||
getScreenGeometry(),
|
||||
payload.anchor,
|
||||
payload.anchorKind ?? null,
|
||||
cursor,
|
||||
{ width: SUGGESTION_OVERLAY_WIDTH, height: SUGGESTION_OVERLAY_HEIGHT },
|
||||
display.workArea
|
||||
{ width: SUGGESTION_OVERLAY_WIDTH, height: SUGGESTION_OVERLAY_MAX_HEIGHT }
|
||||
)
|
||||
suggestionOverlayBounds = null
|
||||
|
||||
win.setBounds({
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
width: SUGGESTION_OVERLAY_WIDTH,
|
||||
height: SUGGESTION_OVERLAY_HEIGHT
|
||||
})
|
||||
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_SUGGESTION.SHOW, {
|
||||
fitSuggestionOverlay(win, payload, () => sendToPopupWindow(win, IPC_CHANNELS.POPUP_SUGGESTION.SHOW, {
|
||||
candidates: payload.candidates,
|
||||
activeIndex: payload.activeIndex,
|
||||
targetTotal: payload.targetTotal ?? payload.candidates.length,
|
||||
|
|
@ -1057,22 +892,27 @@ export function showSuggestionOverlay(
|
|||
provenance: payload.provenance ?? null,
|
||||
_i18n: getPopupI18nStrings(),
|
||||
_keyHints: buildSuggestionKeyHints()
|
||||
})
|
||||
}))
|
||||
|
||||
presentPopup(win, 'screen-saver')
|
||||
}
|
||||
|
||||
export function updateSuggestionOverlay(payload: SuggestionOverlayContent): void {
|
||||
if (suggestionOverlayWindow && !suggestionOverlayWindow.isDestroyed()) {
|
||||
sendToPopupWindow(suggestionOverlayWindow, IPC_CHANNELS.POPUP_SUGGESTION.UPDATE, {
|
||||
...payload,
|
||||
targetTotal: payload.targetTotal ?? payload.candidates.length,
|
||||
_keyHints: buildSuggestionKeyHints()
|
||||
})
|
||||
const win = suggestionOverlayWindow
|
||||
if (win && !win.isDestroyed()) {
|
||||
fitSuggestionOverlay(win, payload, () =>
|
||||
sendToPopupWindow(win, IPC_CHANNELS.POPUP_SUGGESTION.UPDATE, {
|
||||
...payload,
|
||||
targetTotal: payload.targetTotal ?? payload.candidates.length,
|
||||
_keyHints: buildSuggestionKeyHints()
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function hideSuggestionOverlay(): void {
|
||||
suggestionOverlayPlacement = null
|
||||
suggestionOverlayBounds = null
|
||||
if (suggestionOverlayWindow && !suggestionOverlayWindow.isDestroyed()) {
|
||||
sendToPopupWindow(suggestionOverlayWindow, IPC_CHANNELS.POPUP_SUGGESTION.HIDE, {})
|
||||
suggestionOverlayWindow.hide()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue