Fix DiscordNative.desktopCapture.getDesktopCaptureSources() in electron17+

main
Vendicated 2 years ago
parent be94dbbc6c
commit cac77dce40
No known key found for this signature in database
GPG Key ID: EC781ADFB93EFFA3

@ -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)));

@ -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);

@ -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);

Loading…
Cancel
Save