Remove stale shortcut recorder code from built frontend asset

This commit is contained in:
jahruz67
2026-05-19 20:51:28 -07:00
parent e8745f926c
commit c4739dc38c
7 changed files with 167 additions and 60 deletions
+10 -2
View File
@@ -6,8 +6,8 @@ import (
"os"
"path/filepath"
"runtime"
"sync/atomic"
"strings"
"sync/atomic"
"time"
"wis-free-v3/internal/audio/recorder"
@@ -90,6 +90,7 @@ func (a *App) startup(ctx context.Context) {
// Initialize components
a.startupHeadless()
a.startLinuxPressDaemon()
// 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.
@@ -338,7 +339,6 @@ func (a *App) processRecording(recordingPath string) {
transcribeDuration := time.Since(startTranscribe)
logger.Info("Transcription completed in %v", transcribeDuration)
if err != nil {
logger.Error("Transcription failed: %v", err)
tray.UpdateStatus("Ready")
@@ -437,6 +437,12 @@ func (a *App) GetSettings() map[string]interface{} {
conf["history"] = a.config.History
conf["startup"] = platform.IsInStartup()
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
}
@@ -445,6 +451,7 @@ func (a *App) SaveSettings(settings map[string]interface{}) string {
if val, ok := settings["api_key"].(string); ok {
a.config.APIKey = val
}
if runtime.GOOS != "linux" {
if val, ok := settings["shortcut"].(string); ok {
_, _, modOnly, ok := hotkey.ParseShortcut(val)
if !ok {
@@ -476,6 +483,7 @@ func (a *App) SaveSettings(settings map[string]interface{}) string {
a.hotkeyListener.Start()
}
}
}
if val, ok := settings["whisper_model"].(string); ok {
a.config.WhisperModel = val
}
File diff suppressed because one or more lines are too long
+7 -6
View File
@@ -43,18 +43,19 @@
<div class="section-group-label">Input</div>
<!-- Shortcut -->
<div class="section">
<label>Hotkey</label>
<!-- Linux Wayland Hotkey Command -->
<div class="section" id="linuxPressSection" style="display: none;">
<label>System Hotkey Command (Linux)</label>
<div class="form-control">
<div class="flex-row">
<div class="input-wrapper">
<input type="text" id="shortcutInput" placeholder="Click Record to set..." readonly>
<input type="text" id="linuxPressCommand" readonly>
</div>
<button onclick="recordShortcut()" id="recordBtn">Record</button>
<button onclick="copyLinuxPressCommand()">Copy</button>
</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>
<!-- Microphone -->
+7 -6
View File
@@ -41,18 +41,19 @@
<div class="section-group-label">Input</div>
<!-- Shortcut -->
<div class="section">
<label>Hotkey</label>
<!-- Linux Wayland Hotkey Command -->
<div class="section" id="linuxPressSection" style="display: none;">
<label>System Hotkey Command (Linux)</label>
<div class="form-control">
<div class="flex-row">
<div class="input-wrapper">
<input type="text" id="shortcutInput" placeholder="Click Record to set..." readonly>
<input type="text" id="linuxPressCommand" readonly>
</div>
<button onclick="recordShortcut()" id="recordBtn">Record</button>
<button onclick="copyLinuxPressCommand()">Copy</button>
</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>
<!-- Microphone -->
+24 -15
View File
@@ -24,12 +24,18 @@ async function loadSettings() {
// Populate fields
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('aiModel').value = settings.ai_model || 'llama-3.3-70b-versatile';
document.getElementById('aiPrompt').value = settings.ai_prompt || '';
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
renderHistory(settings.history || []);
@@ -123,25 +129,28 @@ async function saveApiKey() {
showToast('API Key saved');
}
// Save Shortcut
async function saveShortcut() {
const shortcut = document.getElementById('shortcutInput').value.trim().toLowerCase();
if (!shortcut) {
alert('Please enter a shortcut');
return;
async function copyLinuxPressCommand() {
const cmdInput = document.getElementById('linuxPressCommand');
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');
}
const parts = shortcut.split('+');
if (parts.length < 2) {
alert('Shortcut must have a modifier + key (e.g., ctrl+x)');
return;
showToast('Command copied');
} catch (err) {
console.error('Failed to copy Linux command:', err);
}
await saveSetting('shortcut', shortcut);
showToast('Shortcut saved: ' + shortcut);
}
window.copyLinuxPressCommand = copyLinuxPressCommand;
// Save Whisper Model
async function saveWhisperModel() {
const model = document.getElementById('whisperModel').value;
+83
View File
@@ -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)
}()
}
+5
View File
@@ -0,0 +1,5 @@
//go:build !linux
package main
func (a *App) startLinuxPressDaemon() {}