Files
wisp-open/linux_press_daemon.go
John Doe 5b6e39c5e8 Refactor Linux hotkey handling and improve installation process
- Removed the legacy HTTP daemon for handling hotkey presses on Linux, replacing it with a simpler command-based approach using `--action=toggle`.
- Updated the build script to support non-interactive installation for CI environments with the `--no-install` flag.
- Enhanced the ydotool setup process to prefer distribution-provided systemd units and improved error messages for missing dependencies.
- Changed the way active window titles are retrieved on Linux to avoid using robotgo, which can fail on Wayland.
- Updated README and frontend hints to clarify the use of GlobalShortcuts portal and fallback commands for Linux.
- Improved package building scripts to allow building only Debian or RPM packages based on command-line flags.
- Adjusted the text insertion logic to handle different versions of ydotool more robustly.
2026-07-10 14:58:25 -07:00

60 lines
1.8 KiB
Go

//go:build linux
// Linux shortcut compatibility helpers.
//
// Older releases used a loopback HTTP server for the `--press` command. That
// made a normal desktop shortcut unreliable: a second key press inside the
// hold-detection window could be mistaken for key auto-repeat, and another
// local process could occupy the fixed TCP port. Linux already has a
// per-user Unix socket for single-instance IPC, so use that authenticated
// per-user path instead.
package main
import (
"os"
"strings"
)
func init() {
// Keep `--press` working for existing custom shortcuts. A desktop shortcut
// invokes a command once, so its correct, predictable behaviour is toggle
// (start on the first press and stop on the next), not push-to-talk.
if hasPressFlag(os.Args[1:]) {
if tryNotifyRunningInstanceAction("toggle") {
os.Exit(0)
}
// Do not launch a second GUI process from this legacy helper. The current
// settings UI emits --action=toggle, which can start the app if needed.
os.Exit(1)
}
}
func hasPressFlag(args []string) bool {
for _, arg := range args {
if arg == "--press" {
return true
}
}
return false
}
// linuxShortcutCommand returns a shell-safe command for GNOME/KDE custom
// shortcuts. Quote the executable because user home directories can contain
// spaces or shell metacharacters.
func linuxShortcutCommand(executable string) string {
return linuxShellQuote(executable) + " --action=toggle"
}
func linuxShellQuote(value string) string {
if value == "" {
return "''"
}
return "'" + strings.ReplaceAll(value, "'", "'\\''") + "'"
}
// The old daemon API remains a no-op so the common lifecycle code and
// non-Linux stub stay simple. Shortcut delivery now uses the instance socket.
func (a *App) startLinuxPressDaemon() {}
func stopLinuxPressDaemon() {}