Add Settings 'page', gitHash, electron version in settings

This commit is contained in:
Vendicated 2022-08-30 01:42:47 +02:00
parent 80b279d3c3
commit cb288e204d
No known key found for this signature in database
GPG key ID: EC781ADFB93EFFA3
11 changed files with 76 additions and 30 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/node
import { execSync } from "child_process";
import esbuild from "esbuild";
import { readdirSync } from "fs";
import { performance } from "perf_hooks";
@ -59,6 +60,23 @@ const globPlugins = {
}
};
const gitHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();
/**
* @type {esbuild.Plugin}
*/
const gitHashPlugin = {
name: "git-hash-plugin",
setup: build => {
const filter = /^git-hash$/;
build.onResolve({ filter }, args => ({
namespace: "git-hash", path: args.path
}));
build.onLoad({ filter, namespace: "git-hash" }, () => ({
contents: `export default "${gitHash}"`
}));
}
};
const begin = performance.now();
await Promise.all([
esbuild.build({
@ -92,9 +110,10 @@ await Promise.all([
target: ["esnext"],
footer: { js: "//# sourceURL=VencordRenderer" },
globalName: "Vencord",
external: ["plugins"],
external: ["plugins", "git-hash"],
plugins: [
globPlugins
globPlugins,
gitHashPlugin
],
sourcemap: "inline",
watch,

View file

@ -1,6 +1,7 @@
export * as Plugins from "./plugins";
export * as Webpack from "./utils/webpack";
export * as Api from "./api";
export * as Components from "./components";
import "./utils/patchWebpack";
import "./utils/quickCss";

View file

@ -7,5 +7,6 @@ export default {
cb(css);
});
},
getQuickCss: () => ipcRenderer.invoke(IPC_GET_QUICK_CSS) as Promise<string>
getQuickCss: () => ipcRenderer.invoke(IPC_GET_QUICK_CSS) as Promise<string>,
getVersions: () => process.versions
};

View file

@ -0,0 +1,4 @@
export default function Settings(props) {
console.log(props);
return (<p>Hi</p>);
}

View file

@ -1,7 +0,0 @@
import React from "react";
export default () => {
<div>
Hi
</div>;
};

1
src/components/index.ts Normal file
View file

@ -0,0 +1 @@
export { default as Settings } from "./Settings";

View file

@ -1,17 +0,0 @@
import definePlugin from "../utils/types";
export default definePlugin({
name: "ClientInfo",
description: "Adds extra info to Client Info in settings",
author: "Vendicated",
patches: [{
find: "default.versionHash",
replacement: {
match: /\w\.createElement.+?["']Host ["'].+?\):null/,
replace: m => {
const idx = m.indexOf("Host") - 1;
return `${m},${m.slice(0, idx)}"Vencord ".repeat(50),"1.0.0")," ")`;
}
}
}]
});

39
src/plugins/settings.ts Normal file
View file

@ -0,0 +1,39 @@
import definePlugin from "../utils/types";
import gitHash from "git-hash";
export default definePlugin({
name: "Settings",
description: "Adds Settings UI and debug info",
author: "Vendicated",
patches: [{
find: "default.versionHash",
replacement: [
{
match: /return .{1,2}\("div"/,
replace: (m) => {
return `var versions=VencordNative.getVersions();${m}`;
}
},
{
match: /\w\.createElement.+?["']Host ["'].+?\):null/,
replace: m => {
const idx = m.indexOf("Host") - 1;
const template = m.slice(0, idx);
return `${m}, ${template}"Vencord ", "${gitHash}"), " "), ` +
`${template} "Electron ", versions.electron), " "), ` +
`${template} "Chrome ", versions.chrome), " ")`;
}
}
]
}, {
find: "Messages.ACTIVITY_SETTINGS",
replacement: {
match: /\{section:(.{1,2})\.SectionTypes\.HEADER,label:(.{1,2})\.default\.Messages\.ACTIVITY_SETTINGS\}/,
replace: (m, mod) =>
`{section:${mod}.SectionTypes.HEADER,label:"Vencord"},` +
`{section:"Vencord",label:"Vencord",element:Vencord.Components.Settings},` +
`{section:${mod}.SectionTypes.DIVIDER},${m}`
}
}]
});

View file

@ -2,3 +2,8 @@ declare module "plugins" {
const plugins: import("./utils/types").Plugin[];
export default plugins;
}
declare module "git-hash" {
const hash: string;
export default hash;
}

View file

@ -9,7 +9,7 @@
"noImplicitAny": false,
"target": "ESNEXT",
// https://esbuild.github.io/api/#jsx-factory
"jsxFactory": "Vencord.React.createElement",
"jsxFactory": "Vencord.Webpack.Common.React.createElement",
"jsx": "react"
},
"include": ["src/**/*"]