Display scale: verify both lines, fail on reload error, honest non-TTY path

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKxGW1raAWaqeU8WdHsMsp
This commit is contained in:
2026-08-24 19:48:35 -04:00
co-authored by Claude Fable 5
parent fff49e747c
commit 3cdb3fa61c
+21 -18
View File
@@ -29,30 +29,33 @@ sed -i -E \
-e "s|^local omarchy_gdk_scale = .*|local omarchy_gdk_scale = $gdk|" \
"$monitors"
if ! grep -q "omarchy_monitor_scale = $preset" "$monitors"; then
if ! grep -q "omarchy_monitor_scale = $preset" "$monitors" ||
! grep -q "omarchy_gdk_scale = $gdk" "$monitors"; then
mv "$backup" "$monitors"
echo "monitors.lua has no omarchy_monitor_scale line; reverted, edit it manually" >&2
echo "monitors.lua lacks the omarchy scale lines; reverted, edit it manually" >&2
exit 1
fi
echo "Monitor scale: $preset, GDK scale: $gdk"
if command -v hyprctl > /dev/null 2>&1 && hyprctl reload > /dev/null 2>&1; then
if [[ -t 0 ]]; then
echo "15 秒内按 y 保留新缩放,超时或按其他键自动恢复"
if read -r -t 15 -n 1 answer && [[ $answer == "y" ]]; then
rm -f "$backup"
echo "已保留"
else
mv "$backup" "$monitors"
hyprctl reload > /dev/null 2>&1
echo "已恢复原缩放"
exit 0
fi
else
rm -f "$backup"
fi
else
if ! command -v hyprctl > /dev/null 2>&1; then
rm -f "$backup"
echo "Hyprland 未运行,重登录后生效"
elif ! hyprctl reload > /dev/null 2>&1; then
mv "$backup" "$monitors"
echo "hyprctl reload 失败,已恢复原配置" >&2
exit 1
elif [[ -t 0 ]]; then
echo "15 秒内按 y 保留新缩放,超时或按其他键自动恢复"
if read -r -t 15 -n 1 answer && [[ $answer == "y" ]]; then
rm -f "$backup"
echo "已保留"
else
mv "$backup" "$monitors"
hyprctl reload > /dev/null 2>&1
echo "已恢复原缩放"
fi
else
omarchy-notification-send "OmarchyCN" "缩放已改为 $preset;如异常运行 omarchycn display scale 恢复" 2> /dev/null || true
echo "无终端交互:已应用,备份保留在 $backup,可用 mv 恢复"
fi