[skip ci] Add version to /vencord-debug

This commit is contained in:
V 2023-06-16 19:07:22 +02:00
parent 662c0227eb
commit eaeb60308e
No known key found for this signature in database
GPG Key ID: A1DC0CFB5615D905
6 changed files with 32 additions and 22 deletions

@ -41,12 +41,5 @@
"path": "modifyResponseHeaders.json"
}
]
},
"browser_specific_settings": {
"gecko": {
"id": "vencord-firefox@vendicated.dev",
"strict_min_version": "109.0"
}
}
}

@ -19,11 +19,13 @@
import esbuild from "esbuild";
import { commonOpts, globPlugins, isStandalone, watch } from "./common.mjs";
import { commonOpts, globPlugins, isStandalone, VERSION, watch } from "./common.mjs";
const defines = {
IS_STANDALONE: isStandalone,
IS_DEV: JSON.stringify(watch)
IS_DEV: JSON.stringify(watch),
VERSION: JSON.stringify(VERSION),
BUILD_TIMESTAMP: Date.now(),
};
if (defines.IS_STANDALONE === "false")
// If this is a local build (not standalone), optimise

@ -24,9 +24,7 @@ import { readFileSync } from "fs";
import { appendFile, mkdir, readFile, rm, writeFile } from "fs/promises";
import { join } from "path";
// wtf is this assert syntax
import PackageJSON from "../../package.json" assert { type: "json" };
import { commonOpts, globPlugins, watch } from "./common.mjs";
import { commonOpts, globPlugins, VERSION, watch } from "./common.mjs";
/**
* @type {esbuild.BuildOptions}
@ -47,7 +45,9 @@ const commonOptions = {
IS_STANDALONE: "true",
IS_DEV: JSON.stringify(watch),
IS_DISCORD_DESKTOP: "false",
IS_VENCORD_DESKTOP: "false"
IS_VENCORD_DESKTOP: "false",
VERSION: JSON.stringify(VERSION),
BUILD_TIMESTAMP: Date.now(),
}
};
@ -67,7 +67,7 @@ await Promise.all(
},
outfile: "dist/Vencord.user.js",
banner: {
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${PackageJSON.version}.${new Date().getTime()}`)
js: readFileSync("browser/userscript.meta.js", "utf-8").replace("%version%", `${VERSION}.${new Date().getTime()}`)
},
footer: {
// UserScripts get wrapped in an iife, so define Vencord prop on window that returns our local
@ -88,7 +88,7 @@ async function buildPluginZip(target, files, shouldZip) {
let content = await readFile(join("browser", f));
if (f.startsWith("manifest")) {
const json = JSON.parse(content.toString("utf-8"));
json.version = PackageJSON.version;
json.version = VERSION;
content = new TextEncoder().encode(JSON.stringify(json));
}

@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import "../suppressExperimentalWarnings.js";
import "../checkNodeVersion.js";
import { exec, execSync } from "child_process";
@ -24,6 +25,11 @@ import { readdir, readFile } from "fs/promises";
import { join, relative } from "path";
import { promisify } from "util";
// wtf is this assert syntax
import PackageJSON from "../../package.json" assert { type: "json" };
export const VERSION = PackageJSON.version;
export const BUILD_TIMESTAMP = Date.now();
export const watch = process.argv.includes("--watch");
export const isStandalone = JSON.stringify(process.argv.includes("--standalone"));
export const gitHash = execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim();

2
src/globals.d.ts vendored

@ -37,6 +37,8 @@ declare global {
export var IS_STANDALONE: boolean;
export var IS_DISCORD_DESKTOP: boolean;
export var IS_VENCORD_DESKTOP: boolean;
export var VERSION: string;
export var BUILD_TIMESTAMP: number;
export var VencordNative: typeof import("./VencordNative").default;
export var Vencord: typeof import("./Vencord");

@ -55,7 +55,10 @@ export default definePlugin({
if (IS_DISCORD_DESKTOP) return `Discord Desktop v${DiscordNative.app.getVersion()}`;
if (IS_VENCORD_DESKTOP) return `Vencord Desktop v${VencordDesktopNative.app.getVersion()}`;
if ("armcord" in window) return `ArmCord v${window.armcord.version}`;
return `Web (${navigator.userAgent})`;
// @ts-expect-error
const name = typeof unsafeWindow !== "undefined" ? "UserScript" : "Web";
return `${name} (${navigator.userAgent})`;
})();
const isApiPlugin = (plugin: string) => plugin.endsWith("API") || plugins[plugin].required;
@ -63,14 +66,18 @@ export default definePlugin({
const enabledPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p));
const enabledApiPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && isApiPlugin(p));
const info = {
Vencord: `v${VERSION}${gitHash}${settings.additionalInfo} - ${Intl.DateTimeFormat("en-GB", { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`,
"Discord Branch": RELEASE_CHANNEL,
Client: client,
Platform: window.navigator.platform,
Outdated: isOutdated,
OpenAsar: "openasar" in window,
};
const debugInfo = `
**Vencord Debug Info**
>>> Discord Branch: ${RELEASE_CHANNEL}
Client: ${client}
Platform: ${window.navigator.platform}
Vencord: ${gitHash}${settings.additionalInfo}
Outdated: ${isOutdated}
OpenAsar: ${"openasar" in window}
>>> ${Object.entries(info).map(([k, v]) => `${k}: ${v}`).join("\n")}
Enabled Plugins (${enabledPlugins.length + enabledApiPlugins.length}):
${makeCodeblock(enabledPlugins.join(", ") + "\n\n" + enabledApiPlugins.join(", "))}