This commit is contained in:
Vendicated 2023-10-11 17:41:51 +02:00
parent c710f67014
commit 7313d47ae9
No known key found for this signature in database
GPG key ID: D66986BAF75ECF18
2 changed files with 12 additions and 16 deletions

View file

@ -26,22 +26,19 @@ export function registerScreenShareHandler() {
});
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
// request full resolution on wayland right away because we always only end up with one result anyway
const width = isWayland ? 1920 : 176;
const sources = await desktopCapturer
.getSources({
types: ["window", "screen"],
thumbnailSize: isWayland
? {
width: 1920,
height: 1080
}
: {
width: 176,
height: 99
}
thumbnailSize: {
width,
height: width * (9 / 16)
}
})
.catch(() => null);
.catch(err => console.error("Error during screenshare picker", err));
if (sources === null) return callback({});
if (!sources) return callback({});
const data = sources.map(({ id, name, thumbnail }) => ({
id,
@ -54,7 +51,7 @@ export function registerScreenShareHandler() {
if (video) {
const stream = await request.frame
.executeJavaScript(
`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([video])}, true)`
`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([video])},true)`
)
.catch(() => null);
if (stream === null) return callback({});
@ -65,7 +62,7 @@ export function registerScreenShareHandler() {
}
const choice = await request.frame
.executeJavaScript(`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify(data)}, false)`)
.executeJavaScript(`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify(data)})`)
.then(e => e as StreamPick)
.catch(e => {
console.error("Error during screenshare picker", e);
@ -75,7 +72,6 @@ export function registerScreenShareHandler() {
if (!choice) return callback({});
const source = sources.find(s => s.id === choice.id);
if (!source) return callback({});
const streams: Streams = {

View file

@ -71,7 +71,7 @@ addPatch({
}
});
export async function openScreenSharePicker(screens: Source[], skipPicker: boolean) {
export function openScreenSharePicker(screens: Source[], skipPicker: boolean) {
let didSubmit = false;
return new Promise<StreamPick>((resolve, reject) => {
const key = openModal(
@ -98,7 +98,7 @@ export async function openScreenSharePicker(screens: Source[], skipPicker: boole
}
}
);
}).catch(null);
});
}
function ScreenPicker({ screens, chooseScreen }: { screens: Source[]; chooseScreen: (id: string) => void }) {