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(windows install): refactor posh install script #528

Merged
merged 3 commits into from
Jun 25, 2023
Merged
Changes from 1 commit
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
87 changes: 43 additions & 44 deletions resources/install.ps1
Original file line number Diff line number Diff line change
@@ -1,61 +1,60 @@
# Modified from https://github.com/JulienMaille/dribbblish-dynamic-theme/blob/main/install.ps1
$ErrorActionPreference = 'Stop'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Write-Host "Setting up..." -ForegroundColor "Green"
Write-Host -Object 'Setting up...' -ForegroundColor Cyan

$checkSpice = Get-Command spicetify -ErrorAction Silent
if ($null -eq $checkSpice) {
Write-Host -ForegroundColor Red "Spicetify not found. Installing that for you..."
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install.ps1" | Invoke-Expression
if (-not (Get-Command -Name spicetify -ErrorAction SilentlyContinue)) {
Write-Host -Object 'Spicetify not found. Installing it for you...' -ForegroundColor Yellow
$Parameters = @{
Uri = 'https://raw.githubusercontent.com/spicetify/spicetify-cli/master/install.ps1'
UseBasicParsing = $true
}
Invoke-WebRequest @Parameters | Invoke-Expression
}

$spicePath = "$env:APPDATA\spicetify"
$sp_dot_dir = "$spicePath\CustomApps"
if (-not (Test-Path $sp_dot_dir)) {
Write-Host "Making a CustomApps folder..." -ForegroundColor "Cyan"
New-Item -Path $sp_dot_dir -ItemType Directory | Out-Null
}

Write-Host "Downloading..." -ForegroundColor "Green"

$latest_release_uri =
"https://api.github.com/repos/spicetify/spicetify-marketplace/releases/latest"
$latest_release_json = Invoke-WebRequest -Uri $latest_release_uri -UseBasicParsing
$version = ($latest_release_json | ConvertFrom-Json).tag_name -replace "v", ""
$download_uri = "https://github.com/spicetify/spicetify-marketplace/releases/download/" +
"v$version/spicetify-marketplace.zip"

Invoke-WebRequest -Uri $download_uri -UseBasicParsing -OutFile "$sp_dot_dir\marketplace.zip"

spicetify path userdata | Out-Null
$spiceUserDataPath = (spicetify path userdata)
$marketAppPath = "$spiceUserDataPath\CustomApps\marketplace"
$marketThemePath = "$spiceUserDataPath\Themes\marketplace"
$isMarketplaceInstalled = (
((spicetify config custom_apps) -contains "marketplace") -and (Test-Path -Path "$sp_dot_dir\marketplace" -PathType Container)
((spicetify config custom_apps) -contains 'marketplace') -and (Test-Path -Path $marketAppPath -PathType Container)
)

Write-Host "Unzipping and installing..." -ForegroundColor "Green"
Expand-Archive -Path "$sp_dot_dir\marketplace.zip" -DestinationPath $sp_dot_dir -Force
Remove-Item -Path "$sp_dot_dir\marketplace.zip" -Force
if (Test-Path -Path "$sp_dot_dir\marketplace") {
Write-Host "marketplace was already found! Updating..." -ForegroundColor "Cyan"
Remove-Item -Path "$sp_dot_dir\marketplace" -Force -Recurse
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
SunsetTechuila marked this conversation as resolved.
Show resolved Hide resolved
$marketArchivePath = "$marketAppPath\marketplace.zip"
$unpackedFolderPath = "$marketAppPath\spicetify-marketplace-dist"
$Parameters = @{
Uri = 'https://github.com/spicetify/spicetify-marketplace/releases/latest/download/spicetify-marketplace.zip'
UseBasicParsing = $true
OutFile = $marketArchivePath
}
Rename-Item -Path "$sp_dot_dir\spicetify-marketplace-dist" -NewName "marketplace" -Force
spicetify config custom_apps spicetify-marketplace-
spicetify config custom_apps marketplace
Invoke-WebRequest @Parameters

# Color injection fix
spicetify config inject_css 1
spicetify config replace_colors 1
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 "Applying placeholder theme..." -ForegroundColor "Cyan"
Remove-Item -Recurse -Force "$spicePath\Themes\marketplace" -ErrorAction Ignore
New-Item -Path "$spicePath\Themes\marketplace" -ItemType Directory | Out-Null
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/spicetify/spicetify-marketplace/main/resources/color.ini" -OutFile "$spicePath\Themes\marketplace\color.ini"
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 $isMarketplaceInstalled) {
spicetify config current_theme marketplace
}

spicetify backup
spicetify backup
spicetify apply

Write-Host "Done! If nothing has happened, do spicetify apply" -ForegroundColor "Green"
Write-Host -Object 'Done! If nothing has happened, do spicetify apply' -ForegroundColor Green