Skip to content

Commit

Permalink
Merge branch 'master' into posh2
Browse files Browse the repository at this point in the history
  • Loading branch information
SunsetTechuila authored Nov 24, 2023
2 parents 6dce590 + a675c71 commit 2c2a6df
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CustomApps/lyrics-plus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class LyricsContainer extends react.Component {
this.tryServices(nextInfo, this.state.explicitMode);
};

if (Spicetify.Player?.data?.track) {
if (Spicetify.Player?.data?.item) {
this.state.explicitMode = this.state.lockMode;
this.currentTrackUri = Spicetify.Player.data.item.uri;
this.fetchLyrics(Spicetify.Player.data.item, this.state.explicitMode);
Expand Down
4 changes: 2 additions & 2 deletions Extensions/trashbin.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@
if (!list[uri]) {
list[uri] = true;
if (shouldSkipCurrentTrack(uri, type)) Spicetify.Player.next();
Spicetify.Player.data?.track.uri === uri && setWidgetState(true);
Spicetify.Player.data?.item.uri === uri && setWidgetState(true);
Spicetify.showNotification(type === Spicetify.URI.Type.TRACK ? "Song added to trashbin" : "Artist added to trashbin");
} else {
delete list[uri];
Spicetify.Player.data?.track.uri === uri && setWidgetState(false);
Spicetify.Player.data?.item.uri === uri && setWidgetState(false);
Spicetify.showNotification(type === Spicetify.URI.Type.TRACK ? "Song removed from trashbin" : "Artist removed from trashbin");
}

Expand Down
23 changes: 22 additions & 1 deletion globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ declare namespace Spicetify {
/**
* React component to render for an icon used as button body. Component, not element!
*/
iconTrailing?: (props: any) => any | string;
iconOnly?: (props: any) => any | string;
/**
* Additional class name to apply to the button.
*/
Expand Down Expand Up @@ -1895,6 +1895,27 @@ declare namespace Spicetify {
* @see Spicetify.ReactComponent.SliderProps
*/
const Slider: any;
/**
* Component to render Spotify primary button
*
* Props:
* @see Spicetify.ReactComponent.ButtonProps
*/
const ButtonPrimary: any;
/**
* Component to render Spotify secondary button
*
* Props:
* @see Spicetify.ReactComponent.ButtonProps
*/
const ButtonSecondary: any;
/**
* Component to render Spotify tertiary button
*
* Props:
* @see Spicetify.ReactComponent.ButtonProps
*/
const ButtonTertiary: any;
}

/**
Expand Down
56 changes: 55 additions & 1 deletion jsHelper/spicetifyWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,60 @@ window.Spicetify = {
Locale: modules.find(m => m?._dictionary)
});

const localeModule = modules.find(m => m?.getTranslations);
if (localeModule) {
const createUrlLocale = functionModules.find(
m => m.toString().includes("has") && m.toString().includes("baseName") && m.toString().includes("language")
);
Spicetify.Locale = {
get _relativeTimeFormat() {
return localeModule._relativeTimeFormat;
},
get _dateTimeFormats() {
return localeModule._dateTimeFormats;
},
get _locale() {
return localeModule._localeForTranslation.baseName;
},
get _urlLocale() {
return localeModule._localeForURLPath;
},
get _dictionary() {
return localeModule._translations;
},
formatRelativeTime: (date, options) => localeModule.formatRelativeDate(date, options),
formatNumber: (number, options) => localeModule.formatNumber(number, options),
formatNumberCompact: (number, options) => localeModule.formatNumberCompact(number, options),
get: (key, children) => localeModule.get(key, children),
getDateTimeFormat: options => localeModule.getDateTimeFormat(options),
getDictionary: () => localeModule.getTranslations(),
getLocale: () => localeModule._localeForTranslation.baseName,
getSmartlingLocale: () => localeModule.getLocaleForSmartling(),
getUrlLocale: () => localeModule.getLocaleForURLPath(),
getRelativeTimeFormat: () => localeModule.getRelativeTimeFormat(),
getSeparator: () => localeModule.getSeparator(),
setLocale: locale => {
return localeModule.initialize({
localeForTranslation: locale,
localeForFormatting: localeModule._localeForFormatting.baseName,
translations: localeModule._translations
});
},
setUrlLocale: locale => {
if (createUrlLocale) localeModule._localeForURLPath = createUrlLocale(locale);
},
setDictionary: dictionary => {
return localeModule.initialize({
localeForTranslation: localeModule._localeForTranslation.baseName,
localeForFormatting: localeModule._localeForFormatting.baseName,
translations: dictionary
});
},
toLocaleLowerCase: text => localeModule.toLocaleLowerCase(text),
toLocaleUpperCase: text => localeModule.toLocaleUpperCase(text)
};
}

if (Spicetify.Locale) Spicetify.Locale._supportedLocales = cache.find(m => typeof m?.ja === "string");

Object.defineProperty(Spicetify, "Queue", {
Expand Down Expand Up @@ -1656,7 +1710,7 @@ Spicetify._cloneSidebarItem = function (list, isLibX = false) {

let appProper = manifest.name;
if (typeof appProper === "object") {
appProper = appProper[Spicetify.Locale.getLocale()] || appProper["en"];
appProper = appProper[Spicetify.Locale?.getLocale()] || appProper["en"];
}
if (!appProper) {
appProper = app[0].toUpperCase() + app.slice(1);
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func InitPaths() {
spotifyPath = settingSection.Key("spotify_path").String()
prefsPath = settingSection.Key("prefs_path").String()

spotifyPath = utils.ReplaceEnvVarsInString(spotifyPath)
prefsPath = utils.ReplaceEnvVarsInString(prefsPath)

if len(spotifyPath) == 0 {
spotifyPath = utils.FindAppPath()

Expand Down
26 changes: 25 additions & 1 deletion src/preprocess/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,31 @@ func disableSentry(input string) string {
func disableLogging(input string) string {
utils.Replace(&input, `sp://logging/v3/\w+`, "")
utils.Replace(&input, `[^"\/]+\/[^"\/]+\/(public\/)?v3\/events`, "")
utils.Replace(&input, `(\(e,\s*t\))\s*{(\s*return\s*this\.storageAdapter\.setItem\([${}\w."`+"`"+`()]+,\s*t\)\s*)}`, "${1}{return null}")

utils.Replace(&input, `key:"registerEventListeners",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"logInteraction",value:function\([\w,]+\)\{`, "${0}return{interactionId:null,pageInstanceId:null};")
utils.Replace(&input, `key:"logNonAuthInteraction",value:function\([\w,]+\)\{`, "${0}return{interactionId:null,pageInstanceId:null};")
utils.Replace(&input, `key:"logImpression",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logNonAuthImpression",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logNavigation",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"logClientLostFocus",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"logClientGainedFocus",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `key:"createLoggingParams",value:function\([\w,]+\)\{`, "${0}return;")
utils.Replace(&input, `key:"initSendingEvents",value:function\(\)\{`, "${0}return;")
utils.Replace(&input, `(\{key:"send",value:function\([\w,]+\))\{[\d\w\s,{}()[\]\.,!\?=>&|;:_""]+?\}(\},\{key:"hasContext")`, "${1}{return;}${2}")
utils.Replace(&input, `key:"lastFlush",value:function\(\)\{`, "${0}return;")

utils.Replace(&input, `(\}registerEventListeners\(\))\{.+?\}(unregisterEventListeners)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logInteraction\([\w,]+\))\{.+?\}(logImpression)`, "${1}{return{interactionId:null,pageInstanceId:null};}${2}")
utils.Replace(&input, `(\}logImpression\([\w,]+\))\{.+?\}(logNavigation)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logNavigation\([\w,]+\))\{.+?\}(getPageInstanceId|getInteractionId)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logClientLostFocus\(\))\{.+?\}(logClientGainedFocus)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}logClientGainedFocus\(\))\{.+?\}(getPageInstanceId|addEventListeners)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}createLoggingParams\([\w,]+\))\{.+?\}(async pullToLocal)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}initSendingEvents\(\))\{.+?\}(initializeContexts)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}send\([\w,:=!\d{}]+\))\{.+?\}(hasContext)`, "${1}{return;}${2}")
utils.Replace(&input, `(\}lastFlush\(\))\{.+?\}(flush\(\))`, "${1}{return;}${2}")

return input
}

Expand Down
11 changes: 11 additions & 0 deletions src/utils/path-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
)

func MigrateConfigFolder() {
Expand All @@ -24,6 +25,16 @@ func MigrateConfigFolder() {
}
}

func ReplaceEnvVarsInString(input string) string {
var replacements []string
for _, v := range os.Environ() {
pair := strings.SplitN(v, "=", 2)
replacements = append(replacements, "$"+pair[0], pair[1])
}
replacer := strings.NewReplacer(replacements...)
return replacer.Replace(input)
}

func GetSpicetifyFolder() string {
result, isAvailable := os.LookupEnv("SPICETIFY_CONFIG")
defer func() { CheckExistAndCreate(result) }()
Expand Down

0 comments on commit 2c2a6df

Please sign in to comment.