diff --git a/install.ps1 b/install.ps1 index a8c52a7b4b..62d55989ea 100644 --- a/install.ps1 +++ b/install.ps1 @@ -2615,11 +2615,27 @@ exit 0 # Ask once (interactive installs only) whether the launcher should open # the browser after the server is up. Skipped when --no-browser/--browser # was passed or input is redirected; then an existing choice is kept. + # Enter keeps the choice baked into the existing launcher so a reinstall + # that accepts the defaults never flips a saved no-browser preference. $_browserPromptOk = [Environment]::UserInteractive -and (-not [Console]::IsInputRedirected) if (-not $OpenBrowserPref -and $_browserPromptOk) { + $_existingPref = "" + $_promptLauncher = if ($StudioDataDir) { Join-Path $StudioDataDir "launch-studio.ps1" } else { $null } + if ($_promptLauncher -and (Test-Path -LiteralPath $_promptLauncher)) { + try { + $_prevText = [System.IO.File]::ReadAllText($_promptLauncher) + if ($_prevText -match "(?m)^\`$openBrowserDefault = '([01])'") { + $_existingPref = $Matches[1] + } + } catch {} + } + $_browserHint = if ($_existingPref -eq '0') { '[y/N]' } else { '[Y/n]' } Write-Host "" - $_browserReply = Read-Host " Open Unsloth Studio in your default browser after launch? [Y/n]" - $OpenBrowserPref = if ($_browserReply -match '^[Nn]') { '0' } else { '1' } + $_browserReply = Read-Host " Open Unsloth Studio in your default browser after launch? $_browserHint" + $OpenBrowserPref = if ($_browserReply -match '^[Nn]') { '0' } + elseif ($_browserReply -match '^[Yy]') { '1' } + elseif ($_existingPref) { $_existingPref } + else { '1' } } # New-StudioShortcuts gates the .lnk shortcuts on env-mode internally. diff --git a/install.sh b/install.sh index 38625c43c5..10bc6b8863 100755 --- a/install.sh +++ b/install.sh @@ -3198,13 +3198,26 @@ if [ "$TAURI_MODE" != true ]; then # Ask once (interactive installs only) whether the launcher should open # the browser after the server is up. Skipped when --no-browser/--browser # was passed or no TTY; then an existing choice is kept, defaulting to on. + # Enter keeps the choice persisted in studio.conf so a reinstall that + # accepts the defaults never flips a saved no-browser preference. if [ -z "$_STUDIO_OPEN_BROWSER" ] && [ -t 1 ] && [ -r /dev/tty ]; then + _existing_open_browser="" + if [ -f "$DATA_DIR/studio.conf" ]; then + _existing_open_browser=$(sed -n "s/^STUDIO_OPEN_BROWSER='\([01]\)'\$/\1/p" \ + "$DATA_DIR/studio.conf" 2>/dev/null | head -n 1) + fi + if [ "$_existing_open_browser" = "0" ]; then + _browser_hint="[y/N]" + else + _browser_hint="[Y/n]" + fi echo "" - printf " Open Unsloth Studio in your default browser after launch? [Y/n] " - read -r _browser_reply