Skip to content

Commit

Permalink
Merge pull request #27675 from element-hq/travis/authed-media-ipc
Browse files Browse the repository at this point in the history
Add Electron IPC APIs for authenticated media
  • Loading branch information
turt2live authored Jul 10, 2024
2 parents 6d84073 + 8e03b27 commit 39bdcaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/@types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ type ElectronChannel =
| "update-downloaded"
| "userDownloadCompleted"
| "userDownloadAction"
| "openDesktopCapturerSourcePicker";
| "openDesktopCapturerSourcePicker"
| "userAccessToken"
| "serverSupportedVersions";

declare global {
interface Window {
Expand Down
14 changes: 14 additions & 0 deletions src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ 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 { OidcRegistrationClientMetadata } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg } from "matrix-react-sdk/src/MatrixClientPeg";

import VectorBasePlatform from "./VectorBasePlatform";
import { SeshatIndexManager } from "./SeshatIndexManager";
Expand Down Expand Up @@ -127,6 +128,19 @@ export default class ElectronPlatform extends VectorBasePlatform {
});
});

// `userAccessToken` (IPC) is requested by the main process when appending authentication
// to media downloads. A reply is sent over the same channel.
window.electron.on("userAccessToken", () => {
window.electron!.send("userAccessToken", MatrixClientPeg.get()?.getAccessToken());
});

// `serverSupportedVersions` is requested by the main process when it needs to know if the
// server supports a particular version. This is primarily used to detect authenticated media
// support. A reply is sent over the same channel.
window.electron.on("serverSupportedVersions", async () => {
window.electron!.send("serverSupportedVersions", await MatrixClientPeg.get()?.getVersions());
});

// try to flush the rageshake logs to indexeddb before quit.
window.electron.on("before-quit", function () {
logger.log("element-desktop closing");
Expand Down

0 comments on commit 39bdcaf

Please sign in to comment.