Skip to content

Commit f9391ab

Browse files
committed
optimized logic for DisableStartup parameter
#632
1 parent 55d452e commit f9391ab

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

run.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,13 +1827,36 @@ if ([version]$offline -ge [version]"1.1.87.612" -and [version]$offline -le [vers
18271827
Get -Url (Get-Link -e "/res/login.spa") -OutputPath $login_spa
18281828
}
18291829

1830+
# Disable Startup client
18301831
if ($DisableStartup) {
1832+
$prefsPath = "$env:APPDATA\Spotify\prefs"
18311833
$keyPath = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
18321834
$keyName = "Spotify"
18331835

1836+
# delete key in registry
18341837
if (Get-ItemProperty -Path $keyPath -Name $keyName -ErrorAction SilentlyContinue) {
18351838
Remove-ItemProperty -Path $keyPath -Name $keyName -Force
18361839
}
1840+
1841+
# create new prefs
1842+
if (-not (Test-Path $prefsPath)) {
1843+
$content = @"
1844+
app.autostart-configured=true
1845+
app.autostart-mode="off"
1846+
"@
1847+
[System.IO.File]::WriteAllLines($prefsPath, $content, [System.Text.UTF8Encoding]::new($false))
1848+
}
1849+
1850+
# update prefs
1851+
else {
1852+
$content = [System.IO.File]::ReadAllText($prefsPath)
1853+
if (-not $content.EndsWith("`n")) {
1854+
$content += "`n"
1855+
}
1856+
$content += 'app.autostart-mode="off"'
1857+
[System.IO.File]::WriteAllText($prefsPath, $content, [System.Text.UTF8Encoding]::new($false))
1858+
}
1859+
18371860
}
18381861

18391862
# Start Spotify

0 commit comments

Comments
 (0)