From d2129628eff2d08dda13006d62b34fbd046cff8f Mon Sep 17 00:00:00 2001 From: Pavlo Buidenkov Date: Sun, 29 May 2022 18:35:03 +0200 Subject: [PATCH] remove sharingSession service from ConnectedDevicesListDrawer --- app/components/ConnectedDevicesListDrawer.tsx | 56 +++-- app/components/TopPanel.tsx | 35 +-- .../__snapshots__/TopPanel.spec.tsx.snap | 201 ------------------ app/main/IpcEvents.enum.ts | 2 + app/main/ipcMainHandlers.ts | 13 ++ 5 files changed, 76 insertions(+), 231 deletions(-) delete mode 100644 app/components/__snapshots__/TopPanel.spec.tsx.snap diff --git a/app/components/ConnectedDevicesListDrawer.tsx b/app/components/ConnectedDevicesListDrawer.tsx index eddb193..b6f4abd 100644 --- a/app/components/ConnectedDevicesListDrawer.tsx +++ b/app/components/ConnectedDevicesListDrawer.tsx @@ -16,20 +16,20 @@ import { Row, Col } from 'react-flexbox-grid'; import { createStyles, makeStyles } from '@material-ui/core/styles'; import CloseOverlayButton from './CloseOverlayButton'; import ConnectedDevicesService from '../features/ConnectedDevicesService'; -import SharingSessionService from '../features/SharingSessionService'; import DeviceInfoCallout from './DeviceInfoCallout'; import SharingSourcePreviewCard from './SharingSourcePreviewCard'; import isWithReactRevealAnimations from '../utils/isWithReactRevealAnimations'; import isProduction from '../utils/isProduction'; import { IpcEvents } from '../main/IpcEvents.enum'; -const sharingSessionService = remote.getGlobal( - 'sharingSessionService' -) as SharingSessionService; const connectedDevicesService = remote.getGlobal( 'connectedDevicesService' ) as ConnectedDevicesService; +type DeviceWithDesktopCapturerSourceId = Device & { + desktopCapturerSourceId: string; +}; + const Fade = require('react-reveal/Fade'); interface ConnectedDevicesListDrawerProps { @@ -62,21 +62,46 @@ export default function ConnectedDevicesListDrawer( const classes = useStyles(); const [isAlertDisconectAllOpen, setIsAlertDisconectAllOpen] = useState(false); - + const [connectedDevices, setConnectedDevices] = useState< + DeviceWithDesktopCapturerSourceId[] + >([]); const [devicesDisplayed, setDevicesDisplayed] = useState(new Map()); + useEffect(() => { + ipcRenderer + .invoke(IpcEvents.GetConnectedDevices) + // eslint-disable-next-line promise/always-return + .then((devices: Device[]) => { + console.log('devices', devices); + // setConnectedDevices(devices); + const devicesWithSourceIds: DeviceWithDesktopCapturerSourceId[] = []; + devices.forEach(async (device) => { + const sharingSourceId = await ipcRenderer.invoke( + IpcEvents.GetDesktopCapturerSourceIdBySharingSessionId, + device.sharingSessionID + ); + devicesWithSourceIds.push({ + ...device, + desktopCapturerSourceId: sharingSourceId, + }); + console.log('device pushed'); + }); + setConnectedDevices(devicesWithSourceIds); + }) + // eslint-disable-next-line no-console + .catch((e) => console.error(e)); + }, []); + useEffect(() => { const map = new Map(); - connectedDevicesService.getDevices().forEach((el) => { + connectedDevices.forEach((el) => { map.set(el.id, true); }); setDevicesDisplayed(map); - }, [setDevicesDisplayed]); + }, [setDevicesDisplayed, connectedDevices]); const handleDisconnectOneDevice = useCallback(async (id: string) => { - const device = connectedDevicesService.devices.find( - (d: Device) => d.id === id - ); + const device = connectedDevices.find((d: Device) => d.id === id); if (!device) return; ipcRenderer.invoke( IpcEvents.DisconnectPeerAndDestroySharingSessionBySessionID, @@ -86,7 +111,7 @@ export default function ConnectedDevicesListDrawer( }, []); const handleDisconnectAll = useCallback(() => { - connectedDevicesService.devices.forEach((device: Device) => { + connectedDevices.forEach((device: Device) => { ipcRenderer.invoke( IpcEvents.DisconnectPeerAndDestroySharingSessionBySessionID, device.sharingSessionID @@ -149,7 +174,6 @@ export default function ConnectedDevicesListDrawer( isOpen={props.isOpen} onClose={props.handleToggle} transitionDuration={isWithReactRevealAnimations() ? 700 : 0} - // transitionDuration={0} > @@ -184,7 +208,7 @@ export default function ConnectedDevicesListDrawer( duration={isWithReactRevealAnimations() ? 700 : 0} >
- {connectedDevicesService.getDevices().map((device) => { + {connectedDevices.map((device) => { return (
diff --git a/app/components/TopPanel.tsx b/app/components/TopPanel.tsx index a5ab80c..13123d0 100644 --- a/app/components/TopPanel.tsx +++ b/app/components/TopPanel.tsx @@ -61,7 +61,10 @@ export default function TopPanel(props: any) { }, [isDarkTheme]); const [isSettingsOpen, setIsSettingsOpen] = React.useState(false); - const [isDrawersOpen, setIsDrawerOpen] = React.useState(false); + const [ + isConnectedDevicesDrawerOpen, + setIsConnectedDevicesDrawerOpen, + ] = React.useState(false); const handleSettingsOpen = useCallback(() => { setIsSettingsOpen(true); @@ -72,8 +75,8 @@ export default function TopPanel(props: any) { }, []); const handleToggleConnectedDevicesListDrawer = useCallback(() => { - setIsDrawerOpen(!isDrawersOpen); - }, [isDrawersOpen]); + setIsConnectedDevicesDrawerOpen(!isConnectedDevicesDrawerOpen); + }, [isConnectedDevicesDrawerOpen]); const donateTooltipContent = t( 'If you like Deskreen consider contributing financially Deskreen is open-source Your donations keep us motivated to make Deskreen even better' @@ -232,15 +235,23 @@ export default function TopPanel(props: any) { {renderSettingsButton()}
- - + {isConnectedDevicesDrawerOpen ? ( + + ) : ( + <> + )} + {isConnectedDevicesDrawerOpen ? ( + + ) : ( + <> + )} ); } diff --git a/app/components/__snapshots__/TopPanel.spec.tsx.snap b/app/components/__snapshots__/TopPanel.spec.tsx.snap deleted file mode 100644 index 2478cb9..0000000 --- a/app/components/__snapshots__/TopPanel.spec.tsx.snap +++ /dev/null @@ -1,201 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` should match exact snapshot 1`] = ` - -
- - - - - - - heart - - -
- -
- -
-
-
- - -
- - -

- Deskreen -

-
-
-
- -
-
-
- - - - - -
-
- - - - - -
-
- - - - - -
-
-
- - -
-`; diff --git a/app/main/IpcEvents.enum.ts b/app/main/IpcEvents.enum.ts index 2739fcf..e2f1493 100644 --- a/app/main/IpcEvents.enum.ts +++ b/app/main/IpcEvents.enum.ts @@ -8,4 +8,6 @@ export enum IpcEvents { SetDeviceConnectedStatus = 'set-device-connected-status', GetSourceDisplayIDByDesktopCapturerSourceID = 'get-source-display-id-by-desktop-capturer-source-id', DisconnectPeerAndDestroySharingSessionBySessionID = 'disconnect-peer-and-destroy-sharing-session-by-session-id', + GetDesktopCapturerSourceIdBySharingSessionId = 'get-desktop-capturer-source-id-by-sharing-session-id', + GetConnectedDevices = 'get-connected-devices-list', } diff --git a/app/main/ipcMainHandlers.ts b/app/main/ipcMainHandlers.ts index 96e52f6..b9cc548 100644 --- a/app/main/ipcMainHandlers.ts +++ b/app/main/ipcMainHandlers.ts @@ -158,4 +158,17 @@ export default function initIpcMainHandlers( ); } ); + + ipcMain.handle( + IpcEvents.GetDesktopCapturerSourceIdBySharingSessionId, + (_, sessionId) => { + return getDeskreenGlobal().sharingSessionService.sharingSessions.get( + sessionId + )?.desktopCapturerSourceID; + } + ); + + ipcMain.handle(IpcEvents.GetConnectedDevices, () => { + return getDeskreenGlobal().connectedDevicesService.getDevices(); + }); }