Workaround Linux Wayland screenshare bug

This commit is contained in:
ayumi-signal 2023-09-12 19:14:07 -07:00 committed by GitHub
parent 944a70abe7
commit d7da7fdca0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 8 deletions

View file

@ -2630,13 +2630,16 @@ ipc.handle('show-save-dialog', async (_event, { defaultPath }) => {
return { canceled: false, filePath: finalFilePath }; return { canceled: false, filePath: finalFilePath };
}); });
ipc.handle('getScreenCaptureSources', async () => { ipc.handle(
return desktopCapturer.getSources({ 'getScreenCaptureSources',
fetchWindowIcons: true, async (_event, types: Array<'screen' | 'window'> = ['screen', 'window']) => {
thumbnailSize: { height: 102, width: 184 }, return desktopCapturer.getSources({
types: ['window', 'screen'], fetchWindowIcons: true,
}); thumbnailSize: { height: 102, width: 184 },
}); types,
});
}
);
ipc.handle('executeMenuRole', async ({ sender }, untypedRole) => { ipc.handle('executeMenuRole', async ({ sender }, untypedRole) => {
const role = untypedRole as MenuItemConstructorOptions['role']; const role = untypedRole as MenuItemConstructorOptions['role'];

View file

@ -95,6 +95,7 @@ import {
import { callingMessageToProto } from '../util/callingMessageToProto'; import { callingMessageToProto } from '../util/callingMessageToProto';
import { getSendOptions } from '../util/getSendOptions'; import { getSendOptions } from '../util/getSendOptions';
import { requestMicrophonePermissions } from '../util/requestMicrophonePermissions'; import { requestMicrophonePermissions } from '../util/requestMicrophonePermissions';
import OS from '../util/os/osMain';
import { SignalService as Proto } from '../protobuf'; import { SignalService as Proto } from '../protobuf';
import dataInterface from '../sql/Client'; import dataInterface from '../sql/Client';
import { import {
@ -1329,8 +1330,20 @@ export class CallingClass {
} }
async getPresentingSources(): Promise<Array<PresentableSource>> { async getPresentingSources(): Promise<Array<PresentableSource>> {
// There's a Linux Wayland Electron bug where requesting desktopCapturer.
// getSources() with types as ['screen', 'window'] (the default) pops 2
// OS permissions dialogs in an unusable state (Dialog 1 for Share Window
// is the foreground and ignores input; Dialog 2 for Share Screen is background
// and requires input. As a workaround, request both sources sequentially.
// https://github.com/signalapp/Signal-Desktop/issues/5350#issuecomment-1688614149
const sources: ReadonlyArray<DesktopCapturerSource> = const sources: ReadonlyArray<DesktopCapturerSource> =
await ipcRenderer.invoke('getScreenCaptureSources'); OS.isLinux() && OS.isWaylandEnabled()
? (
await ipcRenderer.invoke('getScreenCaptureSources', ['screen'])
).concat(
await ipcRenderer.invoke('getScreenCaptureSources', ['window'])
)
: await ipcRenderer.invoke('getScreenCaptureSources');
const presentableSources: Array<PresentableSource> = []; const presentableSources: Array<PresentableSource> = [];

View file

@ -19,9 +19,14 @@ function getLinuxName(): string | undefined {
return match[1]; return match[1];
} }
function isWaylandEnabled(): boolean {
return Boolean(process.env.WAYLAND_DISPLAY);
}
const OS = { const OS = {
...getOSFunctions(os.release()), ...getOSFunctions(os.release()),
getLinuxName, getLinuxName,
isWaylandEnabled,
}; };
export default OS; export default OS;