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) => { 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 const sources = await desktopCapturer
.getSources({ .getSources({
types: ["window", "screen"], types: ["window", "screen"],
thumbnailSize: isWayland thumbnailSize: {
? { width,
width: 1920, height: width * (9 / 16)
height: 1080 }
}
: {
width: 176,
height: 99
}
}) })
.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 }) => ({ const data = sources.map(({ id, name, thumbnail }) => ({
id, id,
@ -54,7 +51,7 @@ export function registerScreenShareHandler() {
if (video) { if (video) {
const stream = await request.frame const stream = await request.frame
.executeJavaScript( .executeJavaScript(
`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([video])}, true)` `Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([video])},true)`
) )
.catch(() => null); .catch(() => null);
if (stream === null) return callback({}); if (stream === null) return callback({});
@ -65,7 +62,7 @@ export function registerScreenShareHandler() {
} }
const choice = await request.frame 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) .then(e => e as StreamPick)
.catch(e => { .catch(e => {
console.error("Error during screenshare picker", e); console.error("Error during screenshare picker", e);
@ -75,7 +72,6 @@ export function registerScreenShareHandler() {
if (!choice) return callback({}); if (!choice) return callback({});
const source = sources.find(s => s.id === choice.id); const source = sources.find(s => s.id === choice.id);
if (!source) return callback({}); if (!source) return callback({});
const streams: Streams = { 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; let didSubmit = false;
return new Promise<StreamPick>((resolve, reject) => { return new Promise<StreamPick>((resolve, reject) => {
const key = openModal( 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 }) { function ScreenPicker({ screens, chooseScreen }: { screens: Source[]; chooseScreen: (id: string) => void }) {