Skip to content

Commit

Permalink
remove: redundant code
Browse files Browse the repository at this point in the history
change: login page is no longer be modded
  • Loading branch information
khanhas committed May 30, 2021
1 parent 782f503 commit bd617cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 41 deletions.
12 changes: 3 additions & 9 deletions src/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ func Backup() {
backup.Extract(backupFolder, rawFolder, tracker.Update)
tracker.Finish()

tracker.Reset()

utils.PrintBold("Preprocessing:")

preprocess.Start(
Expand All @@ -71,20 +69,16 @@ func Backup() {
ExposeAPIs: preprocSection.Key("expose_apis").MustBool(false),
DisableUpgrade: preprocSection.Key("disable_upgrade_check").MustBool(false),
},
tracker.Update,
)

tracker.Finish()
utils.PrintGreen("OK")

err = utils.Copy(rawFolder, themedFolder, true, []string{".html", ".js", ".css"})
if err != nil {
utils.Fatal(err)
}

tracker.Reset()

preprocess.StartCSS(themedFolder, tracker.Update)
tracker.Finish()
preprocess.StartCSS(themedFolder)
utils.PrintGreen("OK")

backupSection.Key("version").SetValue(utils.GetSpotifyVersion(prefsPath))
cfg.Write()
Expand Down
41 changes: 9 additions & 32 deletions src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package preprocess
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"path/filepath"
"regexp"
"strings"
"sync"
"unicode"

"github.com/khanhas/spicetify-cli/src/utils"
Expand All @@ -36,7 +34,7 @@ type jsMap struct {
}

// Start preprocessing apps assets in extractedAppPath
func Start(extractedAppsPath string, flags Flag, callback func(appName string)) {
func Start(extractedAppsPath string, flags Flag) {
appPath := filepath.Join(extractedAppsPath, "xpui")
var cssTranslationMap = make(map[string]string)
// readSourceMapAndGenerateCSSMap(appPath)
Expand Down Expand Up @@ -137,35 +135,14 @@ func Start(extractedAppsPath string, flags Flag, callback func(appName string))

// StartCSS modifies all CSS files in extractedAppsPath to change
// all colors value with CSS variables.
func StartCSS(extractedAppsPath string, callback func(appName string)) {
appList, err := ioutil.ReadDir(extractedAppsPath)

if err != nil {
log.Fatal(err)
}

var wg sync.WaitGroup

for _, app := range appList {
wg.Add(1)
appName := app.Name()
appPath := filepath.Join(extractedAppsPath, appName)

go func() {
defer wg.Done()

filepath.Walk(appPath, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(info.Name()) == ".css" {
utils.ModifyFile(path, colorVariableReplace)
}
return nil
})

callback(appName)
}()
}

wg.Wait()
func StartCSS(extractedAppsPath string) {
appPath := filepath.Join(extractedAppsPath, "xpui")
filepath.Walk(appPath, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(info.Name()) == ".css" {
utils.ModifyFile(path, colorVariableReplace)
}
return nil
})
}

func colorVariableReplace(content string) string {
Expand Down

0 comments on commit bd617cc

Please sign in to comment.