Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to the new session API for screen-sharing #25802

Merged
merged 7 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type ElectronChannel =
| "setBadgeCount"
| "update-downloaded"
| "userDownloadCompleted"
| "userDownloadAction";
| "userDownloadAction"
| "openDesktopCapturerSourcePicker";

declare global {
interface Window {
Expand Down
9 changes: 9 additions & 0 deletions src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions test/unit-tests/vector/platform/ElectronPlatform-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<void>((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();
Expand Down