d3ro-voice/apps/desktop/src/main/services/global-input-hook.ts
Yun Chan 5c11ee2fde
Some checks failed
deploy-site / deploy (push) Failing after 33s
portable-unsigned / portable-windows (push) Failing after 4m7s
release / release-windows (push) Failing after 3m16s
release: ship v1.5.0 with on-device writing suggestions
Adds next-sentence suggestions while typing, weekly input insights and a
personal phrase memory to the desktop app, and fixes custom instructions so
they process the text instead of inserting the instruction's own wording.
Local model requests are now bounded and individually cancellable.

Bumps the product version to 1.5.0 (Android/iOS build 1050000), refreshes the
landing and web download links, and records the new INPUT feature rows and the
open verification gaps in the infrastructure map.
2026-09-23 16:04:27 +09:00

69 lines
No EOL
1.9 KiB
TypeScript

// src/main/services/global-input-hook.ts
// uiohook 글로벌 후킹의 소유권을 참조 카운트로 관리한다.
//
// uiohook 은 프로세스 전역 싱글턴이다. KeyBindingService InputTelemetryService 가
// 각자 start()/stop() 을 부르면 두 번째 start() 는 무시되거나, 먼저 끝난 쪽의 stop() 이
// 상대방 수신까지 죽인다. 그래서 "후킹이 켜져 있어야 하는 소비자 수"를 세고
// 0 이 될 때만 실제로 춘다.
import { uIOhook } from 'uiohook-napi'
import { getLogger } from './LoggerService'
const logger = getLogger('GlobalInputHook')
let refCount = 0
let running = false
/**
* 글로벌 후킹을 (필요하면) 시작하고 해제 함수를 돌려준다.
*
* 반드시 반환된 함수를 호출해야 한다. 시작에 실패하면 예외를 던지고 카운트를 되돌린다.
*/
export function acquireGlobalInputHook(): () => void {
refCount += 1
if (!running) {
try {
uIOhook.start()
running = true
logger.info('uiohook started (global input hook active)')
} catch (error) {
refCount = Math.max(0, refCount - 1)
throw error
}
}
let released = false
return () => {
if (released) return
released = true
refCount = Math.max(0, refCount - 1)
if (refCount === 0 && running) {
try {
uIOhook.stop()
logger.info('uiohook stopped (no consumer left)')
} catch (error) {
logger.error(
`Failed to stop uiohook: ${error instanceof Error ? error.message : String(error)}`
)
} finally {
running = false
}
}
}
}
export function isGlobalInputHookRunning(): boolean {
return running
}
export function getGlobalInputHookRefCount(): number {
return refCount
}
/** 테스트 전용 — 모듈 상태 초기화. */
export function resetGlobalInputHookForTests(): void {
refCount = 0
running = false
}