1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-19 08:50:17 -07:00

add ipcRenderer.invoke to preview source displays

This commit is contained in:
Pavlo Buidenkov 2022-05-30 18:12:53 +02:00
parent 747d275add
commit a33fc14686
3 changed files with 32 additions and 12 deletions

View File

@ -1,12 +1,8 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { remote } from 'electron'; import { ipcRenderer } from 'electron';
import { Text, Card, Spinner } from '@blueprintjs/core'; import { Text, Card, Spinner } from '@blueprintjs/core';
import { Row, Col } from 'react-flexbox-grid'; import { Row, Col } from 'react-flexbox-grid';
import DesktopCapturerSources from '../../features/DesktopCapturerSourcesService'; import { IpcEvents } from '../../main/IpcEvents.enum';
const desktopCapturerSourcesService = remote.getGlobal(
'desktopCapturerSourcesService'
) as DesktopCapturerSources;
class SharingSourcePreviewCardProps { class SharingSourcePreviewCardProps {
sharingSourceID: string | undefined = ''; sharingSourceID: string | undefined = '';
@ -26,19 +22,23 @@ export default function SharingSourcePreviewCard(
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false);
useEffect(() => { useEffect(() => {
setTimeout(async () => { setTimeout(async () => {
const sources = desktopCapturerSourcesService.getSourcesMap(); const sources = await ipcRenderer.invoke(
IpcEvents.GetDesktopCapturerServiceSourcesMap
);
if (sources && sharingSourceID && sources.get(sharingSourceID)) { if (sources && sharingSourceID && sources[sharingSourceID]) {
setSourceImage( setSourceImage(
sources.get(sharingSourceID)?.source.thumbnail.toDataURL() || '' ((sources[sharingSourceID]?.source.thumbnail as unknown) as string) ||
''
); );
if (sources.get(sharingSourceID)?.source.appIcon != null) { if (sources[sharingSourceID]?.source.appIcon != null) {
setAppIconSourceImage( setAppIconSourceImage(
sources.get(sharingSourceID)?.source.appIcon.toDataURL() || '' ((sources[sharingSourceID]?.source.appIcon as unknown) as string) ||
''
); );
} }
setSourceName( setSourceName(
sources.get(sharingSourceID)?.source.name || sources[sharingSourceID]?.source.name ||
'Failed to get source name...' 'Failed to get source name...'
); );
} }

View File

@ -13,4 +13,5 @@ export enum IpcEvents {
DisconnectDeviceById = 'disconnect-device-by-id', DisconnectDeviceById = 'disconnect-device-by-id',
DisconnectAllDevices = 'disconnect-all-devices', DisconnectAllDevices = 'disconnect-all-devices',
AppLanguageChanged = 'app-language-changed', AppLanguageChanged = 'app-language-changed',
GetDesktopCapturerServiceSourcesMap = 'get-desktop-capturer-service-sources-map',
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable no-restricted-syntax */
import { Display, ipcMain, BrowserWindow, screen } from 'electron'; import { Display, ipcMain, BrowserWindow, screen } from 'electron';
import settings from 'electron-settings'; import settings from 'electron-settings';
import i18n from '../configs/i18next.config'; import i18n from '../configs/i18next.config';
@ -187,4 +188,22 @@ export default function initIpcMainHandlers(
} }
); );
}); });
ipcMain.handle(IpcEvents.GetDesktopCapturerServiceSourcesMap, () => {
const map = getDeskreenGlobal().desktopCapturerSourcesService.getSourcesMap();
const res = {};
// eslint-disable-next-line guard-for-in
for (const key of map.keys()) {
const source = map.get(key);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
res[key] = {
source: {
thumbnail: source?.source.thumbnail?.toDataURL(),
appIcon: source?.source.appIcon?.toDataURL(),
},
};
}
return res;
});
} }