Skip to content

Commit

Permalink
refactor(install/windows): follow the general rules (#635)
Browse files Browse the repository at this point in the history
* fix(install/windows): test `spicetify path userdata` output
* chore(install/windows): spicetify installing message & strings style
* feat(install/windows): ask for current theme replacement
  • Loading branch information
SunsetTechuila authored Nov 4, 2023
1 parent 25caa2b commit 9866399
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions resources/install.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand All @@ -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 = @{
Expand All @@ -38,28 +41,36 @@ $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
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
OutFile = "$marketThemePath\color.ini"
}
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'

0 comments on commit 9866399

Please sign in to comment.