Skip to content

Instantly share code, notes, and snippets.

@Vendicated
Last active March 12, 2023 17:59
Show Gist options
  • Save Vendicated/5e5eee64348ee936349367fe7cedd8c3 to your computer and use it in GitHub Desktop.
Save Vendicated/5e5eee64348ee936349367fe7cedd8c3 to your computer and use it in GitHub Desktop.
discord_arch_electron stream fix
const electron = require("electron");
const { join } = require("path");
class BrowserWindow extends electron.BrowserWindow {
constructor(options) {
if (options?.webPreferences?.preload && options.title) {
// Replace Discords preload script with our own
process.env.DISCORD_PRELOAD = options.webPreferences.preload;
options.webPreferences.preload = join(__dirname, "preload.js");
// Fix for sandbox being on by default in newer electron versions
options.webPreferences.sandbox = false;
}
super(options);
}
}
Object.assign(BrowserWindow, electron.BrowserWindow);
electron.ipcMain.handle("DAE_GET_STREAM_SOURCES", (_, opts) =>
electron.desktopCapturer.getSources(opts)
);
// Patch electron with our modified BrowserWindow
const electronPath = require.resolve("electron");
delete require.cache[electronPath].exports;
require.cache[electronPath].exports = {
...electron,
BrowserWindow,
};
// Load original asar
require("../_app.asar");
{
"main": "index.js",
"name": "discord"
}
const electron = require("electron");
// Patch preload electron to polyfill the now extinct desktopCapturer
const electronPath = require.resolve("electron");
delete require.cache[electronPath].exports;
require.cache[electronPath].exports = {
...electron,
desktopCapturer: {
getSources: (opts) => electron.ipcRenderer.invoke("DAE_GET_STREAM_SOURCES", opts),
},
};
// Load Discord's own preload script now
require(process.env.DISCORD_PRELOAD);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment