(jsPath string, flags Flag)
| 268 | } |
| 269 | |
| 270 | func insertCustomApp(jsPath string, flags Flag) { |
| 271 | utils.ModifyFile(jsPath, func(content string) string { |
| 272 | // React lazy loading patterns for dynamic imports |
| 273 | reactPatterns := []string{ |
| 274 | // Sync pattern: X.lazy((() => Y.Z(123).then(W.bind(W, 456)))) |
| 275 | `([\w_\$][\w_\$\d]*(?:\(\))?)\.lazy\(\((?:\(\)=>|function\(\)\{return )(\w+)\.(\w+)\(["']?[\w-]+["']?\)\.then\(\w+\.bind\(\w+,["']?[\w-]+["']?\)\)\}?\)\)`, |
| 276 | // Async pattern (1.2.78+): m.lazy(async()=>{...await o.e(123).then(...)}) |
| 277 | `([\w_\$][\w_\$\d]*)\.lazy\(async\(\)=>\{(?:[^{}]|\{[^{}]*\})*await\s+(\w+)\.(\w+)\(["']?[\w-]+["']?\)\.then\(\w+\.bind\(\w+,["']?[\w-]+["']?\)\)`, |
| 278 | // Async Promise.all pattern (1.2.78+): m.lazy(async()=>await Promise.all([Y.Z(123),...]).then(...)) |
| 279 | // Capture the chunk loader from the first entry inside Promise.all, not from .bind() |
| 280 | `([\w_\$][\w_\$\d]*(?:\(\))?)\.lazy\(async\(\)=>await\s+Promise\.all\(\[(\w+)\.(\w+)\(["']?[\w-]+["']?\)`, |
| 281 | } |
| 282 | |
| 283 | // React element/route patterns for path matching |
| 284 | elementPatterns := []string{ |
| 285 | // JSX pattern (1.2.78+): (0,S.jsx)(se.qh,{path:"/collection/*",element:...}) |
| 286 | // Settings page should be more consistent with having no conditional renders |
| 287 | `(\([\w$\.,]+\))\(([\w\.]+),\{path:"/settings(?:/[\w\*]+)?",?(element|children)?`, |
| 288 | // createElement pattern: X.createElement(Y,{path:"/collection"...}) |
| 289 | `([\w_\$][\w_\$\d]*(?:\(\))?\.createElement|\([\w$\.,]+\))\(([\w\.]+),\{path:"\/collection"(?:,(element|children)?[:.\w,{}()$/*"]+)?\}`, |
| 290 | } |
| 291 | |
| 292 | reactSymbs, matchedReactPattern := utils.FindSymbolWithPattern( |
| 293 | "Custom app React symbols", |
| 294 | content, |
| 295 | reactPatterns) |
| 296 | eleSymbs, matchedElementPattern := utils.FindSymbolWithPattern( |
| 297 | "Custom app React Element", |
| 298 | content, |
| 299 | elementPatterns) |
| 300 | |
| 301 | if (len(reactSymbs) < 2) || (len(eleSymbs) == 0) { |
| 302 | utils.PrintError("Spotify version mismatch with Spicetify. Please report it on our github repository.") |
| 303 | utils.PrintInfo("Spicetify might have been updated for this version already. Please run `spicetify update` to check for a new version.") |
| 304 | utils.PrintInfo("If one isn't available yet, please wait for an update to be released or downgrade Spotify to a supported version.") |
| 305 | return content |
| 306 | } |
| 307 | |
| 308 | appMap := "" |
| 309 | appReactMap := "" |
| 310 | appEleMap := "" |
| 311 | cssEnableMap := "" |
| 312 | appNameArray := "" |
| 313 | |
| 314 | // Spotify's new route system |
| 315 | wildcard := "" |
| 316 | if eleSymbs[2] == "" { |
| 317 | eleSymbs[2] = "children" |
| 318 | } else if eleSymbs[2] == "element" { |
| 319 | wildcard = "*" |
| 320 | } |
| 321 | |
| 322 | for index, app := range flags.CustomApp { |
| 323 | appName := `spicetify-routes-` + app |
| 324 | appMap += fmt.Sprintf(`"%s":"%s",`, appName, appName) |
| 325 | appNameArray += fmt.Sprintf(`"%s",`, app) |
| 326 | |
| 327 | appReactMap += fmt.Sprintf( |
nothing calls this directly
no test coverage detected