Skip to content

Commit

Permalink
feat: update rework (#2638)
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsojramos authored Nov 8, 2023
1 parent c06c364 commit 8d0cbf4
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version-file: "go.mod"

- name: Build
run: go build .
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version-file: "go.mod"

- name: Build
if: env.IS_UNIX == 'true' || env.IS_WIN == 'true'
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/spicetify/spicetify-cli

go 1.19
go 1.21

require (
github.com/go-ini/ini v1.67.0
Expand Down
11 changes: 5 additions & 6 deletions jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2287,9 +2287,9 @@ Spicetify.Playbar = (function () {
setTimeout(checkForUpdate, 300);
return;
}
const { check_spicetify_upgrade, version } = Spicetify.Config;
const { check_spicetify_update, version } = Spicetify.Config;
// Skip checking if upgrade check is disabled, or version is Dev/version is not set
if (!check_spicetify_upgrade || !version || version === "Dev") {
if (!check_spicetify_update || !version || version === "Dev") {
return;
}
// Fetch latest version from GitHub
Expand Down Expand Up @@ -2368,10 +2368,9 @@ Spicetify.Playbar = (function () {
<p>Run these commands in the terminal:</p>
<ol>
<li>Update Spicetify CLI</li>
<pre class="spicetify-update-little-space">spicetify upgrade</pre>
<p class="spicetify-update-space">If you installed Spicetify via a package manager, update using said package manager.</p>
<li>Apply changes to Spotify</li>
<pre>spicetify restore backup apply</pre>
<pre class="spicetify-update-little-space">spicetify update</pre>
<p>Spicetify will automatically apply changes to Spotify after upgrading to the latest version.</p>
<p>If you installed Spicetify via a package manager, update using said package manager.</p>
</ol>
`;

Expand Down
103 changes: 53 additions & 50 deletions spicetify.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"runtime"
"slices"
"strings"
"sync"

Expand All @@ -29,7 +30,7 @@ var (
appFocus = false
styleFocus = false
noRestart = false
liveUpdate = false
liveRefresh = false
)

func init() {
Expand Down Expand Up @@ -84,44 +85,22 @@ func init() {
os.Exit(0)
case "-e", "--extension":
extensionFocus = true
liveUpdate = true
liveRefresh = true
case "-a", "--app":
appFocus = true
liveUpdate = true
liveRefresh = true
case "-q", "--quiet":
quiet = true
case "-n", "--no-restart":
noRestart = true
case "-s", "--style":
styleFocus = true
liveUpdate = true
case "-l", "--live-update":
liveRefresh = true
case "-l", "--live-refresh":
extensionFocus = true
appFocus = true
styleFocus = true
liveUpdate = true
case "--check-update":
upgradeStatus := cmd.Upgrade(version)
if upgradeStatus {
ex, err := os.Executable()
if err != nil {
ex = "spicetify"
}

spotStat := spotifystatus.Get(utils.FindAppPath())
cmds := []string{"backup", "apply"}
if !spotStat.IsBackupable() {
cmds = append([]string{"restore"}, cmds...)
}

cmd := exec.Command(ex, cmds...)
utils.CmdScanner(cmd)

cmd = exec.Command(ex, strings.Join(commands[:], " "))
utils.CmdScanner(cmd)

os.Exit(0)
}
liveRefresh = true
}
}

Expand All @@ -135,14 +114,13 @@ func init() {

if len(commands) < 1 {
help()
cmd.CheckUpdate(version)
os.Exit(0)
}
}

func main() {
// Show config directory without needing to initialize config
switch commands[0] {
case "config-dir":
if slices.Contains(commands, "config-dir") {
cmd.ShowConfigDirectory()
return
}
Expand Down Expand Up @@ -216,10 +194,6 @@ func main() {
log.Println(path)
return

case "upgrade":
cmd.Upgrade(version)
return

case "watch":
var name []string
if len(commands) > 1 {
Expand All @@ -233,31 +207,55 @@ func main() {
go func(name []string, liveUpdate bool) {
defer watchGroup.Done()
cmd.WatchExtensions(name, liveUpdate)
}(name, liveUpdate)
}(name, liveRefresh)
}

if appFocus {
watchGroup.Add(1)
go func(name []string, liveUpdate bool) {
defer watchGroup.Done()
cmd.WatchCustomApp(name, liveUpdate)
}(name, liveUpdate)
}(name, liveRefresh)
}

if styleFocus {
watchGroup.Add(1)
go func(liveUpdate bool) {
defer watchGroup.Done()
cmd.Watch(liveUpdate)
}(liveUpdate)
}(liveRefresh)
}

watchGroup.Wait()
return
}

utils.PrintBold("spicetify v" + version)
cmd.CheckUpgrade(version)
if slices.Contains(commands, "upgrade") || slices.Contains(commands, "update") {
updateStatus := cmd.Update(version)
if updateStatus {
ex, err := os.Executable()
if err != nil {
ex = "spicetify"
}

spotStat := spotifystatus.Get(utils.FindAppPath())
cmds := []string{"backup", "apply"}
if !spotStat.IsBackupable() {
cmds = append([]string{"restore"}, cmds...)
}

cmd := exec.Command(ex, cmds...)
utils.CmdScanner(cmd)

cmd = exec.Command(ex, strings.Join(commands[:], " "))
utils.CmdScanner(cmd)

return
}
} else {
cmd.CheckUpdate(version)
}

// Chainable commands
for _, v := range commands {
Expand All @@ -269,14 +267,20 @@ func main() {
cmd.Clear()

case "apply":
cmd.CheckStates()
cmd.InitSetting()
cmd.Apply(version)
restartSpotify()

case "update":
case "refresh":
cmd.CheckStates()
cmd.InitSetting()
if extensionFocus {
cmd.UpdateAllExtension()
cmd.RefreshExtensions()
} else if appFocus {
cmd.RefreshApps()
} else {
cmd.UpdateTheme()
cmd.RefreshTheme()
}

case "restore":
Expand Down Expand Up @@ -320,7 +324,7 @@ backup Start backup and preprocessing app files.
apply Apply customization.
update By default, updates theme's CSS, JS, colors, and assets.
refresh Refresh the theme's CSS, JS, colors, and assets.
Use with flag "-e" to update extensions.
restore Restore Spotify to original state.
Expand Down Expand Up @@ -414,7 +418,7 @@ color 1. Print all color fields and values.
config-dir Shows config directory in file viewer
upgrade Upgrade spicetify latest version
upgrade|update Update spicetify latest version
` + utils.Bold("FLAGS") + `
-q, --quiet Quiet mode (no output). Be careful, dangerous operations
Expand All @@ -423,15 +427,15 @@ upgrade Upgrade spicetify latest version
-s, --style Use with "watch" command to auto-reload Spotify when changes are made to the active theme (color.ini, user.css, theme.js, assets).
-e, --extension Use with "update", "watch" or "path" command to
-e, --extension Use with "refresh", "watch" or "path" command to
focus on extensions. Use with "watch" command to auto-reload Spotify when changes are made to extensions.
-a, --app Use with "watch" or "path" to focus on custom apps. Use with "watch" command to auto-reload Spotify when changes are made to apps.
-n, --no-restart Do not restart Spotify after running command(s), except
"restart" command.
-l, --live-update Use with "watch" command to auto-reload Spotify when changes are made to any custom component (color.ini, user.css, extensions, apps).
-l, --live-refresh Use with "watch" command to auto-reload Spotify when changes are made to any custom component (color.ini, user.css, extensions, apps).
-c, --config Print config file path and quit
Expand Down Expand Up @@ -477,6 +481,9 @@ spotify_launch_flags
always_enable_devtools <0 | 1>
Whether Chrome DevTools is enabled when launching/restarting Spotify.
check_spicetify_update <0 | 1>
Whether to check for spicetify-cli update when running Spicetify.
` + utils.Bold("[Preprocesses]") + `
disable_sentry <0 | 1>
Prevents Sentry and Amazon Qualaroo to send console log/error/warning to Spotify developers.
Expand All @@ -495,10 +502,6 @@ expose_apis <0 | 1>
Leaks some Spotify's API, functions, objects to Spicetify global object that
are useful for making extensions to extend Spotify functionality.
disable_upgrade_check <0 | 1>
Prevent Spotify checking new version and visually notifying user.
[Windows] Note: Automatic update still works if you don't manually delete "SpotifyMigrator.exe" and "SpotifyUpdate.exe".
` + utils.Bold("[AdditionalOptions]") + `
custom_apps <string>
List of custom apps. Separate each app with "|".
Expand Down
26 changes: 13 additions & 13 deletions src/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (

// Flag enables/disables additional feature
type Flag struct {
CurrentTheme string
ColorScheme string
InjectThemeJS bool
CheckSpicetifyUpgrade bool
Extension []string
CustomApp []string
SidebarConfig bool
HomeConfig bool
ExpFeatures bool
SpicetifyVer string
SpotifyVer string
CurrentTheme string
ColorScheme string
InjectThemeJS bool
CheckSpicetifyUpdate bool
Extension []string
CustomApp []string
SidebarConfig bool
HomeConfig bool
ExpFeatures bool
SpicetifyVer string
SpotifyVer string
}

// AdditionalOptions .
Expand Down Expand Up @@ -129,9 +129,9 @@ func htmlMod(htmlPath string, flags Flag) {
Spicetify.Config["color_scheme"]="%s";
Spicetify.Config["extensions"] = [%s];
Spicetify.Config["custom_apps"] = [%s];
Spicetify.Config["check_spicetify_upgrade"]=%v;
Spicetify.Config["check_spicetify_update"]=%v;
</script>
`, flags.SpicetifyVer, flags.CurrentTheme, flags.ColorScheme, extList, customAppList, flags.CheckSpicetifyUpgrade)
`, flags.SpicetifyVer, flags.CurrentTheme, flags.ColorScheme, extList, customAppList, flags.CheckSpicetifyUpdate)
}

for _, v := range flags.Extension {
Expand Down
Loading

0 comments on commit 8d0cbf4

Please sign in to comment.