Skip to content

Commit

Permalink
(spotify)(#941) Remove Windows Store version
Browse files Browse the repository at this point in the history
  • Loading branch information
pauby committed Jul 28, 2023
1 parent 6b39dc9 commit eacfe9e
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions automatic/spotify/tools/ChocolateyInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ $arguments = @{
validExitCodes = @(0, 1641, 3010)
}

# check we can use Get-AppxPackage
if (Get-Command 'Get-AppxPackage' -ErrorAction SilentlyContinue) {
# there is likely going to be two packages returned for x86 and x64.
# we don't care about the architecture, just the version and they will both be the same.
$allAppxPackages = Get-AppxPackage
$installedAppXPackage = @($allAppxPackages | Where-Object -Property Name -eq 'SpotifyAB.SpotifyMusic')
if ($installedAppXPackage.Count -gt 0) {
if ($env:ChocolateyForce) {
#when you remove a package, you don't remove it per architecture. You just remove it for all architectures.
Write-Warning 'Attempting to remove Spotify installed from the Microsoft Store.'
Remove-AppxPackage -Package $installedAppXPackage[0].PackageFullName
}
else {
throw "Cannot install the Spotify package because the Microsft Store version is installed. Please uninstall this manually or add the '--force' option to the command line."
}
}
}

# Download the installer
$arguments['file'] = Get-ChocolateyWebFile @arguments

Expand All @@ -24,10 +42,10 @@ schtasks.exe /Delete /TN $arguments['packageName'] /F
# Wait for Spotify to start, then kill it
$done = $false
do {
if (Get-Process Spotify -ErrorAction SilentlyContinue) {
Stop-Process -name Spotify
$done = $true
}
if (Get-Process Spotify -ErrorAction SilentlyContinue) {
Stop-Process -name Spotify
$done = $true
}

Start-Sleep -s 10
Start-Sleep -s 10
} until ($done)

0 comments on commit eacfe9e

Please sign in to comment.