aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipcMain.ts3
-rw-r--r--src/preload.ts19
-rw-r--r--src/utils/IpcEvents.ts3
3 files changed, 22 insertions, 3 deletions
diff --git a/src/ipcMain.ts b/src/ipcMain.ts
index 9795ff1..89c49ab 100644
--- a/src/ipcMain.ts
+++ b/src/ipcMain.ts
@@ -2,7 +2,7 @@
import { execFile as cpExecFile } from 'child_process';
import { createHash } from "crypto";
-import { app, BrowserWindow, ipcMain, shell } from "electron";
+import { app, BrowserWindow, desktopCapturer, ipcMain, shell } from "electron";
import { createReadStream, mkdirSync, readFileSync, watch } from "fs";
import { open, readFile, writeFile } from "fs/promises";
import { join } from 'path';
@@ -76,6 +76,7 @@ function serializeErrors(func: (...args: any[]) => any) {
};
}
+ipcMain.handle(IpcEvents.GET_DESKTOP_CAPTURE_SOURCES, (_, opts) => desktopCapturer.getSources(opts));
ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR);
ipcMain.handle(IpcEvents.GET_QUICK_CSS, () => readCss());
ipcMain.handle(IpcEvents.OPEN_PATH, (_, ...pathElements) => shell.openPath(join(...pathElements)));
diff --git a/src/preload.ts b/src/preload.ts
index 73d2eb5..c716d2c 100644
--- a/src/preload.ts
+++ b/src/preload.ts
@@ -1,7 +1,24 @@
-import { contextBridge, webFrame } from "electron";
+import electron, { contextBridge, webFrame } from "electron";
import { readFileSync } from "fs";
import { join } from "path";
import VencordNative from "./VencordNative";
+import { ipcRenderer } from 'electron';
+import IpcEvents from "./utils/IpcEvents";
+
+if (electron.desktopCapturer === void 0) {
+ // Fix for desktopCapturer being main only in Electron 17+
+ // Discord accesses this in discord_desktop_core (DiscordNative.desktopCapture.getDesktopCaptureSources)
+ // and errors with cannot "read property getSources() of undefined"
+ // see discord_desktop_core/app/discord_native/renderer/desktopCapture.js
+ const electronPath = require.resolve("electron");
+ delete require.cache[electronPath]!.exports;
+ require.cache[electronPath]!.exports = {
+ ...electron,
+ desktopCapturer: {
+ getSources: (opts) => ipcRenderer.invoke(IpcEvents.GET_DESKTOP_CAPTURE_SOURCES, opts)
+ }
+ };
+}
contextBridge.exposeInMainWorld("VencordNative", VencordNative);
diff --git a/src/utils/IpcEvents.ts b/src/utils/IpcEvents.ts
index 24e52b9..3ceaa9f 100644
--- a/src/utils/IpcEvents.ts
+++ b/src/utils/IpcEvents.ts
@@ -23,5 +23,6 @@ export default strEnum({
GET_REPO: "VencordGetRepo",
GET_HASHES: "VencordGetHashes",
UPDATE: "VencordUpdate",
- BUILD: "VencordBuild"
+ BUILD: "VencordBuild",
+ GET_DESKTOP_CAPTURE_SOURCES: "VencordGetDesktopCaptureSources"
} as const);