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.
This commit is contained in:
John Doe
2026-07-10 14:58:25 -07:00
parent 26022d67fb
commit 5b6e39c5e8
11 changed files with 392 additions and 378 deletions
+49 -11
View File
@@ -55,18 +55,50 @@ func typeLinuxTextWithYdotool(text string) error {
return err
}
fastArgs := []string{"type", "-d", "1", "--file", "-"}
if err := runLinuxInputCommand(path, fastArgs, text, linuxTextTyperTimeout(text), socketPath); err == nil {
return nil
timeout := linuxTextTyperTimeout(text)
// ydotool has changed option parsing across releases. Use stdin to avoid
// shell quoting and argument-size issues, but keep a direct-argument
// fallback for older packages whose `type --file` support is incomplete.
attempts := [][]string{
{"type", "-d", "1", "--file", "-"},
{"type", "-f", "-"},
{"type", "--file", "-"},
}
var lastErr error
for _, args := range attempts {
if err := runLinuxInputCommand(path, args, text, timeout, socketPath); err == nil {
return nil
} else {
lastErr = err
}
}
return runLinuxInputCommand(path, []string{"type", "--file", "-"}, text, linuxTextTyperTimeout(text), socketPath)
// Do not turn a leading dash into an option. Transcriptions are normally
// small enough for argv and exec.Command passes this value without a shell.
if text != "" && !strings.HasPrefix(text, "-") && !strings.ContainsRune(text, '\x00') {
if err := runLinuxInputCommand(path, []string{"type", text}, "", timeout, socketPath); err == nil {
return nil
} else {
lastErr = err
}
}
return lastErr
}
func getYdotoolCommand() (string, string, error) {
path, err := exec.LookPath("ydotool")
if err != nil {
return "", "", errors.New("ydotool not found; install ydotool and start the ydotool user service")
for _, candidate := range []string{"/usr/local/bin/ydotool", "/usr/bin/ydotool"} {
if info, statErr := os.Stat(candidate); statErr == nil && !info.IsDir() && info.Mode()&0111 != 0 {
path = candidate
err = nil
break
}
}
if err != nil {
return "", "", errors.New("ydotool not found; install ydotool and start its user service")
}
}
socketPath, err := getYdotoolSocketPath()
@@ -89,10 +121,10 @@ func linuxYdotoolStatus() map[string]interface{} {
"sudo apt install ydotool # Debian/Ubuntu",
"sudo dnf install ydotool # Fedora",
"sudo pacman -S ydotool # Arch",
"echo 'KERNEL==\"uinput\", SUBSYSTEM==\"misc\", TAG+=\"uaccess\", OPTIONS+=\"static_node=uinput\"' | sudo tee /etc/udev/rules.d/80-uinput.rules",
"sudo udevadm control --reload-rules && sudo udevadm trigger",
"# Distribution packages normally provide the uinput rule and service:",
"systemctl --user enable --now ydotool.service",
"# Restart your computer, then open WIS Free V3 again.",
"# If the socket is still missing, log out and back in, then run:",
"systemctl --user restart ydotool.service",
},
}
@@ -129,17 +161,23 @@ func getYdotoolSocketPath() (string, error) {
return "", fmt.Errorf("YDOTOOL_SOCKET is set but not accessible: %s", socketPath)
}
candidates := []string{
candidates := make([]string, 0, 6)
if runtimeDir := strings.TrimSpace(os.Getenv("XDG_RUNTIME_DIR")); runtimeDir != "" {
candidates = append(candidates, filepath.Join(runtimeDir, ".ydotool_socket"))
}
candidates = append(candidates,
filepath.Join("/run/user", fmt.Sprintf("%d", os.Getuid()), ".ydotool_socket"),
"/tmp/.ydotool_socket",
}
"/run/ydotoold/socket",
"/run/ydotoold/.ydotool_socket",
)
for _, socketPath := range candidates {
if _, err := os.Stat(socketPath); err == nil {
return socketPath, nil
}
}
return "", fmt.Errorf("ydotoold socket not found; run `systemctl --user start ydotool.service` after configuring /dev/uinput permissions")
return "", fmt.Errorf("ydotoold socket not found; run `systemctl --user enable --now ydotool.service` and log out/in only if the service still cannot access /dev/uinput")
}
func runLinuxInputCommand(path string, args []string, stdin string, timeout time.Duration, socketPath string) error {