1
+ [CmdletBinding ()]
2
+ param (
3
+ [Parameter ()]
4
+ [switch ]$BypassAdmin
5
+ )
6
+
1
7
$ErrorActionPreference = ' Stop'
2
8
[Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
3
9
10
+ function Invoke-Spicetify {
11
+ param (
12
+ [Parameter (Mandatory = $true , Position = 0 , ValueFromRemainingArguments = $true )]
13
+ [string []]$Arguments
14
+ )
15
+
16
+ $spicetifyArgs = @ ()
17
+ if ($BypassAdmin ) {
18
+ $spicetifyArgs += " --bypass-admin"
19
+ }
20
+ $spicetifyArgs += $Arguments
21
+
22
+ & spicetify $spicetifyArgs
23
+ return $LASTEXITCODE
24
+ }
25
+
26
+ function Invoke-SpicetifyWithOutput {
27
+ param (
28
+ [Parameter (Mandatory = $true , Position = 0 , ValueFromRemainingArguments = $true )]
29
+ [string []]$Arguments
30
+ )
31
+
32
+ $spicetifyArgs = @ ()
33
+ if ($BypassAdmin ) {
34
+ $spicetifyArgs += " --bypass-admin"
35
+ }
36
+ $spicetifyArgs += $Arguments
37
+
38
+ $output = (& spicetify $spicetifyArgs 2>&1 | Out-String ).Trim()
39
+ return @ {
40
+ Output = $output
41
+ ExitCode = $LASTEXITCODE
42
+ }
43
+ }
44
+
4
45
Write-Host - Object ' Setting up...' - ForegroundColor ' Cyan'
5
46
6
47
if (-not (Get-Command - Name ' spicetify' - ErrorAction ' SilentlyContinue' )) {
7
- Write-Host - Object ' Spicetify not found.' - ForegroundColor ' Yellow'
8
- Write-Host - Object ' Installing it for you...' - ForegroundColor ' Cyan'
9
- $Parameters = @ {
10
- Uri = ' https://raw.githubusercontent.com/spicetify/cli/main/install.ps1'
11
- UseBasicParsing = $true
12
- }
13
- Invoke-WebRequest @Parameters | Invoke-Expression
48
+ Write-Host - Object ' Spicetify not found.' - ForegroundColor ' Yellow'
49
+ Write-Host - Object ' Installing it for you...' - ForegroundColor ' Cyan'
50
+ $Parameters = @ {
51
+ Uri = ' https://raw.githubusercontent.com/spicetify/cli/main/install.ps1'
52
+ UseBasicParsing = $true
53
+ }
54
+ Invoke-WebRequest @Parameters | Invoke-Expression
14
55
}
15
56
16
57
try {
17
- $spicetifyOutput = spicetify path userdata 2>&1 | Out-String
18
- if ($LASTEXITCODE -ne 0 ) {
58
+ $result = Invoke-SpicetifyWithOutput " path" " userdata"
59
+ if ($result .ExitCode -ne 0 ) {
19
60
Write-Host - Object " Error from Spicetify:" - ForegroundColor ' Red'
20
- Write-Host - Object $spicetifyOutput - ForegroundColor ' Red'
21
- exit 1
61
+ Write-Host - Object $result .Output - ForegroundColor ' Red'
62
+ return
22
63
}
23
- $spiceUserDataPath = $spicetifyOutput .Trim ()
64
+ $spiceUserDataPath = $result .Output
24
65
} catch {
25
66
Write-Host - Object " Error running Spicetify:" - ForegroundColor ' Red'
26
- Write-Host - Object $_.Exception.Message - ForegroundColor ' Red'
27
- exit 1
67
+ Write-Host - Object $_.Exception.Message.Trim () - ForegroundColor ' Red'
68
+ return
28
69
}
29
70
30
71
if (-not (Test-Path - Path $spiceUserDataPath - PathType ' Container' - ErrorAction ' SilentlyContinue' )) {
31
72
$spiceUserDataPath = " $env: APPDATA \spicetify"
32
73
}
33
74
$marketAppPath = " $spiceUserDataPath \CustomApps\marketplace"
34
75
$marketThemePath = " $spiceUserDataPath \Themes\marketplace"
76
+
35
77
$isThemeInstalled = $ (
36
- spicetify path - s | Out-Null
37
- -not $LASTEXITCODE
78
+ Invoke-Spicetify " path" " -s " | Out-Null
79
+ -not $LASTEXITCODE
38
80
)
39
- $currentTheme = (spicetify config current_theme)
81
+ $currentTheme = (Invoke-SpicetifyWithOutput " config" " current_theme" ).Output
40
82
$setTheme = $true
41
83
42
84
Write-Host - Object ' Removing and creating Marketplace folders...' - ForegroundColor ' Cyan'
43
85
try {
44
- $spicetifyOutput = spicetify path userdata 2>&1 | Out-String
45
- if ($LASTEXITCODE -ne 0 ) {
86
+ $result = Invoke-SpicetifyWithOutput " path" " userdata"
87
+ if ($result .ExitCode -ne 0 ) {
46
88
Write-Host - Object " Error: Failed to get Spicetify path. Details:" - ForegroundColor ' Red'
47
- Write-Host - Object $spicetifyOutput - ForegroundColor ' Red'
48
- exit 1
89
+ Write-Host - Object $result .Output - ForegroundColor ' Red'
90
+ return
49
91
}
50
92
51
93
Remove-Item - Path $marketAppPath , $marketThemePath - Recurse - Force - ErrorAction ' SilentlyContinue' | Out-Null
52
94
if (-not (New-Item - Path $marketAppPath , $marketThemePath - ItemType ' Directory' - Force - ErrorAction ' Stop' )) {
53
95
Write-Host - Object " Error: Failed to create Marketplace directories." - ForegroundColor ' Red'
54
- exit 1
96
+ return
55
97
}
56
98
} catch {
57
- Write-Host - Object " Error: $ ( $_.Exception.Message ) " - ForegroundColor ' Red'
58
- exit 1
99
+ Write-Host - Object " Error: $ ( $_.Exception.Message.Trim () ) " - ForegroundColor ' Red'
100
+ return
59
101
}
60
102
61
103
Write-Host - Object ' Downloading Marketplace...' - ForegroundColor ' Cyan'
@@ -72,9 +114,9 @@ Write-Host -Object 'Unzipping and installing...' -ForegroundColor 'Cyan'
72
114
Expand-Archive - Path $marketArchivePath - DestinationPath $marketAppPath - Force
73
115
Move-Item - Path " $unpackedFolderPath \*" - Destination $marketAppPath - Force
74
116
Remove-Item - Path $marketArchivePath , $unpackedFolderPath - Force
75
- spicetify config custom_apps spicetify- marketplace- - q
76
- spicetify config custom_apps marketplace
77
- spicetify config inject_css 1 replace_colors 1
117
+ Invoke-Spicetify " config" " custom_apps" " spicetify-marketplace-" " -q "
118
+ Invoke-Spicetify " config" " custom_apps" " marketplace"
119
+ Invoke-Spicetify " config" " inject_css" " 1 " " replace_colors" " 1 "
78
120
79
121
Write-Host - Object ' Downloading placeholder theme...' - ForegroundColor ' Cyan'
80
122
$Parameters = @ {
@@ -86,18 +128,20 @@ Invoke-WebRequest @Parameters
86
128
87
129
Write-Host - Object ' Applying...' - ForegroundColor ' Cyan'
88
130
if ($isThemeInstalled -and ($currentTheme -ne ' marketplace' )) {
89
- $Host.UI.RawUI.Flushinputbuffer ()
90
- $choice = $Host.UI.PromptForChoice (
91
- ' Local theme found' ,
92
- ' Do you want to replace it with a placeholder to install themes from the Marketplace?' ,
93
- (' &Yes' , ' &No' ),
94
- 0
95
- )
96
- if ($choice = 1 ) { $setTheme = $false }
131
+ $Host.UI.RawUI.Flushinputbuffer ()
132
+ $choice = $Host.UI.PromptForChoice (
133
+ ' Local theme found' ,
134
+ ' Do you want to replace it with a placeholder to install themes from the Marketplace?' ,
135
+ (' &Yes' , ' &No' ),
136
+ 0
137
+ )
138
+ if ($choice = 1 ) { $setTheme = $false }
139
+ }
140
+ if ($setTheme ) {
141
+ Invoke-Spicetify " config" " current_theme" " marketplace"
97
142
}
98
- if ($setTheme ) { spicetify config current_theme marketplace }
99
- spicetify backup
100
- spicetify apply
143
+ Invoke-Spicetify " backup"
144
+ Invoke-Spicetify " apply"
101
145
102
146
Write-Host - Object ' Done!' - ForegroundColor ' Green'
103
- Write-Host - Object ' If nothing has happened, check the messages above for errors'
147
+ Write-Host - Object ' If nothing has happened, check the messages above for errors'
0 commit comments