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

remove .remote from Interrmediate step

This commit is contained in:
Pavlo Buidenkov 2022-05-30 21:31:49 +02:00
parent e3db220e32
commit 42cb2a28e2
6 changed files with 51 additions and 85 deletions

View File

@ -1,4 +1,4 @@
import { remote } from 'electron'; import { ipcRenderer } from 'electron';
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { H3, Card, Dialog, Button } from '@blueprintjs/core'; import { H3, Card, Dialog, Button } from '@blueprintjs/core';
import { Row, Col } from 'react-flexbox-grid'; import { Row, Col } from 'react-flexbox-grid';
@ -6,12 +6,8 @@ import { createStyles, makeStyles } from '@material-ui/core/styles';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import CloseOverlayButton from '../../CloseOverlayButton'; import CloseOverlayButton from '../../CloseOverlayButton';
import PreviewGridList from './PreviewGridList'; import PreviewGridList from './PreviewGridList';
import DesktopCapturerSources from '../../../features/DesktopCapturerSourcesService';
import isWithReactRevealAnimations from '../../../utils/isWithReactRevealAnimations'; import isWithReactRevealAnimations from '../../../utils/isWithReactRevealAnimations';
import { IpcEvents } from '../../../main/IpcEvents.enum';
const desktopCapturerSourcesService = remote.getGlobal(
'desktopCapturerSourcesService'
) as DesktopCapturerSources;
const Zoom = require('react-reveal/Zoom'); const Zoom = require('react-reveal/Zoom');
const Fade = require('react-reveal/Fade'); const Fade = require('react-reveal/Fade');
@ -62,37 +58,22 @@ export default function ChooseAppOrScreenOverlay(
} = props; } = props;
const classes = useStyles(); const classes = useStyles();
const [ const [screenViewSharingIds, setScreenViewSharingIds] = useState<string[]>(
screenViewSharingObjectsMap, []
setScreenViewSharingObjectsMap, );
] = useState<Map<string, ViewSharingObject>>(new Map());
const [ const [appWindowsViewSharingIds, setAppWindowsViewSharingIds] = useState<
appsWindowsViewSharingObjectsMap, string[]
setAppsWindowsViewSharingObjectsMap, >([]);
] = useState<Map<string, ViewSharingObject>>(new Map());
const handleRefreshSources = useCallback(() => { const handleRefreshSources = useCallback(async () => {
const ids = await ipcRenderer.invoke(IpcEvents.GetDesktopSharingSourceIds, {
isEntireScreenToShareChosen,
});
if (isEntireScreenToShareChosen) { if (isEntireScreenToShareChosen) {
const sourcesToShare = desktopCapturerSourcesService.getScreenSources(); setScreenViewSharingIds(ids);
const screenViewMap = new Map<string, ViewSharingObject>();
sourcesToShare.forEach((source) => {
screenViewMap.set(source.id, {
thumbnailUrl: source.thumbnail.toDataURL(),
name: source.name,
});
});
setScreenViewSharingObjectsMap(screenViewMap);
} else { } else {
const sourcesToShare = desktopCapturerSourcesService.getAppWindowSources(); setAppWindowsViewSharingIds(ids);
const appViewMap = new Map<string, ViewSharingObject>();
sourcesToShare.forEach((source) => {
appViewMap.set(source.id, {
thumbnailUrl: source.thumbnail.toDataURL(),
name: source.name,
});
});
setAppsWindowsViewSharingObjectsMap(appViewMap);
} }
}, [isEntireScreenToShareChosen]); }, [isEntireScreenToShareChosen]);
@ -208,10 +189,10 @@ export default function ChooseAppOrScreenOverlay(
<Row> <Row>
<div className={classes.sharePreviewsContainer}> <div className={classes.sharePreviewsContainer}>
<PreviewGridList <PreviewGridList
viewSharingObjectsMap={ viewSharingIds={
isEntireScreenToShareChosen isEntireScreenToShareChosen
? screenViewSharingObjectsMap ? screenViewSharingIds
: appsWindowsViewSharingObjectsMap : appWindowsViewSharingIds
} }
isEntireScreen={isEntireScreenToShareChosen} isEntireScreen={isEntireScreenToShareChosen}
handleNextEntireScreen={() => { handleNextEntireScreen={() => {

View File

@ -1,5 +1,5 @@
import React from 'react';
import { remote } from 'electron'; import { remote } from 'electron';
import React, { useEffect, useState } from 'react';
import { Row, Col } from 'react-flexbox-grid'; import { Row, Col } from 'react-flexbox-grid';
import SharingSessionService from '../../../features/SharingSessionService'; import SharingSessionService from '../../../features/SharingSessionService';
import SharingSourcePreviewCard from '../../SharingSourcePreviewCard'; import SharingSourcePreviewCard from '../../SharingSourcePreviewCard';
@ -8,10 +8,8 @@ const sharingSessionService = remote.getGlobal(
'sharingSessionService' 'sharingSessionService'
) as SharingSessionService; ) as SharingSessionService;
const EMPTY_VIEW_SHARING_OBJECTS_MAP = new Map<string, ViewSharingObject>();
class PreviewGridListProps { class PreviewGridListProps {
viewSharingObjectsMap = EMPTY_VIEW_SHARING_OBJECTS_MAP; viewSharingIds: string[] = [];
isEntireScreen = true; isEntireScreen = true;
@ -22,26 +20,11 @@ class PreviewGridListProps {
export default function PreviewGridList(props: PreviewGridListProps) { export default function PreviewGridList(props: PreviewGridListProps) {
const { const {
viewSharingObjectsMap, viewSharingIds,
isEntireScreen, isEntireScreen,
handleNextEntireScreen, handleNextEntireScreen,
handleNextApplicationWindow, handleNextApplicationWindow,
} = props; } = props;
const [showPreviewNamesMap, setShowPreviewNamesMap] = useState(
new Map<string, boolean>()
);
useEffect(() => {
const map = new Map<string, boolean>();
if (viewSharingObjectsMap === EMPTY_VIEW_SHARING_OBJECTS_MAP) {
setShowPreviewNamesMap(map);
return;
}
[...viewSharingObjectsMap.keys()].forEach((id: string) => {
map.set(id, false);
});
setShowPreviewNamesMap(map);
}, [viewSharingObjectsMap]);
return ( return (
<Row <Row
@ -51,7 +34,7 @@ export default function PreviewGridList(props: PreviewGridListProps) {
height: '90%', height: '90%',
}} }}
> >
{[...showPreviewNamesMap.keys()].map((id) => { {viewSharingIds.map((id) => {
return ( return (
<Col xs={12} md={6} key={id}> <Col xs={12} md={6} key={id}>
<SharingSourcePreviewCard <SharingSourcePreviewCard

View File

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'; import React from 'react';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import { Button, Text } from '@blueprintjs/core'; import { Button, Text } from '@blueprintjs/core';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -18,6 +18,7 @@ interface IntermediateStepProps {
handleNextApplicationWindow: () => void; handleNextApplicationWindow: () => void;
resetPendingConnectionDevice: () => void; resetPendingConnectionDevice: () => void;
resetUserAllowedConnection: () => void; resetUserAllowedConnection: () => void;
connectedDevice: Device | null;
} }
function getStepContent( function getStepContent(
@ -25,7 +26,7 @@ function getStepContent(
stepIndex: number, stepIndex: number,
handleNextEntireScreen: () => void, handleNextEntireScreen: () => void,
handleNextApplicationWindow: () => void, handleNextApplicationWindow: () => void,
device: Device connectedDevice: Device | null
) { ) {
switch (stepIndex) { switch (stepIndex) {
case 0: case 0:
@ -47,7 +48,7 @@ function getStepContent(
</> </>
); );
case 2: case 2:
return <ConfirmStep device={device} />; return <ConfirmStep device={connectedDevice} />;
default: default:
return 'Unknown stepIndex'; return 'Unknown stepIndex';
} }
@ -59,7 +60,6 @@ function isConfirmStep(activeStep: number, steps: string[]) {
export default function IntermediateStep(props: IntermediateStepProps) { export default function IntermediateStep(props: IntermediateStepProps) {
const { t } = useTranslation(); const { t } = useTranslation();
const [pendingConnectionDevice, setPendingConnectionDevice] = useState();
const { const {
activeStep, activeStep,
@ -70,19 +70,9 @@ export default function IntermediateStep(props: IntermediateStepProps) {
handleNextApplicationWindow, handleNextApplicationWindow,
resetPendingConnectionDevice, resetPendingConnectionDevice,
resetUserAllowedConnection, resetUserAllowedConnection,
connectedDevice,
} = props; } = props;
useEffect(() => {
// eslint-disable-next-line promise/always-return
ipcRenderer
.invoke(IpcEvents.GetPendingConnectionDevice)
// eslint-disable-next-line promise/always-return
.then((device) => {
setPendingConnectionDevice(device);
})
.catch((e) => console.error(e));
}, []);
return ( return (
<Col <Col
xs={12} xs={12}
@ -95,15 +85,13 @@ export default function IntermediateStep(props: IntermediateStepProps) {
width: '100%', width: '100%',
}} }}
> >
{pendingConnectionDevice && {getStepContent(
getStepContent( t,
t, activeStep,
activeStep, handleNextEntireScreen,
handleNextEntireScreen, handleNextApplicationWindow,
handleNextApplicationWindow, connectedDevice
pendingConnectionDevice )}
)}
{ {
// eslint-disable-next-line no-nested-ternary // eslint-disable-next-line no-nested-ternary
process.env.NODE_ENV === 'production' && process.env.NODE_ENV === 'production' &&

View File

@ -239,11 +239,9 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
handleBack={handleBack} handleBack={handleBack}
handleNextEntireScreen={handleNextEntireScreen} handleNextEntireScreen={handleNextEntireScreen}
handleNextApplicationWindow={handleNextApplicationWindow} handleNextApplicationWindow={handleNextApplicationWindow}
resetPendingConnectionDevice={ resetPendingConnectionDevice={() => setPendingConnectionDevice(null)}
() => setPendingConnectionDevice(null)
// eslint-disable-next-line react/jsx-curly-newline
}
resetUserAllowedConnection={() => setIsUserAllowedConnection(false)} resetUserAllowedConnection={() => setIsUserAllowedConnection(false)}
connectedDevice={pendingConnectionDevice}
/> />
</div> </div>
); );
@ -255,6 +253,7 @@ const DeskreenStepper = React.forwardRef((_props, ref) => {
handleBack, handleBack,
handleNextEntireScreen, handleNextEntireScreen,
handleNextApplicationWindow, handleNextApplicationWindow,
pendingConnectionDevice,
]); ]);
const renderStepLabelContent = useCallback( const renderStepLabelContent = useCallback(

View File

@ -18,4 +18,5 @@ export enum IpcEvents {
StartSharingOnWaitingForConnectionSharingSession = 'start-sharing-on-waiting-for-connection-sharing-session', StartSharingOnWaitingForConnectionSharingSession = 'start-sharing-on-waiting-for-connection-sharing-session',
GetPendingConnectionDevice = 'get-pending-connection-device', GetPendingConnectionDevice = 'get-pending-connection-device',
GetWaitingForConnectionSharingSessionRoomId = 'get-waiting-for-connection-sharing-session-room-id', GetWaitingForConnectionSharingSessionRoomId = 'get-waiting-for-connection-sharing-session-room-id',
GetDesktopSharingSourceIds = 'get-desktop-sharing-source-ids',
} }

View File

@ -246,4 +246,18 @@ export default function initIpcMainHandlers(
return getDeskreenGlobal().sharingSessionService return getDeskreenGlobal().sharingSessionService
.waitingForConnectionSharingSession?.roomID; .waitingForConnectionSharingSession?.roomID;
}); });
ipcMain.handle(
IpcEvents.GetDesktopSharingSourceIds,
(_, { isEntireScreenToShareChosen }) => {
if (isEntireScreenToShareChosen === true) {
return getDeskreenGlobal()
.desktopCapturerSourcesService.getScreenSources()
.map((source) => source.id);
}
return getDeskreenGlobal()
.desktopCapturerSourcesService.getAppWindowSources()
.map((source) => source.id);
}
);
} }