-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoice-input-daemon.sh
More file actions
executable file
·77 lines (63 loc) · 2.05 KB
/
Copy pathvoice-input-daemon.sh
File metadata and controls
executable file
·77 lines (63 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Voice Input Daemon - Manages tray icon (optional)
# Run this at startup (e.g., in .xinitrc or as systemd user service)
# Resolve symlinks to find real script directory
SCRIPT_PATH="${BASH_SOURCE[0]}"
while [[ -L "$SCRIPT_PATH" ]]; do
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
SCRIPT_PATH="$(readlink "$SCRIPT_PATH")"
[[ "$SCRIPT_PATH" != /* ]] && SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_PATH"
done
SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
# Load config
source "$SCRIPT_DIR/.env" 2>/dev/null
# Defaults
TRAY_ICON="${TRAY_ICON:-true}"
NOTIFICATIONS="${NOTIFICATIONS:-true}"
ICON_DIR="$SCRIPT_DIR/icons"
STATE_FILE="/tmp/voice-input-state"
ICON_STATE_FILE="/tmp/voice-input-icon-state"
# Cleanup on exit
cleanup() {
rm -f "$ICON_STATE_FILE"
exit 0
}
trap cleanup EXIT INT TERM
echo "Plauder daemon started"
# If tray icon disabled, just keep daemon alive
if [[ "$TRAY_ICON" != "true" ]]; then
echo "Tray icon disabled, running in background only"
while true; do
sleep 3600
done
fi
# Tray icon enabled - run yad
echo "Tray icon running - right-click for menu"
# Initialize icon state
echo "idle" > "$ICON_STATE_FILE"
# Run yad with menu
yad --notification \
--image="$ICON_DIR/idle.svg" \
--text="Plauder - Ready" \
--menu="Toggle Recording!$SCRIPT_DIR/voice-input.sh|\
Einstellungen & Historie!$SCRIPT_DIR/plauder-gui|\
Select Microphone!$SCRIPT_DIR/select-mic.sh|\
Select Language!$SCRIPT_DIR/select-language.sh|\
Quit!quit" \
--command="$SCRIPT_DIR/voice-input.sh" &
YAD_PID=$!
# Background process to update icon based on state file
while kill -0 $YAD_PID 2>/dev/null; do
sleep 0.5
if [[ -f "$STATE_FILE" ]]; then
if [[ "$(cat "$ICON_STATE_FILE" 2>/dev/null)" != "recording" ]]; then
echo "recording" > "$ICON_STATE_FILE"
# Notification is sent by voice-input.sh, not here (avoid duplicates)
fi
else
if [[ "$(cat "$ICON_STATE_FILE" 2>/dev/null)" != "idle" ]]; then
echo "idle" > "$ICON_STATE_FILE"
fi
fi
done
cleanup