mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
Tweak screensharing
This commit is contained in:
parent
8e16371521
commit
334d28542f
2 changed files with 32 additions and 35 deletions
|
@ -2,7 +2,8 @@ import {BrowserWindow, desktopCapturer, ipcMain, session, shell} from "electron"
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {iconPath} from "../main";
|
import {iconPath} from "../main";
|
||||||
var capturerWindow: BrowserWindow;
|
var capturerWindow: BrowserWindow;
|
||||||
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
function registerCustomHandler() {
|
||||||
|
session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) => {
|
||||||
const sources = await desktopCapturer.getSources({
|
const sources = await desktopCapturer.getSources({
|
||||||
types: ["screen", "window"]
|
types: ["screen", "window"]
|
||||||
});
|
});
|
||||||
|
@ -21,17 +22,15 @@ session.defaultSession.setDisplayMediaRequestHandler(async (request, callback) =
|
||||||
preload: path.join(__dirname, "preload.js")
|
preload: path.join(__dirname, "preload.js")
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ipcMain.on("selectScreenshareSource", (event, id, name) => {
|
ipcMain.once("selectScreenshareSource", (event, id, name) => {
|
||||||
console.log(sources[id]);
|
console.log(sources[id]);
|
||||||
console.log(id);
|
console.log(id);
|
||||||
callback({video: {id, name}});
|
|
||||||
|
|
||||||
capturerWindow.close();
|
capturerWindow.close();
|
||||||
});
|
var result = {id, name};
|
||||||
capturerWindow.webContents.setWindowOpenHandler(({url}) => {
|
callback({video: result});
|
||||||
shell.openExternal(url);
|
|
||||||
return {action: "deny"};
|
|
||||||
});
|
});
|
||||||
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
|
capturerWindow.loadURL(`file://${__dirname}/picker.html`);
|
||||||
capturerWindow.webContents.send("getSources", sources);
|
capturerWindow.webContents.send("getSources", sources);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
registerCustomHandler();
|
||||||
|
|
|
@ -5,7 +5,7 @@ interface IPCSources {
|
||||||
thumbnail: HTMLCanvasElement;
|
thumbnail: HTMLCanvasElement;
|
||||||
}
|
}
|
||||||
async function addDisplays() {
|
async function addDisplays() {
|
||||||
ipcRenderer.on("getSources", (event, arg) => {
|
ipcRenderer.once("getSources", (event, arg) => {
|
||||||
var sources: IPCSources[] = arg;
|
var sources: IPCSources[] = arg;
|
||||||
console.log(sources);
|
console.log(sources);
|
||||||
const selectionElem = document.createElement("div");
|
const selectionElem = document.createElement("div");
|
||||||
|
@ -45,8 +45,6 @@ async function addDisplays() {
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
} finally {
|
|
||||||
ipcRenderer.sendSync("closeScreenshareWindow");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue