mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-31 13:39:58 +01:00
Switch to the new session
API for screen-sharing
See https://github.com/electron/electron/pull/30702 - this has the benefit of the js-sdk and LiveKit not having to add custom logic for Electron Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
4e69dda7d2
commit
a21e5afb84
29
src/displayMediaCallback.ts
Normal file
29
src/displayMediaCallback.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 New Vector Ltd
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Streams } from "electron";
|
||||||
|
|
||||||
|
type DisplayMediaCallback = (streams: Streams) => void;
|
||||||
|
|
||||||
|
let displayMediaCallback: DisplayMediaCallback | null;
|
||||||
|
|
||||||
|
export const getDisplayMediaCallback = (): DisplayMediaCallback | null => {
|
||||||
|
return displayMediaCallback;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const setDisplayMediaCallback = (callback: DisplayMediaCallback | null): void => {
|
||||||
|
displayMediaCallback = callback;
|
||||||
|
};
|
@ -19,7 +19,7 @@ limitations under the License.
|
|||||||
|
|
||||||
// Squirrel on windows starts the app with various flags as hooks to tell us when we've been installed/uninstalled etc.
|
// Squirrel on windows starts the app with various flags as hooks to tell us when we've been installed/uninstalled etc.
|
||||||
import "./squirrelhooks";
|
import "./squirrelhooks";
|
||||||
import { app, BrowserWindow, Menu, autoUpdater, protocol, dialog, Input, Event } from "electron";
|
import { app, BrowserWindow, Menu, autoUpdater, protocol, dialog, Input, Event, session } from "electron";
|
||||||
import * as Sentry from "@sentry/electron/main";
|
import * as Sentry from "@sentry/electron/main";
|
||||||
import AutoLaunch from "auto-launch";
|
import AutoLaunch from "auto-launch";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@ -39,6 +39,7 @@ import webContentsHandler from "./webcontents-handler";
|
|||||||
import * as updater from "./updater";
|
import * as updater from "./updater";
|
||||||
import { getProfileFromDeeplink, protocolInit } from "./protocol";
|
import { getProfileFromDeeplink, protocolInit } from "./protocol";
|
||||||
import { _t, AppLocalization } from "./language-helper";
|
import { _t, AppLocalization } from "./language-helper";
|
||||||
|
import { setDisplayMediaCallback } from "./displayMediaCallback";
|
||||||
|
|
||||||
const argv = minimist(process.argv, {
|
const argv = minimist(process.argv, {
|
||||||
alias: { help: "h" },
|
alias: { help: "h" },
|
||||||
@ -532,6 +533,11 @@ app.on("ready", async () => {
|
|||||||
store: global.store,
|
store: global.store,
|
||||||
components: [(): void => tray.initApplicationMenu(), (): void => Menu.setApplicationMenu(buildMenuTemplate())],
|
components: [(): void => tray.initApplicationMenu(), (): void => Menu.setApplicationMenu(buildMenuTemplate())],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
session.defaultSession.setDisplayMediaRequestHandler((_, callback) => {
|
||||||
|
global.mainWindow?.webContents.send("openDesktopCapturerSourcePicker");
|
||||||
|
setDisplayMediaCallback(callback);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
|
@ -22,6 +22,7 @@ import { recordSSOSession } from "./protocol";
|
|||||||
import { randomArray } from "./utils";
|
import { randomArray } from "./utils";
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
import { keytar } from "./keytar";
|
import { keytar } from "./keytar";
|
||||||
|
import { getDisplayMediaCallback, setDisplayMediaCallback } from "./displayMediaCallback";
|
||||||
|
|
||||||
ipcMain.on("setBadgeCount", function (_ev: IpcMainEvent, count: number): void {
|
ipcMain.on("setBadgeCount", function (_ev: IpcMainEvent, count: number): void {
|
||||||
if (process.platform !== "win32") {
|
if (process.platform !== "win32") {
|
||||||
@ -186,6 +187,11 @@ ipcMain.on("ipcCall", async function (_ev: IpcMainEvent, payload) {
|
|||||||
thumbnailURL: source.thumbnail.toDataURL(),
|
thumbnailURL: source.thumbnail.toDataURL(),
|
||||||
}));
|
}));
|
||||||
break;
|
break;
|
||||||
|
case "callDisplayMediaCallback":
|
||||||
|
await getDisplayMediaCallback()?.({ video: args[0] });
|
||||||
|
setDisplayMediaCallback(null);
|
||||||
|
ret = null;
|
||||||
|
break;
|
||||||
|
|
||||||
case "clearStorage":
|
case "clearStorage":
|
||||||
global.store.clear();
|
global.store.clear();
|
||||||
|
@ -34,6 +34,7 @@ const CHANNELS = [
|
|||||||
"update-downloaded",
|
"update-downloaded",
|
||||||
"userDownloadCompleted",
|
"userDownloadCompleted",
|
||||||
"userDownloadAction",
|
"userDownloadAction",
|
||||||
|
"openDesktopCapturerSourcePicker",
|
||||||
];
|
];
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("electron", {
|
contextBridge.exposeInMainWorld("electron", {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user