Skip to content

Commit f1fc842

Browse files
committed
fix: use new PlatformAPI in exp features
1 parent cfda93b commit f1fc842

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

jsHelper/expFeatures.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,41 @@
132132

133133
(function waitForRemoteConfigResolver() {
134134
// Don't show options if hooks aren't patched/loaded
135-
if (!hooksPatched || (!Spicetify.RemoteConfigResolver && !Spicetify.Platform?.RemoteConfiguration)) {
135+
if (!hooksPatched || (!Spicetify.RemoteConfigResolver && !Spicetify.Platform?.RemoteConfigDebugAPI && !Spicetify.Platform?.RemoteConfiguration)) {
136136
setTimeout(waitForRemoteConfigResolver, 500);
137137
return;
138138
}
139139

140140
let remoteConfiguration = Spicetify.RemoteConfigResolver?.value.remoteConfiguration || Spicetify.Platform?.RemoteConfiguration;
141-
let setOverrides = () => {};
141+
const setOverrides = async (overrides) => {
142+
if (Spicetify.Platform?.RemoteConfigDebugAPI) {
143+
for (const [name, value] of Object.entries(overrides)) {
144+
const feature = overrideList[name];
145+
const type = feature.values ? "enum" : typeof value === "number" ? "number" : "boolean";
146+
await Spicetify.Platform.RemoteConfigDebugAPI.setOverride(
147+
{
148+
source: "web",
149+
type,
150+
name,
151+
},
152+
value
153+
);
154+
}
155+
} else if (Spicetify.RemoteConfigResolver?.value?.setOverrides) {
156+
Spicetify.RemoteConfigResolver.value.setOverrides(Spicetify.createInternalMap?.(overrides));
157+
}
158+
};
142159

143-
(function waitForResolver() {
144-
if (!Spicetify.RemoteConfigResolver) {
160+
(async function waitForResolver() {
161+
if (!Spicetify.RemoteConfigResolver && !Spicetify.Platform?.RemoteConfigDebugAPI) {
145162
isFallback = true;
146163
notice.innerText = "⚠️ Using fallback mode. Some features may not work.";
147164
setTimeout(waitForResolver, 500);
148165
return;
149166
}
150167
isFallback = false;
151168
notice.remove();
152-
remoteConfiguration = Spicetify.RemoteConfigResolver.value.remoteConfiguration;
153-
setOverrides = Spicetify.RemoteConfigResolver.value.setOverrides;
169+
remoteConfiguration = Spicetify?.RemoteConfigResolver?.remoteConfiguration ?? (await Spicetify.Platform?.RemoteConfigDebugAPI.getProperties());
154170
})();
155171

156172
for (const key of Object.keys(overrideList)) {
@@ -165,7 +181,7 @@
165181
localStorage.setItem("spicetify-exp-features", JSON.stringify(overrideList));
166182

167183
featureMap[name] = value;
168-
setOverrides(Spicetify.createInternalMap?.(featureMap));
184+
setOverrides({ [name]: value });
169185
}
170186

171187
function createSlider(name, desc, defaultVal) {
@@ -254,8 +270,12 @@ ${Spicetify.SVGIcons.search}
254270

255271
for (const name of Object.keys(overrideList)) {
256272
if (!prevSessionOverrideList.includes(name) && remoteConfiguration.values.has(name)) {
257-
changeValue(name, remoteConfiguration.values.get(name));
258-
console.log(name, remoteConfiguration.values.get(name), overrideList[name]);
273+
const currentValue = remoteConfiguration.values.get(name);
274+
overrideList[name].value = currentValue;
275+
localStorage.setItem("spicetify-exp-features", JSON.stringify(overrideList));
276+
277+
featureMap[name] = currentValue;
278+
setOverrides({ [name]: currentValue });
259279
}
260280

261281
const feature = overrideList[name];
@@ -269,8 +289,6 @@ ${Spicetify.SVGIcons.search}
269289
}
270290

271291
content.appendChild(resetButton);
272-
273-
setOverrides(Spicetify.createInternalMap?.(featureMap));
274292
})();
275293

276294
await new Promise((res) => Spicetify.Events.webpackLoaded.on(res));

src/apply/apply.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,20 @@ func insertExpFeatures(jsPath string, flags Flag) {
413413
return fmt.Sprintf("%s%s=Spicetify.expFeatureOverride(%s);%s", submatches[1], submatches[2], submatches[2], submatches[3])
414414
})
415415

416+
// utils.ReplaceOnce(
417+
// &content,
418+
// `(\w+\.fromJSON)(\s*=\s*function\b[^{]*{[^}]*})`,
419+
// func(submatches ...string) string {
420+
// return fmt.Sprintf("%s=Spicetify.createInternalMap%s", submatches[1], submatches[2])
421+
// })
422+
416423
utils.ReplaceOnce(
417424
&content,
418425
`(([\w$.]+\.fromJSON)\(\w+\)+;)(return ?[\w{}().,]+[\w$]+\.Provider,)(\{value:\{localConfiguration)`,
419426
func(submatches ...string) string {
420427
return fmt.Sprintf("%sSpicetify.createInternalMap=%s;%sSpicetify.RemoteConfigResolver=%s", submatches[1], submatches[2], submatches[3], submatches[4])
421428
})
429+
422430
return content
423431
})
424432
}

0 commit comments

Comments
 (0)