Skip to content

Commit

Permalink
style: change linter settings & change copyright to SPDX
Browse files Browse the repository at this point in the history
  • Loading branch information
rxri committed May 30, 2024
1 parent 0f7cb1a commit c80375d
Show file tree
Hide file tree
Showing 11 changed files with 6,803 additions and 6,955 deletions.
11,769 changes: 5,907 additions & 5,862 deletions PlatformAutoGen.d.ts

Large diffs are not rendered by default.

63 changes: 25 additions & 38 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
},
"security": {
"noDangerouslySetInnerHtml": "off"
},
"style": {
"noParameterAssign": "off",
"noNonNullAssertion": "off"
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": true,
"indentStyle": "space",
"indentWidth": 3,
"lineWidth": 112
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"trailingComma": "all"
}
}
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"linter": {
"enabled": false
},
"formatter": {
"enabled": true,
"formatWithErrors": true,
"indentStyle": "space",
"indentWidth": 2,
"lineWidth": 100
},
"organizeImports": {
"enabled": true
},
"javascript": {
"formatter": {
"arrowParentheses": "asNeeded",
"trailingComma": "es5"
}
}
}
28 changes: 8 additions & 20 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
/* Copyright © 2024
* Delusoire <[email protected]>
*
* This file is part of bespoke/hooks.
*
* bespoke/hooks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* bespoke/hooks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bespoke/hooks. If not, see <https://www.gnu.org/licenses/>.
/*
* Copyright (C) 2024 Delusoire
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import mixin, { applyTransforms } from "./mixins.js";
import { MixinLoader, Module } from "./module.js";

await mixin( MixinLoader.INTERNAL.transformer );
await mixin(MixinLoader.INTERNAL.transformer);
await Module.enableAllLoadableMixins();

await Promise.all( [ "/vendor~xpui.js", "/xpui.js" ].map( applyTransforms ).map( async p => import( await p ) ) );
await Promise.all(
["/vendor~xpui.js", "/xpui.js"].map(applyTransforms).map(async p => import(await p))
);

await Promise.all( MixinLoader.INTERNAL.awaitedMixins );
await Promise.all(MixinLoader.INTERNAL.awaitedMixins);
await Module.enableAllLoadable();
183 changes: 86 additions & 97 deletions mixins.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
/* Copyright © 2024
* Delusoire <[email protected]>
*
* This file is part of bespoke/hooks.
*
* bespoke/hooks is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* bespoke/hooks is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bespoke/hooks. If not, see <https://www.gnu.org/licenses/>.
/*
* Copyright (C) 2024 Delusoire
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import { nsUrlHandlers } from "./protocol.js";
Expand All @@ -23,100 +9,103 @@ import { sources, type Transformer } from "./transform.js";
import { matchLast } from "./util.js";

declare global {
var __applyTransforms: typeof applyTransforms;
var __interceptNavigationControlMessage: typeof interceptNavigationControlMessage;
var __applyTransforms: typeof applyTransforms;
var __interceptNavigationControlMessage: typeof interceptNavigationControlMessage;
}

export const applyTransforms = ( path: string ) => {
const i = Paths.indexOf( path as any );
const source = sources[ i ];
console.info( "loadResource", { path, source } );
if ( !source ) return path;
return source.getObjectURL();
export const applyTransforms = (path: string) => {
const i = Paths.indexOf(path as any);
const source = sources[i];
console.info("loadResource", { path, source });
if (!source) return path;
return source.getObjectURL();
};

globalThis.__applyTransforms = applyTransforms;

const rpc = "spotify:app:rpc:";
function interceptNavigationControlMessage( e: Event ): boolean {
const uri: string = ( e as any ).data.data;
if ( !uri.startsWith( rpc ) ) {
return true;
}
const trimmedUri = uri.slice( rpc.length );
if ( trimmedUri === "reload" ) {
document.location.reload();
}
{
const hash = trimmedUri.slice( 0, 47 );
nsUrlHandlers.get( hash )?.( trimmedUri );
}
return false;
function interceptNavigationControlMessage(e: Event): boolean {
const uri: string = (e as any).data.data;
if (!uri.startsWith(rpc)) {
return true;
}
const trimmedUri = uri.slice(rpc.length);
if (trimmedUri === "reload") {
document.location.reload();
}
{
const hash = trimmedUri.slice(0, 47);
nsUrlHandlers.get(hash)?.(trimmedUri);
}
return false;
}

globalThis.__interceptNavigationControlMessage = interceptNavigationControlMessage;

export default async function ( transformer: Transformer ) {
transformer(
emit => str => {
str = str.replace(
/(([a-zA-Z_\$][\w\$]*)=([a-zA-Z_\$][\w\$]*)\.p\+\3\.u\([a-zA-Z_\$][\w\$]*\))/,
"$1,$2=await __applyTransforms($2)",
);
const i = str.search( '"Loading chunk "' );
const { index } = matchLast( str.slice( 0, i ), /=\([a-zA-Z_\$][\w\$]*,[a-zA-Z_\$][\w\$]*\)=>\{/g );
str = `${ str.slice( 0, index! + 1 ) }async${ str.slice( index! + 1 ) }`;
export default async function (transformer: Transformer) {
transformer(
emit => str => {
str = str.replace(
/(([a-zA-Z_\$][\w\$]*)=([a-zA-Z_\$][\w\$]*)\.p\+\3\.u\([a-zA-Z_\$][\w\$]*\))/,
"$1,$2=await __applyTransforms($2)"
);
const i = str.search('"Loading chunk "');
const { index } = matchLast(
str.slice(0, i),
/=\([a-zA-Z_\$][\w\$]*,[a-zA-Z_\$][\w\$]*\)=>\{/g
);
str = `${str.slice(0, index! + 1)}async${str.slice(index! + 1)}`;

str = str.replace(
/(new Promise\(\()(\([a-zA-Z_\$][\w\$]*,[a-zA-Z_\$][\w\$]*\)=>\{var ([a-zA-Z_\$][\w\$]*)=([a-zA-Z_\$][\w\$]*)\.miniCssF\([a-zA-Z_\$][\w\$]*\),([a-zA-Z_\$][\w\$]*)=\4\.p\+\3)/,
"$1async$2,$5=await __applyTransforms($5)",
);
str = str.replace(
/(new Promise\(\()(\([a-zA-Z_\$][\w\$]*,[a-zA-Z_\$][\w\$]*\)=>\{var ([a-zA-Z_\$][\w\$]*)=([a-zA-Z_\$][\w\$]*)\.miniCssF\([a-zA-Z_\$][\w\$]*\),([a-zA-Z_\$][\w\$]*)=\4\.p\+\3)/,
"$1async$2,$5=await __applyTransforms($5)"
);

emit();
return str;
},
{
glob: /^\/xpui\.js/,
},
);
emit();
return str;
},
{
glob: /^\/xpui\.js/,
}
);

transformer(
emit => str => {
str = str.replace( /(\("[^"]+sentry.io)/, ",$1" );
emit();
return str;
},
{
glob: /^\/xpui\.js/,
},
);
transformer(
emit => str => {
str = str.replace(/(\("[^"]+sentry.io)/, ",$1");
emit();
return str;
},
{
glob: /^\/xpui\.js/,
}
);

transformer(
emit => str => {
str = str.replace( /("incognito-enabled":[a-zA-Z_\$][\w\$]*)/, '$1,employee:"1"' );
str = str.replace(
/([a-zA-Z_\$][\w\$]*)\("app\.enable-developer-mode",([a-zA-Z_\$][\w\$]*)\)/,
'$1("app.enable-developer-mode",$2);$1("app-developer",$2?2:0)',
);
emit();
return str;
},
{
glob: /^\/xpui\.js/,
},
);
transformer(
emit => str => {
str = str.replace(/("incognito-enabled":[a-zA-Z_\$][\w\$]*)/, '$1,employee:"1"');
str = str.replace(
/([a-zA-Z_\$][\w\$]*)\("app\.enable-developer-mode",([a-zA-Z_\$][\w\$]*)\)/,
'$1("app.enable-developer-mode",$2);$1("app-developer",$2?2:0)'
);
emit();
return str;
},
{
glob: /^\/xpui\.js/,
}
);

transformer(
emit => str => {
str = str.replace(
/(([a-zA-Z_\$][\w\$]*)\.data\.type===(?:[a-zA-Z_\$][\w\$]*\.){2}NAVIGATION&&)/,
"$1__interceptNavigationControlMessage($2)&&",
);
emit();
return str;
},
{
glob: /^\/xpui\.js/,
},
);
transformer(
emit => str => {
str = str.replace(
/(([a-zA-Z_\$][\w\$]*)\.data\.type===(?:[a-zA-Z_\$][\w\$]*\.){2}NAVIGATION&&)/,
"$1__interceptNavigationControlMessage($2)&&"
);
emit();
return str;
},
{
glob: /^\/xpui\.js/,
}
);
}
Loading

0 comments on commit c80375d

Please sign in to comment.