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 { remote } from 'electron';
import { ipcRenderer } from 'electron';
import { Text, Card, Spinner } from '@blueprintjs/core';
import { Row, Col } from 'react-flexbox-grid';
import DesktopCapturerSources from '../../features/DesktopCapturerSourcesService';
const desktopCapturerSourcesService = remote.getGlobal(
'desktopCapturerSourcesService'
) as DesktopCapturerSources;
import { IpcEvents } from '../../main/IpcEvents.enum';
class SharingSourcePreviewCardProps {
sharingSourceID: string | undefined = '';
@ -26,19 +22,23 @@ export default function SharingSourcePreviewCard(
const [isHovered, setIsHovered] = useState(false);
useEffect(() => {
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(
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(
sources.get(sharingSourceID)?.source.appIcon.toDataURL() || ''
((sources[sharingSourceID]?.source.appIcon as unknown) as string) ||
''
);
}
setSourceName(
sources.get(sharingSourceID)?.source.name ||
sources[sharingSourceID]?.source.name ||
'Failed to get source name...'
);
}

View File

@ -13,4 +13,5 @@ export enum IpcEvents {
DisconnectDeviceById = 'disconnect-device-by-id',
DisconnectAllDevices = 'disconnect-all-devices',
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 settings from 'electron-settings';
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;
});
}