Sync current Hyprland widgets
This commit is contained in:
91
config/hypr/Scripts/ags-package-runner.py
Executable file
91
config/hypr/Scripts/ags-package-runner.py
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import os
|
||||
import pty
|
||||
import select
|
||||
import sys
|
||||
|
||||
|
||||
def emit(event_type, **payload):
|
||||
print(json.dumps({"type": event_type, **payload}), flush=True)
|
||||
|
||||
|
||||
def handle_message(pid, fd, raw_line):
|
||||
try:
|
||||
message = json.loads(raw_line.decode("utf-8", "replace"))
|
||||
except json.JSONDecodeError:
|
||||
return
|
||||
|
||||
if message.get("type") == "input":
|
||||
os.write(fd, str(message.get("data", "")).encode("utf-8", "replace"))
|
||||
elif message.get("type") == "signal":
|
||||
os.kill(pid, int(message.get("signal", 15)))
|
||||
|
||||
|
||||
def main():
|
||||
if "--" not in sys.argv:
|
||||
emit("exit", code=2, signaled=False)
|
||||
return 2
|
||||
|
||||
command = sys.argv[sys.argv.index("--") + 1 :]
|
||||
if not command:
|
||||
emit("exit", code=2, signaled=False)
|
||||
return 2
|
||||
|
||||
pid, fd = pty.fork()
|
||||
if pid == 0:
|
||||
os.execvp(command[0], command)
|
||||
|
||||
emit("start", pid=pid)
|
||||
stdin_fd = sys.stdin.fileno()
|
||||
open_fds = [fd, stdin_fd]
|
||||
stdin_buffer = b""
|
||||
|
||||
while open_fds:
|
||||
readable, _, _ = select.select(open_fds, [], [], 0.2)
|
||||
|
||||
if fd in readable:
|
||||
try:
|
||||
data = os.read(fd, 4096)
|
||||
except OSError:
|
||||
data = b""
|
||||
|
||||
if data:
|
||||
emit("out", data=data.decode("utf-8", "replace"))
|
||||
else:
|
||||
open_fds.remove(fd)
|
||||
|
||||
if stdin_fd in readable:
|
||||
try:
|
||||
chunk = os.read(stdin_fd, 4096)
|
||||
except OSError:
|
||||
chunk = b""
|
||||
|
||||
if not chunk:
|
||||
open_fds.remove(stdin_fd)
|
||||
continue
|
||||
|
||||
stdin_buffer += chunk
|
||||
while b"\n" in stdin_buffer:
|
||||
line, stdin_buffer = stdin_buffer.split(b"\n", 1)
|
||||
handle_message(pid, fd, line)
|
||||
|
||||
try:
|
||||
finished_pid, status = os.waitpid(pid, os.WNOHANG)
|
||||
except ChildProcessError:
|
||||
break
|
||||
|
||||
if finished_pid == pid:
|
||||
if os.WIFSIGNALED(status):
|
||||
emit("exit", code=os.WTERMSIG(status), signaled=True)
|
||||
return 128 + os.WTERMSIG(status)
|
||||
|
||||
code = os.WEXITSTATUS(status)
|
||||
emit("exit", code=code, signaled=False)
|
||||
return code
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -322,11 +322,41 @@ docker_menu() {
|
||||
esac
|
||||
}
|
||||
|
||||
launch_codex() {
|
||||
if ! command -v kitty >/dev/null 2>&1; then
|
||||
notify "kitty ist nicht installiert."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! command -v codex >/dev/null 2>&1; then
|
||||
notify "codex ist nicht installiert."
|
||||
return 0
|
||||
fi
|
||||
|
||||
kitty --title "Codex" sh -lc 'cd "$HOME" && exec codex' >/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
launch_opencode() {
|
||||
if ! command -v kitty >/dev/null 2>&1; then
|
||||
notify "kitty ist nicht installiert."
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! command -v opencode >/dev/null 2>&1; then
|
||||
notify "opencode ist nicht installiert."
|
||||
return 0
|
||||
fi
|
||||
|
||||
kitty --title "opencode" sh -lc 'cd "$HOME" && exec opencode' >/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
choice="$(
|
||||
printf '%s\n' \
|
||||
"📁 Projekt Management" \
|
||||
" Homelab Controlcenter" \
|
||||
"🐳 Docker Control" \
|
||||
" Codex" \
|
||||
" opencode" \
|
||||
" Terminal" \
|
||||
" Projektordner" \
|
||||
" VS Code / Codium" \
|
||||
@@ -344,6 +374,12 @@ case "$choice" in
|
||||
*"Docker Control"*)
|
||||
docker_menu
|
||||
;;
|
||||
*"Codex"*)
|
||||
launch_codex
|
||||
;;
|
||||
*"opencode"*)
|
||||
launch_opencode
|
||||
;;
|
||||
*"Terminal"*)
|
||||
kitty
|
||||
;;
|
||||
|
||||
26
config/hypr/Scripts/widget-panel.sh
Executable file
26
config/hypr/Scripts/widget-panel.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HYPR_DIR="$(cd -- "$SCRIPT_DIR/.." && pwd)"
|
||||
export HYPR_DIR
|
||||
|
||||
notify() {
|
||||
notify-send "Widgetbereich" "$1" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
if ! command -v ags >/dev/null 2>&1; then
|
||||
notify "ags ist nicht installiert."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t AGS_INSTANCES < <(ags list 2>/dev/null || true)
|
||||
for INSTANCE in "${AGS_INSTANCES[@]}"; do
|
||||
if [[ "$INSTANCE" == "widget-panel" ]]; then
|
||||
ags toggle widget-panel --instance widget-panel >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
cd "$HYPR_DIR"
|
||||
nohup ags run "$HYPR_DIR/ags/widget-panel.tsx" >/dev/null 2>&1 &
|
||||
Reference in New Issue
Block a user