fix: streamline hotkey listener initialization and improve error handling for Linux

This commit is contained in:
jahruz67
2026-05-19 17:42:13 -07:00
parent b6ae530876
commit 00f4912cc3
3 changed files with 15 additions and 22 deletions
+4 -9
View File
@@ -461,10 +461,8 @@ func (a *App) SaveSettings(settings map[string]interface{}) string {
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
if runtime.GOOS == "windows" { a.hotkeyListener = hotkey.NewListener(val, a.StartRecording, a.StopRecording)
a.hotkeyListener = hotkey.NewListener(val, a.StartRecording, a.StopRecording) if runtime.GOOS != "windows" {
} else {
a.hotkeyListener = hotkey.NewListener(val, a.ToggleRecording, func() {})
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() {
@@ -626,11 +624,8 @@ func (a *App) startupHeadless() {
} }
// Initialize Hotkey Listener // Initialize Hotkey Listener
if runtime.GOOS == "windows" { a.hotkeyListener = hotkey.NewListener(a.config.Shortcut, a.StartRecording, a.StopRecording)
a.hotkeyListener = hotkey.NewListener(a.config.Shortcut, a.StartRecording, a.StopRecording) if runtime.GOOS != "windows" {
} else {
// Linux (Wayland fallback) uses toggle mode: keydown toggles, keyup ignored
a.hotkeyListener = hotkey.NewListener(a.config.Shortcut, a.ToggleRecording, func() {})
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() {
+5 -1
View File
@@ -170,7 +170,11 @@ func (l *Listener) eventLoop(hk *xhk.Hotkey) {
case <-time.After(20 * time.Millisecond): case <-time.After(20 * time.Millisecond):
// Genuine second press. Toggle off. // Genuine second press. Toggle off.
logger.Info("Shortcut activated again: toggling recording (Wayland toggle fallback)") logger.Info("Shortcut activated again: toggling recording (Wayland toggle fallback)")
go l.startCallback() if l.stopCallback != nil {
go l.stopCallback()
} else {
go l.startCallback()
}
isRecording = false isRecording = false
} }
} }
+6 -12
View File
@@ -140,10 +140,6 @@ if command_exists pkg-config; then
echo "[WARNING] Missing Wails dependencies (GTK3 / WebKit2GTK)." echo "[WARNING] Missing Wails dependencies (GTK3 / WebKit2GTK)."
MISSING_DEPS=1 MISSING_DEPS=1
fi fi
if ! pkg-config --exists x11 xtst xcb xkbcommon-x11; then
echo "[WARNING] Missing gohook dependencies (X11 / Xtst / Xcb / Xkbcommon)."
MISSING_DEPS=1
fi
if ! pkg-config --exists alsa; then if ! pkg-config --exists alsa; then
echo "[WARNING] Missing audio dependencies (ALSA)." echo "[WARNING] Missing audio dependencies (ALSA)."
MISSING_DEPS=1 MISSING_DEPS=1
@@ -158,22 +154,20 @@ if [ $MISSING_DEPS -eq 1 ]; then
echo "" echo ""
echo "It looks like you are missing some required libraries." echo "It looks like you are missing some required libraries."
echo "" echo ""
echo "Wayland note: global hotkeys use the XDG GlobalShortcuts portal when WAYLAND_DISPLAY" echo "Wayland note: global hotkeys use the XDG GlobalShortcuts portal (xdg-desktop-portal"
echo "or XDG_SESSION_TYPE=wayland is set (xdg-desktop-portal + a supporting compositor, e.g. KDE Plasma)." echo "with a supporting compositor, e.g. KDE Plasma or GNOME)."
echo "Override: WISFREE_USE_X11_HOTKEY=1 forces X11 grabs (needs XWayland);"
echo "WISFREE_USE_PORTAL_HOTKEY=1 forces the portal on X11 sessions for testing."
echo "" echo ""
DEBIAN_DEPS="build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.0-dev libx11-dev libx11-xcb-dev libxtst-dev libasound2-dev libayatana-appindicator3-dev libxkbcommon-x11-dev" DEBIAN_DEPS="build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.0-dev libasound2-dev libayatana-appindicator3-dev"
# Runtime niceties (optional): libnotify-bin — status toasts; playerctl — pause media while recording # Runtime niceties (optional): libnotify-bin — status toasts; playerctl — pause media while recording
DEBIAN_RUNTIME_OPT="libnotify-bin playerctl" DEBIAN_RUNTIME_OPT="libnotify-bin playerctl"
# Fedora 40+: WebKit2GTK 4.0 packages are gone; use 4.1 + Wails -tags webkit2_41 (see wails build below). # Fedora 40+: WebKit2GTK 4.0 packages are gone; use 4.1 + Wails -tags webkit2_41 (see wails build below).
# pkgconf-pkg-config provides `pkg-config` on Fedora. # pkgconf-pkg-config provides `pkg-config` on Fedora.
FEDORA_DEPS="gcc gcc-c++ make pkgconf-pkg-config gtk3-devel webkit2gtk4.1-devel libX11-devel libxcb-devel libXtst-devel alsa-lib-devel libayatana-appindicator-gtk3-devel libxkbcommon-x11-devel" FEDORA_DEPS="gcc gcc-c++ make pkgconf-pkg-config gtk3-devel webkit2gtk4.1-devel alsa-lib-devel libayatana-appindicator-gtk3-devel"
# Same as FEDORA_DEPS but classic libappindicator (some spins/repos lack Ayatana -devel) # Same as FEDORA_DEPS but classic libappindicator (some spins/repos lack Ayatana -devel)
FEDORA_DEPS_ALT="gcc gcc-c++ make pkgconf-pkg-config gtk3-devel webkit2gtk4.1-devel libX11-devel libxcb-devel libXtst-devel alsa-lib-devel libappindicator-gtk3-devel libxkbcommon-x11-devel" FEDORA_DEPS_ALT="gcc gcc-c++ make pkgconf-pkg-config gtk3-devel webkit2gtk4.1-devel alsa-lib-devel libappindicator-gtk3-devel"
FEDORA_RUNTIME_OPT="libnotify playerctl xdg-desktop-portal" FEDORA_RUNTIME_OPT="libnotify playerctl xdg-desktop-portal"
ARCH_DEPS="base-devel pkgconf gtk3 webkit2gtk libx11 libxtst alsa-lib libayatana-appindicator libxkbcommon-x11" ARCH_DEPS="base-devel pkgconf gtk3 webkit2gtk alsa-lib libayatana-appindicator"
ARCH_RUNTIME_OPT="libnotify playerctl" ARCH_RUNTIME_OPT="libnotify playerctl"
echo "The full list of dependencies needed:" echo "The full list of dependencies needed:"