From 93e6ee11ab8fe010eb7591ea93437b1e13abf96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Fri, 14 Jul 2023 22:05:23 +0200 Subject: [PATCH] Switch to the new `session` API for screen-sharing (#25802) --- src/@types/global.d.ts | 3 +- src/vector/platform/ElectronPlatform.tsx | 9 ++++++ .../vector/platform/ElectronPlatform-test.ts | 32 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/@types/global.d.ts b/src/@types/global.d.ts index 5047aeeed5..0145673ec9 100644 --- a/src/@types/global.d.ts +++ b/src/@types/global.d.ts @@ -32,7 +32,8 @@ type ElectronChannel = | "setBadgeCount" | "update-downloaded" | "userDownloadCompleted" - | "userDownloadAction"; + | "userDownloadAction" + | "openDesktopCapturerSourcePicker"; declare global { interface Window { diff --git a/src/vector/platform/ElectronPlatform.tsx b/src/vector/platform/ElectronPlatform.tsx index b18b1abe4e..05c2564395 100644 --- a/src/vector/platform/ElectronPlatform.tsx +++ b/src/vector/platform/ElectronPlatform.tsx @@ -43,6 +43,7 @@ import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore"; import { UPDATE_EVENT } from "matrix-react-sdk/src/stores/AsyncStore"; import { avatarUrlForRoom, getInitialLetter } from "matrix-react-sdk/src/Avatar"; +import DesktopCapturerSourcePicker from "matrix-react-sdk/src/components/views/elements/DesktopCapturerSourcePicker"; import VectorBasePlatform from "./VectorBasePlatform"; import { SeshatIndexManager } from "./SeshatIndexManager"; @@ -163,6 +164,14 @@ export default class ElectronPlatform extends VectorBasePlatform { }); }); + window.electron.on("openDesktopCapturerSourcePicker", () => { + const { finished } = Modal.createDialog(DesktopCapturerSourcePicker); + finished.then(([source]) => { + if (!source) return; + this.ipc.call("callDisplayMediaCallback", source); + }); + }); + this.ipc.call("startSSOFlow", this.ssoID); BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate); diff --git a/test/unit-tests/vector/platform/ElectronPlatform-test.ts b/test/unit-tests/vector/platform/ElectronPlatform-test.ts index 653c5cf3f5..3c93f98a28 100644 --- a/test/unit-tests/vector/platform/ElectronPlatform-test.ts +++ b/test/unit-tests/vector/platform/ElectronPlatform-test.ts @@ -21,6 +21,9 @@ import { Action } from "matrix-react-sdk/src/dispatcher/actions"; import dispatcher from "matrix-react-sdk/src/dispatcher/dispatcher"; import * as rageshake from "matrix-react-sdk/src/rageshake/rageshake"; import { BreadcrumbsStore } from "matrix-react-sdk/src/stores/BreadcrumbsStore"; +import Modal from "matrix-react-sdk/src/Modal"; +import DesktopCapturerSourcePicker from "matrix-react-sdk/src/components/views/elements/DesktopCapturerSourcePicker"; +import { mocked } from "jest-mock"; import ElectronPlatform from "../../../../src/vector/platform/ElectronPlatform"; @@ -76,6 +79,35 @@ describe("ElectronPlatform", () => { expect(dispatchFireSpy).toHaveBeenCalledWith(Action.ViewUserSettings); }); + it("creates a modal on openDesktopCapturerSourcePicker", async () => { + const plat = new ElectronPlatform(); + Modal.createDialog = jest.fn(); + + // @ts-ignore mock + mocked(Modal.createDialog).mockReturnValue({ + finished: new Promise((r) => r(["source"])), + }); + + let res: () => void; + const waitForIPCSend = new Promise((r) => { + res = r; + }); + // @ts-ignore mock + jest.spyOn(plat.ipc, "call").mockImplementation(() => { + res(); + }); + + const [event, handler] = getElectronEventHandlerCall("openDesktopCapturerSourcePicker")!; + handler(); + + await waitForIPCSend; + + expect(event).toBeTruthy(); + expect(Modal.createDialog).toHaveBeenCalledWith(DesktopCapturerSourcePicker); + // @ts-ignore mock + expect(plat.ipc.call).toHaveBeenCalledWith("callDisplayMediaCallback", "source"); + }); + describe("updates", () => { it("dispatches on check updates action", () => { new ElectronPlatform();