diff --git a/scripts/build/build.mts b/scripts/build/build.mts index 636dea0..2aa98fc 100644 --- a/scripts/build/build.mts +++ b/scripts/build/build.mts @@ -8,6 +8,7 @@ import { BuildContext, BuildOptions, context } from "esbuild"; import { copyFile } from "fs/promises"; import vencordDep from "./vencordDep.mjs"; +import { includeDirPlugin } from "./includeDirPlugin.mts"; const isDev = process.argv.includes("--dev"); @@ -78,7 +79,7 @@ await Promise.all([ jsxFactory: "VencordCreateElement", jsxFragment: "VencordFragment", external: ["@vencord/types/*"], - plugins: [vencordDep], + plugins: [vencordDep, includeDirPlugin("patches", "src/renderer/patches")], footer: { js: "//# sourceURL=VCDRenderer" } }) ]); diff --git a/scripts/build/includeDirPlugin.mts b/scripts/build/includeDirPlugin.mts new file mode 100644 index 0000000..83bea4c --- /dev/null +++ b/scripts/build/includeDirPlugin.mts @@ -0,0 +1,25 @@ +import { Plugin } from "esbuild"; +import { readdir } from "fs/promises"; + +const makeImportAllCode = (files: string[]) => + files.map(f => `require("./${f.replace(/\.[cm]?[tj]sx?$/, "")}")`).join("\n"); + +const makeImportDirRecursiveCode = (dir: string) => readdir(dir).then(files => makeImportAllCode(files)); + +export function includeDirPlugin(namespace: string, path: string): Plugin { + return { + name: `include-dir-plugin:${namespace}`, + setup(build) { + const filter = new RegExp(`^__${namespace}__$`); + + build.onResolve({ filter }, args => ({ path: args.path, namespace })); + + build.onLoad({ filter, namespace }, async args => { + return { + contents: await makeImportDirRecursiveCode(path), + resolveDir: path + }; + }); + } + }; +} diff --git a/src/module.d.ts b/src/module.d.ts new file mode 100644 index 0000000..61d1df0 --- /dev/null +++ b/src/module.d.ts @@ -0,0 +1,10 @@ +/* + * Vesktop, a desktop app aiming to give you a snappier Discord Experience + * Copyright (c) 2025 Vendicated and Vesktop contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +declare module "__patches__" { + const never: never; + export default never; +} diff --git a/src/renderer/index.ts b/src/renderer/index.ts index 4e4a3ed..aba68c1 100644 --- a/src/renderer/index.ts +++ b/src/renderer/index.ts @@ -7,9 +7,9 @@ import "./themedSplash"; import "./ipcCommands"; import "./appBadge"; -import "./patches"; import "./fixes"; import "./arrpc"; +import "__patches__"; // auto generated by the build script export * as Components from "./components"; diff --git a/src/renderer/patches/hideSwitchDevice.tsx b/src/renderer/patches/hideSwitchDevice.tsx index f0a7597..773f7b0 100644 --- a/src/renderer/patches/hideSwitchDevice.tsx +++ b/src/renderer/patches/hideSwitchDevice.tsx @@ -13,12 +13,12 @@ addPatch({ replacement: { // eslint-disable-next-line no-useless-escape match: /(\i)\.\i\.getState\(\).neverShowModal/, - replace: "$& || $self.shouldIgnore($1)" + replace: "$& || $self.shouldIgnoreDevice($1)" } } ], - shouldIgnore(state: any) { + shouldIgnoreDevice(state: any) { return Object.keys(state?.default?.lastDeviceConnected ?? {})?.[0] === "vencord-screen-share"; } }); diff --git a/src/renderer/patches/index.ts b/src/renderer/patches/index.ts deleted file mode 100644 index fc3e414..0000000 --- a/src/renderer/patches/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Vesktop, a desktop app aiming to give you a snappier Discord Experience - * Copyright (c) 2023 Vendicated and Vencord contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -// TODO: Possibly auto generate glob if we have more patches in the future -import "./enableNotificationsByDefault"; -import "./platformClass"; -import "./allowDevToolsKeybind"; -import "./hideSwitchDevice"; -import "./hideVenmicInput"; -import "./screenShareFixes"; -import "./spellCheck"; -import "./windowsTitleBar"; -import "./streamerMode"; -import "./windowMethods"; -import "./hideDownloadAppsButton"; -import "./fixAutoGainToggle";