mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-16 15:30:20 -07:00
remove remote dependency from IntermediateStep
This commit is contained in:
parent
4ab3668532
commit
b47c31c33a
@ -1,20 +1,14 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { ipcRenderer, remote } 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';
|
||||||
import { TFunction } from 'i18next';
|
import { TFunction } from 'i18next';
|
||||||
import { Col, Row } from 'react-flexbox-grid';
|
import { Col, Row } from 'react-flexbox-grid';
|
||||||
import DEVICES from '../../constants/test-devices.json';
|
|
||||||
import ScanQRStep from './ScanQRStep';
|
import ScanQRStep from './ScanQRStep';
|
||||||
import ChooseAppOrScreeenStep from './ChooseAppOrScreeenStep';
|
import ChooseAppOrScreeenStep from './ChooseAppOrScreeenStep';
|
||||||
import ConfirmStep from './ConfirmStep';
|
import ConfirmStep from './ConfirmStep';
|
||||||
import ConnectedDevicesService from '../../features/ConnectedDevicesService';
|
|
||||||
import { IpcEvents } from '../../main/IpcEvents.enum';
|
import { IpcEvents } from '../../main/IpcEvents.enum';
|
||||||
|
|
||||||
const connectedDevicesService = remote.getGlobal(
|
|
||||||
'connectedDevicesService'
|
|
||||||
) as ConnectedDevicesService;
|
|
||||||
|
|
||||||
interface IntermediateStepProps {
|
interface IntermediateStepProps {
|
||||||
activeStep: number;
|
activeStep: number;
|
||||||
steps: string[];
|
steps: string[];
|
||||||
@ -31,7 +25,7 @@ function getStepContent(
|
|||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
handleNextEntireScreen: () => void,
|
handleNextEntireScreen: () => void,
|
||||||
handleNextApplicationWindow: () => void,
|
handleNextApplicationWindow: () => void,
|
||||||
pendingConnectionDevice: Device | null
|
device: Device
|
||||||
) {
|
) {
|
||||||
switch (stepIndex) {
|
switch (stepIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -53,7 +47,7 @@ function getStepContent(
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
case 2:
|
case 2:
|
||||||
return <ConfirmStep device={pendingConnectionDevice} />;
|
return <ConfirmStep device={device} />;
|
||||||
default:
|
default:
|
||||||
return 'Unknown stepIndex';
|
return 'Unknown stepIndex';
|
||||||
}
|
}
|
||||||
@ -65,6 +59,7 @@ 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,
|
||||||
@ -77,9 +72,16 @@ export default function IntermediateStep(props: IntermediateStepProps) {
|
|||||||
resetUserAllowedConnection,
|
resetUserAllowedConnection,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const connectDevice = (device: Device) => {
|
useEffect(() => {
|
||||||
connectedDevicesService.setPendingConnectionDevice(device);
|
// 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
|
||||||
@ -93,13 +95,14 @@ export default function IntermediateStep(props: IntermediateStepProps) {
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{getStepContent(
|
{pendingConnectionDevice &&
|
||||||
t,
|
getStepContent(
|
||||||
activeStep,
|
t,
|
||||||
handleNextEntireScreen,
|
activeStep,
|
||||||
handleNextApplicationWindow,
|
handleNextEntireScreen,
|
||||||
connectedDevicesService.pendingConnectionDevice
|
handleNextApplicationWindow,
|
||||||
)}
|
pendingConnectionDevice
|
||||||
|
)}
|
||||||
|
|
||||||
{
|
{
|
||||||
// eslint-disable-next-line no-nested-ternary
|
// eslint-disable-next-line no-nested-ternary
|
||||||
@ -111,11 +114,7 @@ export default function IntermediateStep(props: IntermediateStepProps) {
|
|||||||
// eslint-disable-next-line react/jsx-indent
|
// eslint-disable-next-line react/jsx-indent
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
connectDevice(
|
// connectedDevicesService.setPendingConnectionDevice(DEVICES[Math.floor(Math.random() * DEVICES.length)]);
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-ignore
|
|
||||||
DEVICES[Math.floor(Math.random() * DEVICES.length)]
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Connect Test Device
|
Connect Test Device
|
||||||
|
@ -16,7 +16,6 @@ export default function ToggleThemeBtnGroup() {
|
|||||||
document.body.classList.toggle(Classes.DARK);
|
document.body.classList.toggle(Classes.DARK);
|
||||||
setIsDarkThemeHook(true);
|
setIsDarkThemeHook(true);
|
||||||
}
|
}
|
||||||
// TODO: call sharing sessions service here to notify all connected clients about theme change
|
|
||||||
sharingSessionService.sharingSessions.forEach((sharingSession) => {
|
sharingSessionService.sharingSessions.forEach((sharingSession) => {
|
||||||
sharingSession?.appThemeChanged();
|
sharingSession?.appThemeChanged();
|
||||||
});
|
});
|
||||||
@ -27,7 +26,6 @@ export default function ToggleThemeBtnGroup() {
|
|||||||
document.body.classList.toggle(Classes.DARK);
|
document.body.classList.toggle(Classes.DARK);
|
||||||
setIsDarkThemeHook(false);
|
setIsDarkThemeHook(false);
|
||||||
}
|
}
|
||||||
// TODO: call sharing sessions service here to notify all connected clients about theme change
|
|
||||||
sharingSessionService.sharingSessions.forEach((sharingSession) => {
|
sharingSessionService.sharingSessions.forEach((sharingSession) => {
|
||||||
sharingSession?.appThemeChanged();
|
sharingSession?.appThemeChanged();
|
||||||
});
|
});
|
||||||
|
@ -16,4 +16,5 @@ export enum IpcEvents {
|
|||||||
GetDesktopCapturerServiceSourcesMap = 'get-desktop-capturer-service-sources-map',
|
GetDesktopCapturerServiceSourcesMap = 'get-desktop-capturer-service-sources-map',
|
||||||
GetWaitingForConnectionSharingSessionSourceId = 'get-waiting-for-connection-sharing-session-source-id',
|
GetWaitingForConnectionSharingSessionSourceId = 'get-waiting-for-connection-sharing-session-source-id',
|
||||||
StartSharingOnWaitingForConnectionSharingSession = 'start-sharing-on-waiting-for-connection-sharing-session',
|
StartSharingOnWaitingForConnectionSharingSession = 'start-sharing-on-waiting-for-connection-sharing-session',
|
||||||
|
GetPendingConnectionDevice = 'get-pending-connection-device',
|
||||||
}
|
}
|
||||||
|
@ -231,4 +231,8 @@ export default function initIpcMainHandlers(
|
|||||||
getDeskreenGlobal().connectedDevicesService.resetPendingConnectionDevice();
|
getDeskreenGlobal().connectedDevicesService.resetPendingConnectionDevice();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ipcMain.handle(IpcEvents.GetPendingConnectionDevice, () => {
|
||||||
|
return getDeskreenGlobal().connectedDevicesService.pendingConnectionDevice;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user