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.
This commit is contained in:
parent
bf3a6f1a51
commit
0d0425c8c4
3 changed files with 41 additions and 5 deletions
20
install.ps1
20
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.
|
||||
|
|
|
|||
19
install.sh
19
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 </dev/tty || _browser_reply="y"
|
||||
printf " Open Unsloth Studio in your default browser after launch? %s " "$_browser_hint"
|
||||
read -r _browser_reply </dev/tty || _browser_reply=""
|
||||
case "$_browser_reply" in
|
||||
[nN]*) _STUDIO_OPEN_BROWSER=0 ;;
|
||||
*) _STUDIO_OPEN_BROWSER=1 ;;
|
||||
[yY]*) _STUDIO_OPEN_BROWSER=1 ;;
|
||||
*) _STUDIO_OPEN_BROWSER="${_existing_open_browser:-1}" ;;
|
||||
esac
|
||||
fi
|
||||
create_studio_shortcuts "$VENV_ABS_BIN/unsloth" "$OS"
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ assert_contains \
|
|||
assert_contains \
|
||||
"install.sh: interactive prompt asks about browser auto-open" \
|
||||
"$_installer" "Open Unsloth Studio in your default browser after launch?"
|
||||
# A reinstall that accepts the prompt default must keep the saved choice.
|
||||
assert_contains \
|
||||
"install.sh: prompt Enter keeps the persisted preference" \
|
||||
"$_installer" '*) _STUDIO_OPEN_BROWSER="${_existing_open_browser:-1}"'
|
||||
|
||||
echo ""
|
||||
echo "=== install.sh _open_browser gating (functional) ==="
|
||||
|
|
@ -158,6 +162,9 @@ assert_file_contains \
|
|||
assert_file_contains \
|
||||
"install.ps1: interactive prompt asks about browser auto-open" \
|
||||
"$INSTALL_PS1" "Open Unsloth Studio in your default browser after launch?"
|
||||
assert_file_contains \
|
||||
"install.ps1: prompt Enter keeps the baked preference" \
|
||||
"$INSTALL_PS1" 'elseif ($_existingPref) { $_existingPref }'
|
||||
# All launcher URL opens must route through the gated helper.
|
||||
_ps1_direct_open=$(grep -cF 'Start-Process "http://localhost:' "$INSTALL_PS1" || true)
|
||||
if [ "$_ps1_direct_open" -eq 0 ]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue