// This desktop capturer has been taken from https://github.com/SpacingBat3/electron-discord-webapp
/*
* Thanks, @WesselKroos!
*/
/*function l10n(origin, locale){
if(originalString == 'Entire Screen') {
return locale;
} else {
return origin;
}
}*/
const { desktopCapturer } = require("electron");
navigator.mediaDevices.getDisplayMedia = () => {
return new Promise(async (resolve, reject) => {
try {
const sources = await desktopCapturer.getSources({
types: ["screen", "window"],
});
const selectionElem = document.createElement("div");
selectionElem.setAttribute("class", "desktop-capturer-selection");
selectionElem.innerHTML = `
`;
document.body.appendChild(selectionElem);
document
.querySelectorAll(".desktop-capturer-selection__btn")
.forEach((button) => {
button.addEventListener("click", async () => {
try {
const id = button.getAttribute("data-id");
const source = sources.find((source) => source.id === id);
if (!source) {
throw new Error(`Source with id ${id} does not exist`);
}
const stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: "desktop",
chromeMediaSourceId: source.id,
},
},
});
resolve(stream);
selectionElem.remove();
} catch (err) {
console.error("Error selecting desktop capture source:", err);
reject(err);
}
});
});
document.querySelectorAll(".desktop-capturer-close").forEach((button) => {
button.addEventListener("click", () => {
selectionElem.remove();
});
});
} catch (err) {
console.error("Error displaying desktop capture sources:", err);
reject(err);
}
});
};
console.log("Desktop capturer has been preloaded 🎉️");