diff --git a/index.ts b/index.ts index bfdc55a..d58f73b 100644 --- a/index.ts +++ b/index.ts @@ -8,7 +8,7 @@ import { ApplicationCommandInputType, Argument, CommandContext } from "@api/Comm import { gitHash } from "@shared/vencordUserAgent"; import { Devs } from "@utils/constants"; import { sendMessage } from "@utils/discord"; -import definePlugin, { Plugin } from "@utils/types"; +import definePlugin, { Plugin, PluginNative } from "@utils/types"; import { GuildMemberStore, UserStore } from "@webpack/common"; import { PluginMeta } from "~plugins"; @@ -18,6 +18,8 @@ import { findByCodeLazy } from "@webpack"; import { getUserSettingLazy } from "../../api/UserSettings.js"; import SettingsPlugin from "../../plugins/_core/settings"; +const Native = VencordNative.pluginHelpers.venfetch as PluginNative; + const clientVersion = () => { const version = IS_DISCORD_DESKTOP ? DiscordNative.app.getVersion() : IS_VESKTOP ? VesktopNative.app.getVersion() : null; // @ts-ignore @@ -100,27 +102,7 @@ function getContribStatus() { return isPluginDev(userId) || GuildMemberStore.getMember("1015060230222131221", userId).roles.includes("1026534353167208489"); } -function humanFileSize(bytes, si = false, dp = 1) { - const thresh = si ? 1000 : 1024; - if (Math.abs(bytes) < thresh) { - return bytes + " B"; - } - - const units = si - ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] - : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]; - let u = -1; - const r = 10 ** dp; - - do { - bytes /= thresh; - ++u; - } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); - - - return bytes.toFixed(dp) + " " + units[u]; -} const getVersions = findByCodeLazy("logsUploaded:new Date().toISOString(),"); const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; @@ -135,7 +117,7 @@ export default definePlugin({ name: "venfetch", description: "neofetch for vencord", inputType: ApplicationCommandInputType.BUILT_IN, - execute: (args: Argument[], ctx: CommandContext) => { + execute: async (args: Argument[], ctx: CommandContext) => { const commonIssues = { "NoRPC": Vencord.Plugins.isPluginEnabled("NoRPC"), "disabled activities": tryOrElse(() => !ShowCurrentGame.getSetting(), false), @@ -143,6 +125,8 @@ export default definePlugin({ "likes java": ['287555395151593473', '886685857560539176', "728342296696979526"].includes(UserStore.getCurrentUser().id), }; + const memory = await Native?.getMemory(); + const { username } = UserStore.getCurrentUser(); const versions = getVersions(); const info: Record = { @@ -157,8 +141,7 @@ export default definePlugin({ platform: navigator.userAgentData?.platform ? `${navigator.userAgentData?.platform} (${navigator.platform})` : navigator.platform, plugins: getEnabledPlugins(), uptime: `${~~((Date.now() - window.GLOBAL_ENV.HTML_TIMESTAMP) / 1000)}s`, - // TODO: add to native.ts - // memory: `${humanFileSize(VencordNative.memoryUsage().heapUsed)} / ${humanFileSize(VencordNative.memoryUsage().heapTotal)}`, + memory: memory ? `${humanFileSize(memory.heapUsed)} / ${humanFileSize(memory.heapTotal)}` : '', __: null, @@ -188,7 +171,7 @@ export default definePlugin({ else if (line[0] === "__COLOR_TEST__") str += line[0] + "\n"; else str += "\n"; } else { if (line && line[1] !== null && line[0] !== "__COLOR_TEST__") str += `\t${" ".repeat(22)}${t(line[0])}: ${line[1]}\n`; - else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(25)}${line[1]}\n`; else str += "\n"; + else if (line[0] === "__COLOR_TEST__") str += `${" ".repeat(22)}${line[1]}\n`; else str += "\n"; } } @@ -202,3 +185,24 @@ export default definePlugin({ }); const t = (e: string) => e.length > 0 ? e[0].toUpperCase() + e.slice(1) : ""; +function humanFileSize(bytes, si = false, dp = 1) { + const thresh = si ? 1000 : 1024; + + if (Math.abs(bytes) < thresh) { + return bytes + " B"; + } + + const units = si + ? ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] + : ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]; + let u = -1; + const r = 10 ** dp; + + do { + bytes /= thresh; + ++u; + } while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1); + + + return bytes.toFixed(dp) + " " + units[u]; +} diff --git a/native.ts b/native.ts new file mode 100644 index 0000000..7095bc2 --- /dev/null +++ b/native.ts @@ -0,0 +1,8 @@ + +export function getMemory() { + const memory = process.memoryUsage(); + return { + heapUsed: memory.heapUsed, + heapTotal: memory.heapTotal + }; +}