Last active
March 12, 2023 17:59
-
-
Save Vendicated/5e5eee64348ee936349367fe7cedd8c3 to your computer and use it in GitHub Desktop.
discord_arch_electron stream fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "index.js", | |
"name": "discord" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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