diff --git a/apps/desktop/src/main/services/TextInsertService.ts b/apps/desktop/src/main/services/TextInsertService.ts index 52fdc69..0179fac 100644 --- a/apps/desktop/src/main/services/TextInsertService.ts +++ b/apps/desktop/src/main/services/TextInsertService.ts @@ -123,7 +123,8 @@ class TextInsertService extends EventEmitter { } /** - * 클립보드 방식: save → set → Ctrl+V → restore (Speakly 패턴) + * 클립보드 방식: save → set → Cmd/Ctrl+V → restore (Speakly 패턴) + * macOS는 ⌘+V, Windows/Linux는 Ctrl+V로 분기. */ private async _insertViaClipboard(text: string): Promise { // 1. 기존 클립보드 저장 @@ -134,24 +135,22 @@ class TextInsertService extends EventEmitter { // 2. 클립보드에 텍스트 설정 clipboard.writeText(text) - // 3. Ctrl+V 시뮬레이션 + // 짧은 지연: 일부 앱이 클립보드 변경을 받아들일 시간 필요 + await this._sleep(20) + + // 3. Paste 단축키 시뮬레이션 — 플랫폼별 modifier const nut = await this._ensureNut() - await nut.pressKey(nut.Key.LeftControl, nut.Key.V) - await nut.releaseKey(nut.Key.LeftControl, nut.Key.V) + const pasteModKey = + process.platform === 'darwin' ? nut.Key.LeftSuper : nut.Key.LeftControl - // 4. 붙여넣기 완료 대기 - await this._sleep(150) + await nut.pressKey(pasteModKey, nut.Key.V) + await nut.releaseKey(nut.Key.V, pasteModKey) - // 4.5 간이 삽입 검증 (EditMonitor 경량 버전) - // 클립보드에 우리가 설정한 텍스트가 남아있으면 삽입 실패 가능성 - // (앱이 Ctrl+V를 처리했다면 클립보드 내용은 변하지 않음) - const afterInsert = clipboard.readText() - if (afterInsert === text) { - // 클립보드가 그대로 → 정상 (앱이 붙여넣기함) - logger.debug('Insert verification: clipboard unchanged (normal)') - } + // 4. 붙여넣기 완료 대기 — 앱이 paste 이벤트를 처리할 시간 + // macOS는 비동기 처리가 좀 더 느린 경우가 있어 250ms로 잡음 + await this._sleep(process.platform === 'darwin' ? 250 : 150) - // 5. 클립보드 복원 + // 5. 클립보드 복원 (원래 내용으로 되돌림) this.restoreClipboard(snapshot) this.emit('clipboard-restored', {}) } catch (error) {