From 98663996ff1e1e0243555e7c747468d79dbac988 Mon Sep 17 00:00:00 2001 From: Grigory Date: Sun, 5 Nov 2023 00:01:13 +0500 Subject: [PATCH] refactor(install/windows): follow the general rules (#635) * fix(install/windows): test `spicetify path userdata` output * chore(install/windows): spicetify installing message & strings style * feat(install/windows): ask for current theme replacement --- resources/install.ps1 | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/resources/install.ps1 b/resources/install.ps1 index 79f611a4..683dc890 100644 --- a/resources/install.ps1 +++ b/resources/install.ps1 @@ -1,10 +1,11 @@ $ErrorActionPreference = 'Stop' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -Write-Host -Object 'Setting up...' -ForegroundColor Cyan +Write-Host -Object 'Setting up...' -ForegroundColor 'Cyan' -if (-not (Get-Command -Name spicetify -ErrorAction SilentlyContinue)) { - Write-Host -Object 'Spicetify not found. Installing it for you...' -ForegroundColor Yellow +if (-not (Get-Command -Name 'spicetify' -ErrorAction 'SilentlyContinue')) { + Write-Host -Object 'Spicetify not found.' -ForegroundColor 'Yellow' + Write-Host -Object 'Installing it for you...' -ForegroundColor 'Cyan' $Parameters = @{ Uri = 'https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install.ps1' UseBasicParsing = $true @@ -14,7 +15,7 @@ if (-not (Get-Command -Name spicetify -ErrorAction SilentlyContinue)) { spicetify path userdata | Out-Null $spiceUserDataPath = (spicetify path userdata) -if (-not (Test-Path -Path $spiceUserDataPath -PathType Container)) { +if (-not (Test-Path -Path $spiceUserDataPath -PathType 'Container' -ErrorAction 'SilentlyContinue')) { $spiceUserDataPath = "$env:APPDATA\spicetify" } $marketAppPath = "$spiceUserDataPath\CustomApps\marketplace" @@ -23,12 +24,14 @@ $isThemeInstalled = $( spicetify path -s | Out-Null -not $LASTEXITCODE ) +$currentTheme = (spicetify config current_theme) +$setTheme = $true -Write-Host -Object 'Removing and creating Marketplace folders...' -ForegroundColor Cyan -Remove-Item -Path $marketAppPath, $marketThemePath -Recurse -Force -ErrorAction SilentlyContinue | Out-Null -New-Item -Path $marketAppPath, $marketThemePath -ItemType Directory -Force | Out-Null +Write-Host -Object 'Removing and creating Marketplace folders...' -ForegroundColor 'Cyan' +Remove-Item -Path $marketAppPath, $marketThemePath -Recurse -Force -ErrorAction 'SilentlyContinue' | Out-Null +New-Item -Path $marketAppPath, $marketThemePath -ItemType 'Directory' -Force | Out-Null -Write-Host 'Downloading Marketplace...' -ForegroundColor Cyan +Write-Host -Object 'Downloading Marketplace...' -ForegroundColor 'Cyan' $marketArchivePath = "$marketAppPath\marketplace.zip" $unpackedFolderPath = "$marketAppPath\spicetify-marketplace-dist" $Parameters = @{ @@ -38,7 +41,7 @@ $Parameters = @{ } Invoke-WebRequest @Parameters -Write-Host -Object 'Unzipping and installing...' -ForegroundColor Cyan +Write-Host -Object 'Unzipping and installing...' -ForegroundColor 'Cyan' Expand-Archive -Path $marketArchivePath -DestinationPath $marketAppPath -Force Move-Item -Path "$unpackedFolderPath\*" -Destination $marketAppPath -Force Remove-Item -Path $marketArchivePath, $unpackedFolderPath -Force @@ -46,7 +49,7 @@ spicetify config custom_apps spicetify-marketplace- -q spicetify config custom_apps marketplace spicetify config inject_css 1 replace_colors 1 -Write-Host -Object 'Downloading placeholder theme...' -ForegroundColor Cyan +Write-Host -Object 'Downloading placeholder theme...' -ForegroundColor 'Cyan' $Parameters = @{ Uri = 'https://raw.githubusercontent.com/spicetify/spicetify-marketplace/main/resources/color.ini' UseBasicParsing = $true @@ -54,12 +57,20 @@ $Parameters = @{ } Invoke-WebRequest @Parameters -Write-Host -Object 'Applying...' -ForegroundColor Cyan -if (-not $isThemeInstalled) { - spicetify config current_theme marketplace +Write-Host -Object 'Applying...' -ForegroundColor 'Cyan' +if ($isThemeInstalled -and ($currentTheme -ne 'marketplace')) { + $Host.UI.RawUI.Flushinputbuffer() + $choice = $Host.UI.PromptForChoice( + 'Local theme found', + 'Do you want to replace it with a placeholder to install themes from the Marketplace?', + ('&Yes', '&No'), + 0 + ) + if ($choice = 1) { $setTheme = $false } } +if ($setTheme) { spicetify config current_theme marketplace } spicetify backup spicetify apply -Write-Host -Object 'Done!' -ForegroundColor Green +Write-Host -Object 'Done!' -ForegroundColor 'Green' Write-Host -Object 'If nothing has happened, check the messages above for errors'