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:
parent
747d275add
commit
a33fc14686
@ -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();
|
||||
|
||||
if (sources && sharingSourceID && sources.get(sharingSourceID)) {
|
||||
setSourceImage(
|
||||
sources.get(sharingSourceID)?.source.thumbnail.toDataURL() || ''
|
||||
const sources = await ipcRenderer.invoke(
|
||||
IpcEvents.GetDesktopCapturerServiceSourcesMap
|
||||
);
|
||||
if (sources.get(sharingSourceID)?.source.appIcon != null) {
|
||||
|
||||
if (sources && sharingSourceID && sources[sharingSourceID]) {
|
||||
setSourceImage(
|
||||
((sources[sharingSourceID]?.source.thumbnail as unknown) as string) ||
|
||||
''
|
||||
);
|
||||
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...'
|
||||
);
|
||||
}
|
||||
|
@ -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',
|
||||
}
|
||||
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user