feat: add control of dae

This commit is contained in:
2026-03-28 09:23:25 +08:00
parent adfb3c31cc
commit 2e706f4e99
5 changed files with 134 additions and 46 deletions

View File

@@ -3,103 +3,103 @@
* Generated with Matugen * Generated with Matugen
*/ */
@define-color background #15130b; @define-color background #101417;
@define-color error #ffb4ab; @define-color error #ffb4ab;
@define-color error_container #93000a; @define-color error_container #93000a;
@define-color inverse_on_surface #333027; @define-color inverse_on_surface #2d3135;
@define-color inverse_primary #6e5e0e; @define-color inverse_primary #226488;
@define-color inverse_surface #e9e2d4; @define-color inverse_surface #dfe3e7;
@define-color on_background #e9e2d4; @define-color on_background #dfe3e7;
@define-color on_error #690005; @define-color on_error #690005;
@define-color on_error_container #ffdad6; @define-color on_error_container #ffdad6;
@define-color on_primary #3a3000; @define-color on_primary #00344c;
@define-color on_primary_container #f9e287; @define-color on_primary_container #c7e7ff;
@define-color on_primary_fixed #221b00; @define-color on_primary_fixed #001e2e;
@define-color on_primary_fixed_variant #534600; @define-color on_primary_fixed_variant #004c6c;
@define-color on_secondary #373016; @define-color on_secondary #21323e;
@define-color on_secondary_container #eee2bc; @define-color on_secondary_container #d2e5f5;
@define-color on_secondary_fixed #211b04; @define-color on_secondary_fixed #0b1d29;
@define-color on_secondary_fixed_variant #4e472a; @define-color on_secondary_fixed_variant #374955;
@define-color on_surface #e9e2d4; @define-color on_surface #dfe3e7;
@define-color on_surface_variant #cdc6b4; @define-color on_surface_variant #c1c7ce;
@define-color on_tertiary #153722; @define-color on_tertiary #342b4b;
@define-color on_tertiary_container #c5ecce; @define-color on_tertiary_container #e9ddff;
@define-color on_tertiary_fixed #00210f; @define-color on_tertiary_fixed #1f1635;
@define-color on_tertiary_fixed_variant #2c4e38; @define-color on_tertiary_fixed_variant #4b4263;
@define-color outline #969080; @define-color outline #8b9198;
@define-color outline_variant #4b4739; @define-color outline_variant #41484d;
@define-color primary #dcc66e; @define-color primary #93cdf6;
@define-color primary_container #534600; @define-color primary_container #004c6c;
@define-color primary_fixed #f9e287; @define-color primary_fixed #c7e7ff;
@define-color primary_fixed_dim #dcc66e; @define-color primary_fixed_dim #93cdf6;
@define-color scrim #000000; @define-color scrim #000000;
@define-color secondary #d1c6a1; @define-color secondary #b6c9d8;
@define-color secondary_container #4e472a; @define-color secondary_container #374955;
@define-color secondary_fixed #eee2bc; @define-color secondary_fixed #d2e5f5;
@define-color secondary_fixed_dim #d1c6a1; @define-color secondary_fixed_dim #b6c9d8;
@define-color shadow #000000; @define-color shadow #000000;
@define-color source_color #dabc2c; @define-color source_color #80c6f4;
@define-color surface #15130b; @define-color surface #101417;
@define-color surface_bright #3c3930; @define-color surface_bright #353a3d;
@define-color surface_container #221f17; @define-color surface_container #1c2024;
@define-color surface_container_high #2d2a21; @define-color surface_container_high #262a2e;
@define-color surface_container_highest #38352b; @define-color surface_container_highest #313539;
@define-color surface_container_low #1e1b13; @define-color surface_container_low #181c20;
@define-color surface_container_lowest #100e07; @define-color surface_container_lowest #0a0f12;
@define-color surface_dim #15130b; @define-color surface_dim #101417;
@define-color surface_tint #dcc66e; @define-color surface_tint #93cdf6;
@define-color surface_variant #4b4739; @define-color surface_variant #41484d;
@define-color tertiary #aad0b3; @define-color tertiary #cdc0e9;
@define-color tertiary_container #2c4e38; @define-color tertiary_container #4b4263;
@define-color tertiary_fixed #c5ecce; @define-color tertiary_fixed #e9ddff;
@define-color tertiary_fixed_dim #aad0b3; @define-color tertiary_fixed_dim #cdc0e9;

View File

@@ -26,9 +26,9 @@
"bluetooth", "bluetooth",
"network", "network",
"custom/wfrec", "custom/wfrec",
// "custom/screenshot",
"custom/left_div#2", "custom/left_div#2",
// "idle_inhibitor", // "idle_inhibitor",
"custom/dae",
"custom/colorpicker", "custom/colorpicker",
"power-profiles-daemon", "power-profiles-daemon",
"custom/left_div#11", "custom/left_div#11",

View File

@@ -128,6 +128,14 @@
"power-saver": "", "power-saver": "",
}, },
}, },
"custom/dae": {
"exec": "$HOME/.config/waybar/scripts/dae_control.sh",
"return-type": "json",
"interval": 5,
"on-click": "$HOME/.config/waybar/scripts/dae_control.sh toggle",
"tooltip": true,
"format": "{}"
},
//截图 //截图
"custom/screenshot": { "custom/screenshot": {
"format": "", "format": "",

View File

@@ -0,0 +1,80 @@
#!/usr/bin/env bash
# 配置
API_URL="http://localhost:2023/graphql"
TOKEN=""
CURL_OPTS=(-s -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN")
# 图标 (需要 Nerd Font)
ICON_RUNNING="󰔡"
ICON_STOPPED="󰨙"
# 检查 jq
if ! command -v jq &> /dev/null; then
echo '{"text": "⚠️", "tooltip": "jq not installed", "class": "error"}'
exit 1
fi
# 获取当前运行状态
get_status() {
QUERY_JSON='{"query":"query { general { dae { running } } }"}'
RESPONSE=$(curl "${CURL_OPTS[@]}" -d "$QUERY_JSON" "$API_URL" 2>/dev/null)
# 提取 running 字段,直接取值,不添加 // empty
RUNNING=$(echo "$RESPONSE" | jq -r '.data.general.dae.running' 2>/dev/null)
if [ "$RUNNING" = "null" ] || [ -z "$RUNNING" ]; then
echo "error"
else
echo "$RUNNING"
fi
}
# 切换状态
toggle() {
CURRENT=$(get_status)
if [ "$CURRENT" = "error" ]; then
echo "error"
return
fi
# dry: true 停止, false 启动
if [ "$CURRENT" = "true" ]; then
DRY_VALUE="true"
else
DRY_VALUE="false"
fi
MUTATION_JSON="{\"query\":\"mutation Run(\$dry: Boolean!) { run(dry: \$dry) }\",\"variables\":{\"dry\":$DRY_VALUE},\"operationName\":\"Run\"}"
curl "${CURL_OPTS[@]}" -d "$MUTATION_JSON" "$API_URL" > /dev/null 2>&1
}
# 输出 Waybar 格式
output_waybar() {
STATUS=$(get_status)
if [ "$STATUS" = "error" ]; then
echo '{"text": "󰤫", "tooltip": "dae API 连接失败", "class": "error"}'
return
fi
if [ "$STATUS" = "true" ]; then
echo "{\"text\": \"$ICON_RUNNING\", \"tooltip\": \"dae 正在运行\", \"class\": \"running\"}"
else
echo "{\"text\": \"$ICON_STOPPED\", \"tooltip\": \"dae 已停止\", \"class\": \"stopped\"}"
fi
}
# 主入口
case "$1" in
toggle)
toggle
output_waybar
;;
status)
output_waybar
;;
*)
output_waybar
;;
esac

View File

@@ -176,7 +176,7 @@ window#waybar.empty #window {
padding: 0px 0px; padding: 0px 0px;
font-size: 1.39em; /* 25px */ font-size: 1.39em; /* 25px */
} }
#custom-dae,
#power-profiles-daemon, #power-profiles-daemon,
#custom-colorpicker, #custom-colorpicker,
#idle_inhibitor { #idle_inhibitor {