mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
Merge branch 'main' of https://github.com/jahruz67/wisp-open
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync/atomic"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"wis-free-v3/internal/audio/recorder"
|
"wis-free-v3/internal/audio/recorder"
|
||||||
@@ -90,6 +90,7 @@ func (a *App) startup(ctx context.Context) {
|
|||||||
|
|
||||||
// Initialize components
|
// Initialize components
|
||||||
a.startupHeadless()
|
a.startupHeadless()
|
||||||
|
a.startLinuxPressDaemon()
|
||||||
|
|
||||||
// When the user launches the app again while it is already running (tray-only),
|
// When the user launches the app again while it is already running (tray-only),
|
||||||
// the second process signals us here so the settings window becomes visible.
|
// the second process signals us here so the settings window becomes visible.
|
||||||
@@ -338,7 +339,6 @@ func (a *App) processRecording(recordingPath string) {
|
|||||||
transcribeDuration := time.Since(startTranscribe)
|
transcribeDuration := time.Since(startTranscribe)
|
||||||
logger.Info("Transcription completed in %v", transcribeDuration)
|
logger.Info("Transcription completed in %v", transcribeDuration)
|
||||||
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Transcription failed: %v", err)
|
logger.Error("Transcription failed: %v", err)
|
||||||
tray.UpdateStatus("Ready")
|
tray.UpdateStatus("Ready")
|
||||||
@@ -380,14 +380,14 @@ func (a *App) processRecording(recordingPath string) {
|
|||||||
} else {
|
} else {
|
||||||
// Save old clipboard
|
// Save old clipboard
|
||||||
oldClip, clipErr := wailsruntime.ClipboardGetText(a.ctx)
|
oldClip, clipErr := wailsruntime.ClipboardGetText(a.ctx)
|
||||||
|
|
||||||
// Copy to clipboard
|
// Copy to clipboard
|
||||||
wailsruntime.ClipboardSetText(a.ctx, refinedText)
|
wailsruntime.ClipboardSetText(a.ctx, refinedText)
|
||||||
|
|
||||||
// Paste
|
// Paste
|
||||||
a.pasteText()
|
a.pasteText()
|
||||||
|
|
||||||
// Restore old clipboard after a short delay, but ONLY if the user
|
// Restore old clipboard after a short delay, but ONLY if the user
|
||||||
// hasn't manually copied something else or another burst hasn't finished.
|
// hasn't manually copied something else or another burst hasn't finished.
|
||||||
if clipErr == nil && oldClip != "" {
|
if clipErr == nil && oldClip != "" {
|
||||||
go func() {
|
go func() {
|
||||||
@@ -437,6 +437,12 @@ func (a *App) GetSettings() map[string]interface{} {
|
|||||||
conf["history"] = a.config.History
|
conf["history"] = a.config.History
|
||||||
conf["startup"] = platform.IsInStartup()
|
conf["startup"] = platform.IsInStartup()
|
||||||
conf["app_version"] = AppVersion
|
conf["app_version"] = AppVersion
|
||||||
|
if runtime.GOOS == "linux" {
|
||||||
|
if exePath, err := os.Executable(); err == nil {
|
||||||
|
conf["linux_press_command"] = exePath + " --press"
|
||||||
|
}
|
||||||
|
conf["linux_press_mode"] = true
|
||||||
|
}
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,35 +451,37 @@ func (a *App) SaveSettings(settings map[string]interface{}) string {
|
|||||||
if val, ok := settings["api_key"].(string); ok {
|
if val, ok := settings["api_key"].(string); ok {
|
||||||
a.config.APIKey = val
|
a.config.APIKey = val
|
||||||
}
|
}
|
||||||
if val, ok := settings["shortcut"].(string); ok {
|
if runtime.GOOS != "linux" {
|
||||||
_, _, modOnly, ok := hotkey.ParseShortcut(val)
|
if val, ok := settings["shortcut"].(string); ok {
|
||||||
if !ok {
|
_, _, modOnly, ok := hotkey.ParseShortcut(val)
|
||||||
logger.Error("Invalid shortcut: %s (rejected)", val)
|
if !ok {
|
||||||
return "Invalid shortcut - use modifiers plus a key (e.g. ctrl+k), or modifier-only on Windows (e.g. ctrl+win)"
|
logger.Error("Invalid shortcut: %s (rejected)", val)
|
||||||
}
|
return "Invalid shortcut - use modifiers plus a key (e.g. ctrl+k), or modifier-only on Windows (e.g. ctrl+win)"
|
||||||
if modOnly && runtime.GOOS != "windows" {
|
}
|
||||||
return "Modifier-only shortcuts (like ctrl+win) are only supported on Windows"
|
if modOnly && runtime.GOOS != "windows" {
|
||||||
}
|
return "Modifier-only shortcuts (like ctrl+win) are only supported on Windows"
|
||||||
|
}
|
||||||
|
|
||||||
a.config.Shortcut = val
|
a.config.Shortcut = val
|
||||||
// Update existing listener with new shortcut (hot-swap)
|
// Update existing listener with new shortcut (hot-swap)
|
||||||
if a.hotkeyListener != nil {
|
if a.hotkeyListener != nil {
|
||||||
a.hotkeyListener.UpdateShortcut(val)
|
a.hotkeyListener.UpdateShortcut(val)
|
||||||
} else {
|
} else {
|
||||||
// Should not happen if app started correctly, but just in case
|
// Should not happen if app started correctly, but just in case
|
||||||
a.hotkeyListener = hotkey.NewListener(val, a.StartRecording, a.StopRecording)
|
a.hotkeyListener = hotkey.NewListener(val, a.StartRecording, a.StopRecording)
|
||||||
if runtime.GOOS != "windows" {
|
if runtime.GOOS != "windows" {
|
||||||
a.hotkeyListener.SetRegistrationErrorCallback(func(err error) {
|
a.hotkeyListener.SetRegistrationErrorCallback(func(err error) {
|
||||||
logger.Error("Linux hotkey registration failed: %v", err)
|
logger.Error("Linux hotkey registration failed: %v", err)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
if a.overlay != nil {
|
if a.overlay != nil {
|
||||||
a.overlay.Show("Shortcut registration failed. Please add a custom system shortcut calling 'wis-free-v3 --action=toggle' as a fallback.")
|
a.overlay.Show("Shortcut registration failed. Please add a custom system shortcut calling 'wis-free-v3 --action=toggle' as a fallback.")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
a.hotkeyListener.Start()
|
||||||
}
|
}
|
||||||
a.hotkeyListener.Start()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if val, ok := settings["whisper_model"].(string); ok {
|
if val, ok := settings["whisper_model"].(string); ok {
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+7
-6
@@ -43,18 +43,19 @@
|
|||||||
|
|
||||||
<div class="section-group-label">Input</div>
|
<div class="section-group-label">Input</div>
|
||||||
|
|
||||||
<!-- Shortcut -->
|
<!-- Linux Wayland Hotkey Command -->
|
||||||
<div class="section">
|
<div class="section" id="linuxPressSection" style="display: none;">
|
||||||
<label>Hotkey</label>
|
<label>System Hotkey Command (Linux)</label>
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<div class="flex-row">
|
<div class="flex-row">
|
||||||
<div class="input-wrapper">
|
<div class="input-wrapper">
|
||||||
<input type="text" id="shortcutInput" placeholder="Click Record to set..." readonly>
|
<input type="text" id="linuxPressCommand" readonly>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="recordShortcut()" id="recordBtn">Record</button>
|
<button onclick="copyLinuxPressCommand()">Copy</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">Click Record, then press your desired key combination (e.g. Ctrl+X).</p>
|
<p class="hint">GNOME: Settings -> Keyboard -> Custom Shortcuts -> Add a shortcut using the copied command.</p>
|
||||||
|
<p class="hint">KDE: System Settings -> Shortcuts -> Command/URL -> Add a shortcut using the copied command.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Microphone -->
|
<!-- Microphone -->
|
||||||
|
|||||||
+7
-6
@@ -41,18 +41,19 @@
|
|||||||
|
|
||||||
<div class="section-group-label">Input</div>
|
<div class="section-group-label">Input</div>
|
||||||
|
|
||||||
<!-- Shortcut -->
|
<!-- Linux Wayland Hotkey Command -->
|
||||||
<div class="section">
|
<div class="section" id="linuxPressSection" style="display: none;">
|
||||||
<label>Hotkey</label>
|
<label>System Hotkey Command (Linux)</label>
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<div class="flex-row">
|
<div class="flex-row">
|
||||||
<div class="input-wrapper">
|
<div class="input-wrapper">
|
||||||
<input type="text" id="shortcutInput" placeholder="Click Record to set..." readonly>
|
<input type="text" id="linuxPressCommand" readonly>
|
||||||
</div>
|
</div>
|
||||||
<button onclick="recordShortcut()" id="recordBtn">Record</button>
|
<button onclick="copyLinuxPressCommand()">Copy</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p class="hint">Click Record, then press your desired key combination (e.g. Ctrl+X).</p>
|
<p class="hint">GNOME: Settings -> Keyboard -> Custom Shortcuts -> Add a shortcut with the copied command.</p>
|
||||||
|
<p class="hint">KDE: System Settings -> Shortcuts -> Command/URL -> Add a shortcut with the copied command.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Microphone -->
|
<!-- Microphone -->
|
||||||
|
|||||||
+25
-16
@@ -24,12 +24,18 @@ async function loadSettings() {
|
|||||||
|
|
||||||
// Populate fields
|
// Populate fields
|
||||||
document.getElementById('apiKey').value = settings.api_key || '';
|
document.getElementById('apiKey').value = settings.api_key || '';
|
||||||
document.getElementById('shortcutInput').value = settings.shortcut || 'alt+z';
|
|
||||||
document.getElementById('whisperModel').value = settings.whisper_model || 'whisper-large-v3-turbo';
|
document.getElementById('whisperModel').value = settings.whisper_model || 'whisper-large-v3-turbo';
|
||||||
document.getElementById('aiModel').value = settings.ai_model || 'llama-3.3-70b-versatile';
|
document.getElementById('aiModel').value = settings.ai_model || 'llama-3.3-70b-versatile';
|
||||||
document.getElementById('aiPrompt').value = settings.ai_prompt || '';
|
document.getElementById('aiPrompt').value = settings.ai_prompt || '';
|
||||||
document.getElementById('startupToggle').checked = settings.startup || false;
|
document.getElementById('startupToggle').checked = settings.startup || false;
|
||||||
|
|
||||||
|
if (settings.linux_press_mode) {
|
||||||
|
const section = document.getElementById('linuxPressSection');
|
||||||
|
const cmdInput = document.getElementById('linuxPressCommand');
|
||||||
|
if (section) section.style.display = 'block';
|
||||||
|
if (cmdInput) cmdInput.value = settings.linux_press_command || '';
|
||||||
|
}
|
||||||
|
|
||||||
// Load history
|
// Load history
|
||||||
renderHistory(settings.history || []);
|
renderHistory(settings.history || []);
|
||||||
|
|
||||||
@@ -123,25 +129,28 @@ async function saveApiKey() {
|
|||||||
showToast('API Key saved');
|
showToast('API Key saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save Shortcut
|
|
||||||
async function saveShortcut() {
|
|
||||||
const shortcut = document.getElementById('shortcutInput').value.trim().toLowerCase();
|
|
||||||
|
|
||||||
if (!shortcut) {
|
async function copyLinuxPressCommand() {
|
||||||
alert('Please enter a shortcut');
|
const cmdInput = document.getElementById('linuxPressCommand');
|
||||||
return;
|
if (!cmdInput) return;
|
||||||
|
|
||||||
|
const command = cmdInput.value || '';
|
||||||
|
try {
|
||||||
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||||
|
await navigator.clipboard.writeText(command);
|
||||||
|
} else {
|
||||||
|
cmdInput.focus();
|
||||||
|
cmdInput.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
}
|
||||||
|
showToast('Command copied');
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to copy Linux command:', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
const parts = shortcut.split('+');
|
|
||||||
if (parts.length < 2) {
|
|
||||||
alert('Shortcut must have a modifier + key (e.g., ctrl+x)');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await saveSetting('shortcut', shortcut);
|
|
||||||
showToast('Shortcut saved: ' + shortcut);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.copyLinuxPressCommand = copyLinuxPressCommand;
|
||||||
|
|
||||||
// Save Whisper Model
|
// Save Whisper Model
|
||||||
async function saveWhisperModel() {
|
async function saveWhisperModel() {
|
||||||
const model = document.getElementById('whisperModel').value;
|
const model = document.getElementById('whisperModel').value;
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const linuxPressAddr = "127.0.0.1:9876"
|
||||||
|
|
||||||
|
var (
|
||||||
|
linuxPressMu sync.Mutex
|
||||||
|
linuxPressTimer *time.Timer
|
||||||
|
linuxPressRecording bool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
if hasPressFlag(os.Args[1:]) {
|
||||||
|
if err := sendLinuxPressPing(); err != nil {
|
||||||
|
_ = exec.Command("notify-send", "Voice App", "Please open the main application first").Run()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasPressFlag(args []string) bool {
|
||||||
|
for _, arg := range args {
|
||||||
|
if arg == "--press" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendLinuxPressPing() error {
|
||||||
|
client := &http.Client{Timeout: 300 * time.Millisecond}
|
||||||
|
resp, err := client.Get("http://" + linuxPressAddr + "/press")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) startLinuxPressDaemon() {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("/press", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
linuxPressMu.Lock()
|
||||||
|
defer linuxPressMu.Unlock()
|
||||||
|
|
||||||
|
if !linuxPressRecording {
|
||||||
|
linuxPressRecording = true
|
||||||
|
go a.StartRecording()
|
||||||
|
}
|
||||||
|
|
||||||
|
if linuxPressTimer != nil {
|
||||||
|
linuxPressTimer.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
linuxPressTimer = time.AfterFunc(300*time.Millisecond, func() {
|
||||||
|
linuxPressMu.Lock()
|
||||||
|
defer linuxPressMu.Unlock()
|
||||||
|
if linuxPressRecording {
|
||||||
|
linuxPressRecording = false
|
||||||
|
go a.StopRecording()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
_ = http.ListenAndServe(linuxPressAddr, mux)
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func (a *App) startLinuxPressDaemon() {}
|
||||||
Reference in New Issue
Block a user