fix(popups): close the history and command popups on an outside click or after 15s idle

The popups are non-focusable, so nothing closed them except their own toggle,
Esc or a selection, while they held Enter, arrows, Esc and 0-9 as global
shortcuts. Typing "3" or Enter in another app inserted a history entry or
switched the active command. A click outside the popup (converted from
physical pixels to DIP) or 15s without a navigation key now dismisses it and
releases the keys.
This commit is contained in:
Yun Chan 2026-10-21 11:32:17 +09:00
parent 67cc920e06
commit 06365651fc
3 changed files with 126 additions and 2 deletions

View file

@ -1,7 +1,7 @@
// src/main/bootstrap.ts — 초기화 시퀀스
import { app, dialog, globalShortcut, ipcMain as ipcMainRef, nativeTheme } from 'electron'
import { uIOhook, type UiohookKeyboardEvent } from 'uiohook-napi'
import { app, dialog, globalShortcut, ipcMain as ipcMainRef, nativeTheme, screen, type BrowserWindow } from 'electron'
import { uIOhook, type UiohookKeyboardEvent, type UiohookMouseEvent } from 'uiohook-napi'
import { VK } from '@d3ro/core/keybinding'
import { initLoggerService, getLogger } from './services/LoggerService'
import { initConfigService, configGet, configSet, onConfigChanged } from './services/ConfigService'
@ -43,6 +43,8 @@ import {
hideCommandPopup,
sendKeyToCommandPopup,
isCommandPopupVisible,
getHistoryPopupWindow,
getCommandPopupWindow,
reapplyThemeToAllPopups,
} from './windows/WindowManager'
import { createTray } from './windows/TrayManager'
@ -380,6 +382,15 @@ async function initPopupWindows(): Promise<void> {
const popups = createPopupNavigationController()
getShutdownRegistry().register({ name: 'popup-navigation', dispose: () => popups.dispose() })
// 팝업은 포커스가 없어 blur 가 없다 — 다른 곳을 클릭하면 닫아 전역 Enter·숫자키를 놓게 한다.
const releasePopupClickHook = acquireGlobalInputHook()
getShutdownRegistry().register({ name: 'popup-click-hook', dispose: () => releasePopupClickHook() })
uIOhook.on('mousedown', (event: UiohookMouseEvent) => {
if (!popups.owner) return
// uiohook 은 물리 픽셀, 창 bounds 는 DIP 다(배율 125%·150% 에서 어긋난다).
const physical = { x: event.x, y: event.y }
popups.handlePointerDown(process.platform === 'win32' ? screen.screenToDipPoint(physical) : physical)
})
// 팝업 토글도 재바인딩 가능한 액션이다 — 하드코딩 accelerator 대신 KeyBindingService를 구독한다.
getKeyBindingService().on('triggered', (payload) => {
@ -394,6 +405,11 @@ async function initPopupWindows(): Promise<void> {
setupPopupIPC(popups)
}
function windowContains(win: BrowserWindow, point: { x: number; y: number }): boolean {
const b = win.getBounds()
return point.x >= b.x && point.x < b.x + b.width && point.y >= b.y && point.y < b.y + b.height
}
/** 팝업 컨트롤러를 Electron 창·전역 단축키·서비스 어댑터로 조립한다. */
function createPopupNavigationController(): PopupNavigationController {
return new PopupNavigationController({
@ -406,6 +422,7 @@ function createPopupNavigationController(): PopupNavigationController {
hide: () => hideHistoryPopup(),
isVisible: () => isHistoryPopupVisible(),
sendKey: (key) => sendKeyToHistoryPopup(key),
containsPoint: (point) => windowContains(getHistoryPopupWindow(), point),
},
command: {
show: () => {
@ -416,6 +433,7 @@ function createPopupNavigationController(): PopupNavigationController {
hide: () => hideCommandPopup(),
isVisible: () => isCommandPopupVisible(),
sendKey: (key) => sendKeyToCommandPopup(key),
containsPoint: (point) => windowContains(getCommandPopupWindow(), point),
},
},
shortcuts: {