From 5ab514abdd8da16b7818cc7493c633fa88709cd9 Mon Sep 17 00:00:00 2001 From: jahruz67 Date: Wed, 20 May 2026 15:29:09 -0700 Subject: [PATCH] feat: refactor transcription handling for Linux and non-Linux environments --- app.go | 36 +------------------------------ text_insert_linux.go | 18 ++++++++++++++++ text_insert_nonlinux.go | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 35 deletions(-) create mode 100644 text_insert_linux.go create mode 100644 text_insert_nonlinux.go diff --git a/app.go b/app.go index 0be7f96..fc629b1 100644 --- a/app.go +++ b/app.go @@ -374,32 +374,7 @@ func (a *App) processRecording(recordingPath string) { wailsruntime.EventsEmit(a.ctx, "history:updated") } - if len(refinedText) < 50 { - // Type short text directly to avoid clipboard interference - robotgo.TypeStr(refinedText) - } else { - // Save old clipboard - oldClip, clipErr := wailsruntime.ClipboardGetText(a.ctx) - - // Copy to clipboard - wailsruntime.ClipboardSetText(a.ctx, refinedText) - - // Paste - a.pasteText() - - // Restore old clipboard after a short delay, but ONLY if the user - // hasn't manually copied something else or another burst hasn't finished. - if clipErr == nil && oldClip != "" { - go func() { - time.Sleep(1000 * time.Millisecond) - current, _ := wailsruntime.ClipboardGetText(a.ctx) - if current == refinedText { - wailsruntime.ClipboardSetText(a.ctx, oldClip) - logger.Info("Clipboard history restored") - } - }() - } - } + a.insertTranscription(refinedText) // Clean up the recording file if removeErr := os.Remove(recordingPath); removeErr != nil { @@ -415,15 +390,6 @@ func (a *App) processRecording(recordingPath string) { } } -// pasteText simulates Ctrl+V to paste from clipboard -func (a *App) pasteText() { - // Give a substantial delay for Linux GTK clipboard sync - time.Sleep(200 * time.Millisecond) - - // Simulate Ctrl+V using modern robotgo API - robotgo.KeyTap("v", "ctrl") -} - // GetSettings returns the current configuration func (a *App) GetSettings() map[string]interface{} { conf := make(map[string]interface{}) diff --git a/text_insert_linux.go b/text_insert_linux.go new file mode 100644 index 0000000..b07271f --- /dev/null +++ b/text_insert_linux.go @@ -0,0 +1,18 @@ +//go:build linux + +package main + +import ( + "unicode/utf8" + + "wis-free-v3/internal/logger" + + "github.com/go-vgo/robotgo" +) + +func (a *App) insertTranscription(text string) { + // Avoid synthetic Ctrl+V on Linux; desktop environments can interpret it + // together with lingering shortcut modifiers and open global UI instead. + logger.Info("Typing transcription directly on Linux (%d chars)", utf8.RuneCountInString(text)) + robotgo.TypeStr(text) +} diff --git a/text_insert_nonlinux.go b/text_insert_nonlinux.go new file mode 100644 index 0000000..9372289 --- /dev/null +++ b/text_insert_nonlinux.go @@ -0,0 +1,48 @@ +//go:build !linux + +package main + +import ( + "time" + + "wis-free-v3/internal/logger" + + "github.com/go-vgo/robotgo" + wailsruntime "github.com/wailsapp/wails/v2/pkg/runtime" +) + +func (a *App) insertTranscription(text string) { + if len(text) < 50 { + // Type short text directly to avoid clipboard interference + robotgo.TypeStr(text) + return + } + + // Save old clipboard + oldClip, clipErr := wailsruntime.ClipboardGetText(a.ctx) + + // Copy to clipboard + wailsruntime.ClipboardSetText(a.ctx, text) + + // Paste + a.pasteText() + + // Restore old clipboard after a short delay, but ONLY if the user + // hasn't manually copied something else or another burst hasn't finished. + if clipErr == nil && oldClip != "" { + go func() { + time.Sleep(1000 * time.Millisecond) + current, _ := wailsruntime.ClipboardGetText(a.ctx) + if current == text { + wailsruntime.ClipboardSetText(a.ctx, oldClip) + logger.Info("Clipboard history restored") + } + }() + } +} + +// pasteText simulates Ctrl+V to paste from clipboard +func (a *App) pasteText() { + time.Sleep(200 * time.Millisecond) + robotgo.KeyTap("v", "ctrl") +}