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

Allow desktop app to expose recent rooms in UI integrations #16940

Merged
merged 5 commits into from
Mar 22, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ import ToastStore from "matrix-react-sdk/src/stores/ToastStore";
import GenericExpiringToast from "matrix-react-sdk/src/components/views/toasts/GenericExpiringToast";
import { logger } from "matrix-js-sdk/src/logger";
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 VectorBasePlatform from "./VectorBasePlatform";
import { SeshatIndexManager } from "./SeshatIndexManager";
import { IPCManager } from "./IPCManager";

interface SquirrelUpdate {
releaseNotes: string;
releaseName: string;
releaseDate: Date;
updateURL: string;
}

const isMac = navigator.platform.toUpperCase().includes("MAC");

function platformFriendlyName(): string {
Expand Down Expand Up @@ -150,13 +160,29 @@ export default class ElectronPlatform extends VectorBasePlatform {
});

this.ipc.call("startSSOFlow", this.ssoID);

BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate);
}

public async getConfig(): Promise<IConfigOptions> {
return this.ipc.call("getConfig");
}

private onUpdateDownloaded = async (ev, { releaseNotes, releaseName }): Promise<void> => {
private onBreadcrumbsUpdate = (): void => {
const rooms = BreadcrumbsStore.instance.rooms.slice(0, 7).map((r) => ({
roomId: r.roomId,
avatarUrl: avatarUrlForRoom(
r,
Math.floor(60 * window.devicePixelRatio),
Math.floor(60 * window.devicePixelRatio),
"crop",
),
initial: getInitialLetter(r.name),
}));
this.ipc.call("breadcrumbs", rooms);
};

private onUpdateDownloaded = async (ev: Event, { releaseNotes, releaseName }: SquirrelUpdate): Promise<void> => {
dis.dispatch<CheckUpdatesPayload>({
action: Action.CheckUpdates,
status: UpdateCheckStatus.Ready,
Expand Down
18 changes: 17 additions & 1 deletion test/unit-tests/vector/platform/ElectronPlatform-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { UpdateCheckStatus } from "matrix-react-sdk/src/BasePlatform";
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 ElectronPlatform from "../../../../src/vector/platform/ElectronPlatform";

Expand All @@ -43,7 +44,6 @@ describe("ElectronPlatform", () => {
const userId = "@alice:server.org";
const deviceId = "device-id";

window.electron = mockElectron;
beforeEach(() => {
window.electron = mockElectron;
jest.clearAllMocks();
Expand Down Expand Up @@ -260,4 +260,20 @@ describe("ElectronPlatform", () => {
expect(mockElectron.send).toHaveBeenCalledWith("install_update");
});
});

describe("breacrumbs", () => {
it("should send breadcrumb updates over the IPC", () => {
const spy = jest.spyOn(BreadcrumbsStore.instance, "on");
new ElectronPlatform();
const cb = spy.mock.calls[0][1];
cb();

expect(mockElectron.send).toHaveBeenCalledWith(
"ipcCall",
expect.objectContaining({
name: "breadcrumbs",
}),
);
});
});
});