fix: split autostart menu into install/enable/disable separate options

This commit is contained in:
i
2026-06-02 22:37:16 +08:00
parent 6f1408ac68
commit f02838a95d
2 changed files with 42 additions and 11 deletions
+19 -3
View File
@@ -796,11 +796,22 @@ function Main-Menu {
Write-Host ""
if ($script:STATUS_AUTOSTART_HUB -or $script:STATUS_AUTOSTART_RUNNER) {
$hubExists = $null -ne $script:STATUS_AUTOSTART_HUB
$runnerExists = $null -ne $script:STATUS_AUTOSTART_RUNNER
$hasService = $hubExists -or $runnerExists
$autostartEnabled = ($hubExists -and "$($script:STATUS_AUTOSTART_HUB)" -ne "Disabled") -or ($runnerExists -and "$($script:STATUS_AUTOSTART_RUNNER)" -ne "Disabled")
if (-not $hasService) {
Write-Host " $i) 安装计划任务 (hub + runner)"
$options += "setup_autostart"
$i++
}
if ($autostartEnabled) {
Write-Host " $i) 禁用开机自启"
$options += "disable_autostart"
$i++
} else {
} elseif ($hasService) {
Write-Host " $i) 启用开机自启"
$options += "enable_autostart"
$i++
@@ -851,12 +862,17 @@ function Main-Menu {
Collect-Status
Read-Host "按 Enter 继续..."
}
"enable_autostart" {
"setup_autostart" {
if (-not $script:STATUS_HUB_CONFIGURED) { Write-Warn "Hub 未配置,先执行配置"; Setup-Hub }
Setup-AutoStart
Collect-Status
Read-Host "按 Enter 继续..."
}
"enable_autostart" {
Setup-AutoStart
Collect-Status
Read-Host "按 Enter 继续..."
}
"disable_autostart" {
Disable-AutoStart
Collect-Status
+23 -8
View File
@@ -1163,16 +1163,26 @@ main_menu() {
fi
echo ""
local has_autostart=false
[[ "$STATUS_AUTOSTART_HUB_ENABLED" == "enabled" || "$STATUS_AUTOSTART_RUNNER_ENABLED" == "enabled" ]] && has_autostart=true
if [[ "$has_autostart" == true ]]; then
local has_service=false
[[ -n "$STATUS_AUTOSTART_HUB_ENABLED" || -n "$STATUS_AUTOSTART_RUNNER_ENABLED" ]] && has_service=true
local autostart_enabled=false
[[ "$STATUS_AUTOSTART_HUB_ENABLED" == "enabled" || "$STATUS_AUTOSTART_RUNNER_ENABLED" == "enabled" ]] && autostart_enabled=true
if [[ "$has_service" == false ]]; then
echo " $i) 安装系统服务 (hub + runner)"
options+=("setup_autostart")
((i++))
fi
if [[ "$autostart_enabled" == true ]]; then
echo " $i) 禁用开机自启"
options+=("disable_autostart")
else
echo " $i) 设置开机自启"
options+=("setup_autostart")
((i++))
elif [[ "$has_service" == true ]]; then
echo " $i) 启用开机自启"
options+=("enable_autostart")
((i++))
fi
((i++))
echo ""
echo " $i) 刷新状态"
@@ -1226,7 +1236,7 @@ main_menu() {
collect_status
read -rp "按 Enter 继续..."
;;
setup_autostart|enable_autostart)
setup_autostart)
if [[ "$STATUS_HUB_CONFIGURED" == false ]]; then
warn "Hub 未配置,先执行配置"
setup_hub || true
@@ -1235,6 +1245,11 @@ main_menu() {
collect_status
read -rp "按 Enter 继续..."
;;
enable_autostart)
enable_autostart
collect_status
read -rp "按 Enter 继续..."
;;
disable_autostart)
disable_autostart
collect_status