Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(install/windows): follow the general rules #635

Merged
merged 4 commits into from
Nov 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'