From 0d0425c8c49dbbc88a444944af51b59782734e37 Mon Sep 17 00:00:00 2001 From: Unsloth Date: Thu, 9 Jul 2026 00:23:56 -0700 Subject: [PATCH] Keep the saved browser preference when the reinstall prompt is accepted An interactive reinstall over an install that had persisted STUDIO_OPEN_BROWSER='0' would flip it back to 1 when the user pressed Enter, because the prompt default was hardcoded to yes and the answer then overrode the preserve logic. Seed the prompt default from the existing preference (studio.conf on macOS/Linux/WSL, the value baked in launch-studio.ps1 on Windows) and flip the hint to [y/N] accordingly. Explicit y/n answers still override. --- install.ps1 | 20 ++++++++++++++++++-- install.sh | 19 ++++++++++++++++--- tests/sh/test_launcher_no_browser.sh | 7 +++++++ 3 files changed, 41 insertions(+), 5 deletions(-) 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