From 6b26c12bfa1f28d40834478b50d2f7b09c9f54fb Mon Sep 17 00:00:00 2001 From: V Date: Tue, 4 Apr 2023 01:16:29 +0200 Subject: [PATCH] Add additional build flavours for Vencord Desktop (#765) --- .github/workflows/build.yml | 2 +- scripts/build/build.mjs | 48 +++++++- src/Vencord.ts | 12 +- src/components/VencordSettings/Updater.tsx | 3 +- src/components/VencordSettings/VencordTab.tsx | 4 +- src/globals.d.ts | 3 + src/main/index.ts | 108 ++++++++++++++++++ src/{ipcMain/index.ts => main/ipcMain.ts} | 10 +- src/{ => main}/patchWin32Updater.ts | 0 src/{ => main}/patcher.ts | 92 +-------------- src/{ipcMain => main}/updater/common.ts | 0 src/{ipcMain => main}/updater/git.ts | 0 src/{ipcMain => main}/updater/http.ts | 24 +++- src/{ipcMain => main}/updater/index.ts | 0 src/{ipcMain => main/utils}/constants.ts | 2 + src/{ipcMain => main/utils}/crxToZip.ts | 0 src/{ipcMain => main/utils}/extensions.ts | 0 src/{ipcMain => main/utils}/simpleGet.ts | 0 src/plugins/consoleShortcuts.ts | 3 +- src/plugins/settings.tsx | 1 + src/preload.ts | 4 +- src/utils/native.ts | 24 ++++ src/utils/settingsSync.ts | 42 +++---- src/utils/updater.ts | 7 +- src/webpack/webpack.ts | 2 +- 25 files changed, 264 insertions(+), 127 deletions(-) create mode 100644 src/main/index.ts rename src/{ipcMain/index.ts => main/ipcMain.ts} (93%) rename src/{ => main}/patchWin32Updater.ts (100%) rename src/{ => main}/patcher.ts (52%) rename src/{ipcMain => main}/updater/common.ts (100%) rename src/{ipcMain => main}/updater/git.ts (100%) rename src/{ipcMain => main}/updater/http.ts (81%) rename src/{ipcMain => main}/updater/index.ts (100%) rename src/{ipcMain => main/utils}/constants.ts (94%) rename src/{ipcMain => main/utils}/crxToZip.ts (100%) rename src/{ipcMain => main/utils}/extensions.ts (100%) rename src/{ipcMain => main/utils}/simpleGet.ts (100%) create mode 100644 src/utils/native.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7a95cf0..f2787070 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - name: Clean up obsolete files run: | - rm -rf dist/extension* Vencord.user.css + rm -rf dist/extension* Vencord.user.css vencordDesktopRenderer.css vencordDesktopRenderer.css.map - name: Get some values needed for the release id: release_values diff --git a/scripts/build/build.mjs b/scripts/build/build.mjs index 70a05cf9..a4b06f53 100755 --- a/scripts/build/build.mjs +++ b/scripts/build/build.mjs @@ -48,6 +48,7 @@ const sourceMapFooter = s => watch ? "" : `//# sourceMappingURL=vencord://${s}.j const sourcemap = watch ? "inline" : "external"; await Promise.all([ + // common preload esbuild.build({ ...nodeCommonOpts, entryPoints: ["src/preload.ts"], @@ -55,12 +56,19 @@ await Promise.all([ footer: { js: "//# sourceURL=VencordPreload\n" + sourceMapFooter("preload") }, sourcemap, }), + + // Discord Desktop main & renderer esbuild.build({ ...nodeCommonOpts, - entryPoints: ["src/patcher.ts"], + entryPoints: ["src/main/index.ts"], outfile: "dist/patcher.js", footer: { js: "//# sourceURL=VencordPatcher\n" + sourceMapFooter("patcher") }, sourcemap, + define: { + ...defines, + IS_DISCORD_DESKTOP: true, + IS_VENCORD_DESKTOP: false + } }), esbuild.build({ ...commonOpts, @@ -77,7 +85,43 @@ await Promise.all([ ], define: { ...defines, - IS_WEB: false + IS_WEB: false, + IS_DISCORD_DESKTOP: true, + IS_VENCORD_DESKTOP: false + } + }), + + // Vencord Desktop main & renderer + esbuild.build({ + ...nodeCommonOpts, + entryPoints: ["src/main/index.ts"], + outfile: "dist/vencordDesktopMain.js", + footer: { js: "//# sourceURL=VencordDesktopMain\n" + sourceMapFooter("vencordDesktopMain") }, + sourcemap, + define: { + ...defines, + IS_DISCORD_DESKTOP: false, + IS_VENCORD_DESKTOP: true + } + }), + esbuild.build({ + ...commonOpts, + entryPoints: ["src/Vencord.ts"], + outfile: "dist/vencordDesktopRenderer.js", + format: "iife", + target: ["esnext"], + footer: { js: "//# sourceURL=VencordDesktopRenderer\n" + sourceMapFooter("vencordDesktopRenderer") }, + globalName: "Vencord", + sourcemap, + plugins: [ + globPlugins, + ...commonOpts.plugins + ], + define: { + ...defines, + IS_WEB: false, + IS_DISCORD_DESKTOP: false, + IS_VENCORD_DESKTOP: true } }), ]).catch(err => { diff --git a/src/Vencord.ts b/src/Vencord.ts index 00f8a58c..73b53e84 100644 --- a/src/Vencord.ts +++ b/src/Vencord.ts @@ -30,7 +30,7 @@ import "./webpack/patchWebpack"; import { showNotification } from "./api/Notifications"; import { PlainSettings, Settings } from "./api/settings"; import { patches, PMLogger, startAllPlugins } from "./plugins"; -import { checkForUpdates, rebuild, update, UpdateLogger } from "./utils/updater"; +import { checkForUpdates, rebuild, update,UpdateLogger } from "./utils/updater"; import { onceReady } from "./webpack"; import { SettingsRouter } from "./webpack/common"; @@ -56,8 +56,12 @@ async function init() { permanent: true, noPersist: true, onClick() { - if (needsFullRestart) - window.DiscordNative.app.relaunch(); + if (needsFullRestart) { + if (IS_DISCORD_DESKTOP) + window.DiscordNative.app.relaunch(); + else + window.VencordDesktop.app.relaunch(); + } else location.reload(); } @@ -96,7 +100,7 @@ async function init() { init(); -if (!IS_WEB && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { +if (IS_DISCORD_DESKTOP && Settings.winNativeTitleBar && navigator.platform.toLowerCase().startsWith("win")) { document.addEventListener("DOMContentLoaded", () => { document.head.append(Object.assign(document.createElement("style"), { id: "vencord-native-titlebar-style", diff --git a/src/components/VencordSettings/Updater.tsx b/src/components/VencordSettings/Updater.tsx index 3c3eb91b..15a8c87a 100644 --- a/src/components/VencordSettings/Updater.tsx +++ b/src/components/VencordSettings/Updater.tsx @@ -24,6 +24,7 @@ import { handleComponentFailed } from "@components/handleComponentFailed"; import { Link } from "@components/Link"; import { Margins } from "@utils/margins"; import { classes, useAwaiter } from "@utils/misc"; +import { relaunch } from "@utils/native"; import { changes, checkForUpdates, getRepo, isNewer, rebuild, update, updateError, UpdateLogger } from "@utils/updater"; import { Alerts, Button, Card, Forms, Parser, React, Switch, Toasts } from "@webpack/common"; @@ -133,7 +134,7 @@ function Updatable(props: CommonProps) { cancelText: "Not now!", onConfirm() { if (needFullRestart) - window.DiscordNative.app.relaunch(); + relaunch(); else location.reload(); r(); diff --git a/src/components/VencordSettings/VencordTab.tsx b/src/components/VencordSettings/VencordTab.tsx index 7113421a..8b869684 100644 --- a/src/components/VencordSettings/VencordTab.tsx +++ b/src/components/VencordSettings/VencordTab.tsx @@ -26,6 +26,7 @@ import { ErrorCard } from "@components/ErrorCard"; import IpcEvents from "@utils/IpcEvents"; import { Margins } from "@utils/margins"; import { identity, useAwaiter } from "@utils/misc"; +import { relaunch } from "@utils/native"; import { Button, Card, Forms, React, Select, Slider, Switch } from "@webpack/common"; const cl = classNameFactory("vc-settings-"); @@ -100,7 +101,7 @@ function VencordSettings() { ) : ( @@ -111,6 +112,7 @@ function VencordSettings() { Open QuickCSS File