mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
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:
+33
-12
@@ -86,6 +86,17 @@ setup_ydotool_systemd() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Prefer the distribution-provided unit. Debian's ydotool package ships
|
||||
# both the udev rule and a user unit; replacing it caused fresh installs
|
||||
# to use a different socket and often made typing work only after relogin.
|
||||
for service in ydotool.service ydotoold.service; do
|
||||
if systemctl --user cat "$service" >/dev/null 2>&1; then
|
||||
echo "[INFO] Using the distribution-provided $service"
|
||||
systemctl --user enable --now "$service"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
YDOTOOLD_BIN="$(find_ydotoold || true)"
|
||||
if [ -z "$YDOTOOLD_BIN" ]; then
|
||||
echo "[ERROR] ydotoold was not found after installing ydotool."
|
||||
@@ -95,23 +106,23 @@ setup_ydotool_systemd() {
|
||||
|
||||
SYSTEMD_USER_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user"
|
||||
mkdir -p "$SYSTEMD_USER_DIR"
|
||||
SERVICE_FILE="$SYSTEMD_USER_DIR/ydotool.service"
|
||||
SERVICE_FILE="$SYSTEMD_USER_DIR/wis-free-v3-ydotool.service"
|
||||
|
||||
cat > "$SERVICE_FILE" << YDSVCEOF
|
||||
[Unit]
|
||||
Description=ydotool daemon for WIS Free V3 direct keyboard injection
|
||||
Documentation=man:ydotool(1)
|
||||
After=graphical-session.target
|
||||
PartOf=graphical-session.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
Environment=YDOTOOL_SOCKET=%t/.ydotool_socket
|
||||
ExecStart=$YDOTOOLD_BIN
|
||||
ExecStart=$YDOTOOLD_BIN --socket-path=%t/.ydotool_socket
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
WantedBy=graphical-session.target
|
||||
YDSVCEOF
|
||||
|
||||
echo "[INFO] Created $SERVICE_FILE"
|
||||
@@ -140,13 +151,13 @@ YDSVCEOF
|
||||
echo ""
|
||||
echo " Reloading systemd user daemon..."
|
||||
systemctl --user daemon-reload
|
||||
echo " Enabling ydotool user service..."
|
||||
systemctl --user enable ydotool.service
|
||||
echo " Starting ydotool user service..."
|
||||
if systemctl --user restart ydotool.service; then
|
||||
echo " Enabling WIS Free V3 ydotool user service..."
|
||||
systemctl --user enable wis-free-v3-ydotool.service
|
||||
echo " Starting WIS Free V3 ydotool user service..."
|
||||
if systemctl --user restart wis-free-v3-ydotool.service; then
|
||||
echo " ydotool systemd service is running."
|
||||
else
|
||||
echo " [WARN] Could not start ydotool.service. Check: systemctl --user status ydotool.service"
|
||||
echo " [WARN] Could not start the ydotool service. Check: systemctl --user status wis-free-v3-ydotool.service"
|
||||
fi
|
||||
echo ""
|
||||
}
|
||||
@@ -154,6 +165,7 @@ YDSVCEOF
|
||||
INSTALL_MODE="none" # none, system, user
|
||||
INSTALL_SYSTEMD=false
|
||||
SHOW_HELP=false
|
||||
NO_INSTALL=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
@@ -166,24 +178,28 @@ for arg in "$@"; do
|
||||
--install-systemd)
|
||||
INSTALL_SYSTEMD=true
|
||||
;;
|
||||
--no-install)
|
||||
NO_INSTALL=true
|
||||
;;
|
||||
--help|-h)
|
||||
SHOW_HELP=true
|
||||
;;
|
||||
*)
|
||||
echo "[ERROR] Unknown option: $arg"
|
||||
echo "Usage: $0 [--install|--install-user|--install-systemd|--help]"
|
||||
echo "Usage: $0 [--install|--install-user|--install-systemd|--no-install|--help]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$SHOW_HELP" = true ]; then
|
||||
echo "Usage: $0 [--install|--install-user|--install-systemd|--help]"
|
||||
echo "Usage: $0 [--install|--install-user|--install-systemd|--no-install|--help]"
|
||||
echo ""
|
||||
echo " (no flags) Build only, then offer interactive install prompts"
|
||||
echo " --install Build and install system-wide (/usr/local/bin)"
|
||||
echo " --install-user Build and install per-user (~/.local/bin)"
|
||||
echo " --install-systemd Generate, reload, enable, and start ydotool user service"
|
||||
echo " --no-install Build without prompting to install (for CI)"
|
||||
echo " --help Show this message"
|
||||
echo ""
|
||||
exit 0
|
||||
@@ -404,12 +420,17 @@ fi
|
||||
|
||||
if ! pkg-config --exists webkit2gtk-4.0 2>/dev/null && pkg-config --exists webkit2gtk-4.1 2>/dev/null; then
|
||||
WEBKIT41_PC=""
|
||||
WEBKIT41_PKGCONFIG_DIR="$(pkg-config --variable=pcfiledir webkit2gtk-4.1 2>/dev/null || true)"
|
||||
if [ -n "$WEBKIT41_PKGCONFIG_DIR" ] && [ -f "$WEBKIT41_PKGCONFIG_DIR/webkit2gtk-4.1.pc" ]; then
|
||||
WEBKIT41_PC="$WEBKIT41_PKGCONFIG_DIR/webkit2gtk-4.1.pc"
|
||||
fi
|
||||
for dir in \
|
||||
$(printf '%s' "${PKG_CONFIG_PATH:-}" | tr ':' '\n') \
|
||||
/usr/lib64/pkgconfig \
|
||||
/usr/lib/pkgconfig \
|
||||
/usr/local/lib64/pkgconfig \
|
||||
/usr/local/lib/pkgconfig; do
|
||||
[ -n "$WEBKIT41_PC" ] && break
|
||||
[ -z "$dir" ] && continue
|
||||
[ -f "$dir/webkit2gtk-4.1.pc" ] || continue
|
||||
WEBKIT41_PC="$dir/webkit2gtk-4.1.pc"
|
||||
@@ -451,7 +472,7 @@ echo " Binary is ready at: $EXECUTABLE"
|
||||
echo ""
|
||||
|
||||
# If no install flags were passed, do interactive prompt (backward-compatible)
|
||||
if [ "$INSTALL_MODE" = "none" ] && [ "$INSTALL_SYSTEMD" = false ]; then
|
||||
if [ "$INSTALL_MODE" = "none" ] && [ "$INSTALL_SYSTEMD" = false ] && [ "$NO_INSTALL" = false ]; then
|
||||
read -p "Would you like to install it system-wide to /usr/local/bin? (y/n): " INSTALL
|
||||
if [[ "$INSTALL" == "y" || "$INSTALL" == "Y" ]]; then
|
||||
INSTALL_MODE="system"
|
||||
|
||||
@@ -25,6 +25,32 @@ fi
|
||||
|
||||
PKG_VERSION="$(printf '%s' "$APP_VERSION" | sed 's/[^A-Za-z0-9.+~]/./g')"
|
||||
PKG_RELEASE="${PKG_RELEASE:-1}"
|
||||
BUILD_DEB=true
|
||||
BUILD_RPM=true
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--deb)
|
||||
BUILD_DEB=true
|
||||
BUILD_RPM=false
|
||||
;;
|
||||
--rpm)
|
||||
BUILD_DEB=false
|
||||
BUILD_RPM=true
|
||||
;;
|
||||
--help|-h)
|
||||
echo "Usage: $0 [--deb|--rpm]"
|
||||
echo " (no flag) Build both formats when their build tools are installed."
|
||||
echo " --deb Build only a Debian package."
|
||||
echo " --rpm Build only an RPM package."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "[ERROR] Unknown option: $arg" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo "========================================"
|
||||
echo " $APP_NAME - Linux Package Script"
|
||||
@@ -48,8 +74,12 @@ require_command() {
|
||||
require_command go
|
||||
require_command pkg-config
|
||||
require_command gcc
|
||||
require_command dpkg-deb
|
||||
require_command rpmbuild
|
||||
if [ "$BUILD_DEB" = true ]; then
|
||||
require_command dpkg-deb
|
||||
fi
|
||||
if [ "$BUILD_RPM" = true ]; then
|
||||
require_command rpmbuild
|
||||
fi
|
||||
|
||||
if ! command_exists wails; then
|
||||
echo "[INFO] Wails CLI not found. Installing..."
|
||||
@@ -74,6 +104,20 @@ appindicator_ok() {
|
||||
return 1
|
||||
}
|
||||
|
||||
if pkg-config --exists ayatana-appindicator3-0.1 2>/dev/null; then
|
||||
APPINDICATOR_DEB_DEP="libayatana-appindicator3-1"
|
||||
elif pkg-config --exists appindicator3-0.1 2>/dev/null; then
|
||||
APPINDICATOR_DEB_DEP="libappindicator3-1"
|
||||
else
|
||||
APPINDICATOR_DEB_DEP="libayatana-appindicator3-1"
|
||||
fi
|
||||
|
||||
if pkg-config --exists webkit2gtk-4.1 2>/dev/null; then
|
||||
WEBKIT_DEB_DEP="libwebkit2gtk-4.1-0"
|
||||
else
|
||||
WEBKIT_DEB_DEP="libwebkit2gtk-4.0-37"
|
||||
fi
|
||||
|
||||
echo "[1/5] Checking Linux build dependencies..."
|
||||
if ! pkg-config --exists gtk+-3.0 || ! webkit2_ok || ! pkg-config --exists alsa || ! appindicator_ok; then
|
||||
echo "[ERROR] Missing one or more native build dependencies."
|
||||
@@ -114,12 +158,17 @@ fi
|
||||
|
||||
if ! pkg-config --exists webkit2gtk-4.0 2>/dev/null && pkg-config --exists webkit2gtk-4.1 2>/dev/null; then
|
||||
WEBKIT41_PC=""
|
||||
WEBKIT41_PKGCONFIG_DIR="$(pkg-config --variable=pcfiledir webkit2gtk-4.1 2>/dev/null || true)"
|
||||
if [ -n "$WEBKIT41_PKGCONFIG_DIR" ] && [ -f "$WEBKIT41_PKGCONFIG_DIR/webkit2gtk-4.1.pc" ]; then
|
||||
WEBKIT41_PC="$WEBKIT41_PKGCONFIG_DIR/webkit2gtk-4.1.pc"
|
||||
fi
|
||||
for dir in \
|
||||
$(printf '%s' "${PKG_CONFIG_PATH:-}" | tr ':' '\n') \
|
||||
/usr/lib64/pkgconfig \
|
||||
/usr/lib/pkgconfig \
|
||||
/usr/local/lib64/pkgconfig \
|
||||
/usr/local/lib/pkgconfig; do
|
||||
[ -n "$WEBKIT41_PC" ] && break
|
||||
[ -z "$dir" ] && continue
|
||||
[ -f "$dir/webkit2gtk-4.1.pc" ] || continue
|
||||
WEBKIT41_PC="$dir/webkit2gtk-4.1.pc"
|
||||
@@ -156,6 +205,9 @@ if [ -f "build/appicon.png" ]; then
|
||||
install -m 0644 "build/appicon.png" "$WORK_DIR/root/usr/share/pixmaps/$APP_NAME.png"
|
||||
elif [ -f "frontend/src/assets/images/logo-universal.png" ]; then
|
||||
install -m 0644 "frontend/src/assets/images/logo-universal.png" "$WORK_DIR/root/usr/share/pixmaps/$APP_NAME.png"
|
||||
else
|
||||
echo "[ERROR] Application icon was not found; refusing to build a package with a broken desktop entry."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat > "$WORK_DIR/root/usr/share/applications/$APP_NAME.desktop" <<EOF
|
||||
@@ -175,6 +227,7 @@ if [ -f README.md ]; then
|
||||
install -m 0644 README.md "$WORK_DIR/root/usr/share/doc/$APP_NAME/README.md"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_DEB" = true ]; then
|
||||
echo "[4/5] Building .deb package..."
|
||||
DEB_ROOT="$WORK_DIR/deb"
|
||||
rm -rf "$DEB_ROOT"
|
||||
@@ -190,7 +243,7 @@ Priority: optional
|
||||
Architecture: $ARCH_DEB
|
||||
Maintainer: $MAINTAINER
|
||||
Installed-Size: $INSTALLED_SIZE
|
||||
Depends: libgtk-3-0, libwebkit2gtk-4.0-37 | libwebkit2gtk-4.1-0, libasound2, libayatana-appindicator3-1
|
||||
Depends: libgtk-3-0, $WEBKIT_DEB_DEP, libasound2, $APPINDICATOR_DEB_DEP
|
||||
Recommends: ydotool
|
||||
Description: $COMMENT
|
||||
WIS Free V3 is a desktop voice dictation app built with Go and Wails.
|
||||
@@ -198,7 +251,9 @@ Description: $COMMENT
|
||||
EOF
|
||||
|
||||
dpkg-deb --build "$DEB_ROOT" "$DIST_DIR/${APP_NAME}_${PKG_VERSION}-${PKG_RELEASE}_${ARCH_DEB}.deb"
|
||||
fi
|
||||
|
||||
if [ "$BUILD_RPM" = true ]; then
|
||||
echo "[5/5] Building .rpm package..."
|
||||
RPM_TOP="$WORK_DIR/rpm"
|
||||
RPM_PAYLOAD="$(pwd)/$WORK_DIR/root"
|
||||
@@ -214,7 +269,6 @@ Summary: $COMMENT
|
||||
License: $LICENSE
|
||||
Requires: gtk3
|
||||
Requires: alsa-lib
|
||||
Requires: libayatana-appindicator-gtk3
|
||||
Recommends: ydotool
|
||||
|
||||
%description
|
||||
@@ -235,6 +289,7 @@ EOF
|
||||
|
||||
rpmbuild --target "$ARCH_RPM" --define "_topdir $(pwd)/$RPM_TOP" -bb "$RPM_SPEC"
|
||||
find "$RPM_TOP/RPMS" -type f -name "*.rpm" -exec cp {} "$DIST_DIR/" \;
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Packages written to:"
|
||||
|
||||
Reference in New Issue
Block a user