fix audio and quality settings menu on wayland (#131)
Co-authored-by: V <vendicated@riseup.net>
This commit is contained in:
parent
ce47f8e1a8
commit
56dd9ea2c8
2 changed files with 35 additions and 20 deletions
|
@ -10,6 +10,9 @@ import { IpcEvents } from "shared/IpcEvents";
|
||||||
|
|
||||||
import { handle } from "./utils/ipcWrappers";
|
import { handle } from "./utils/ipcWrappers";
|
||||||
|
|
||||||
|
const isWayland =
|
||||||
|
process.platform === "linux" && (process.env.XDG_SESSION_TYPE === "wayland" || !!process.env.WAYLAND_DISPLAY);
|
||||||
|
|
||||||
export function registerScreenShareHandler() {
|
export function registerScreenShareHandler() {
|
||||||
handle(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, async (_, id: string) => {
|
handle(IpcEvents.CAPTURER_GET_LARGE_THUMBNAIL, async (_, id: string) => {
|
||||||
const sources = await desktopCapturer.getSources({
|
const sources = await desktopCapturer.getSources({
|
||||||
|
@ -23,17 +26,19 @@ export function registerScreenShareHandler() {
|
||||||
});
|
});
|
||||||
|
|
||||||
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
||||||
const sources = await desktopCapturer.getSources({
|
// 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"],
|
types: ["window", "screen"],
|
||||||
thumbnailSize: {
|
thumbnailSize: {
|
||||||
width: 176,
|
width,
|
||||||
height: 99
|
height: width * (9 / 16)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.catch(err => console.error("Error during screenshare picker", err));
|
||||||
|
|
||||||
const isWayland =
|
if (!sources) return callback({});
|
||||||
process.platform === "linux" &&
|
|
||||||
(process.env.XDG_SESSION_TYPE === "wayland" || !!process.env.WAYLAND_DISPLAY);
|
|
||||||
|
|
||||||
const data = sources.map(({ id, name, thumbnail }) => ({
|
const data = sources.map(({ id, name, thumbnail }) => ({
|
||||||
id,
|
id,
|
||||||
|
@ -43,10 +48,14 @@ export function registerScreenShareHandler() {
|
||||||
|
|
||||||
if (isWayland) {
|
if (isWayland) {
|
||||||
const video = data[0];
|
const video = data[0];
|
||||||
if (video)
|
if (video) {
|
||||||
await request.frame.executeJavaScript(
|
const stream = await request.frame
|
||||||
`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([data])}, true)`
|
.executeJavaScript(
|
||||||
);
|
`Vesktop.Components.ScreenShare.openScreenSharePicker(${JSON.stringify([video])},true)`
|
||||||
|
)
|
||||||
|
.catch(() => null);
|
||||||
|
if (stream === null) return callback({});
|
||||||
|
}
|
||||||
|
|
||||||
callback(video ? { video: sources[0] } : {});
|
callback(video ? { video: sources[0] } : {});
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -71,7 +71,7 @@ addPatch({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export function openScreenSharePicker(screens: Source[], skipPicker = false) {
|
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(
|
||||||
|
@ -119,16 +119,21 @@ function ScreenPicker({ screens, chooseScreen }: { screens: Source[]; chooseScre
|
||||||
function StreamSettings({
|
function StreamSettings({
|
||||||
source,
|
source,
|
||||||
settings,
|
settings,
|
||||||
setSettings
|
setSettings,
|
||||||
|
skipPicker
|
||||||
}: {
|
}: {
|
||||||
source: Source;
|
source: Source;
|
||||||
settings: StreamSettings;
|
settings: StreamSettings;
|
||||||
setSettings: Dispatch<SetStateAction<StreamSettings>>;
|
setSettings: Dispatch<SetStateAction<StreamSettings>>;
|
||||||
|
skipPicker: boolean;
|
||||||
}) {
|
}) {
|
||||||
const [thumb] = useAwaiter(() => VesktopNative.capturer.getLargeThumbnail(source.id), {
|
const [thumb] = useAwaiter(
|
||||||
|
() => (skipPicker ? Promise.resolve(source.url) : VesktopNative.capturer.getLargeThumbnail(source.id)),
|
||||||
|
{
|
||||||
fallbackValue: source.url,
|
fallbackValue: source.url,
|
||||||
deps: [source.id]
|
deps: [source.id]
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -269,6 +274,7 @@ function ModalComponent({
|
||||||
source={screens.find(s => s.id === selected)!}
|
source={screens.find(s => s.id === selected)!}
|
||||||
settings={settings}
|
settings={settings}
|
||||||
setSettings={setSettings}
|
setSettings={setSettings}
|
||||||
|
skipPicker={skipPicker}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Modals.ModalContent>
|
</Modals.ModalContent>
|
||||||
|
|
Reference in a new issue