/* eslint-disable @typescript-eslint/ban-ts-comment */ import React, { useState, useCallback, useContext, useEffect } from 'react'; import { ipcRenderer, shell } from 'electron'; import { makeStyles, createStyles } from '@material-ui/core/styles'; import Stepper from '@material-ui/core/Stepper'; import Step from '@material-ui/core/Step'; import StepLabel from '@material-ui/core/StepLabel'; import { Row, Col, Grid } from 'react-flexbox-grid'; import settings from 'electron-settings'; import { Button, Dialog, H1, H3, H4, H5, Icon, Position, Spinner, Text, Tooltip, } from '@blueprintjs/core'; import { useTranslation } from 'react-i18next'; import { TFunction } from 'i18next'; import { useToasts } from 'react-toast-notifications'; import SuccessStep from '../components/StepsOfStepper/SuccessStep'; import IntermediateStep from '../components/StepsOfStepper/IntermediateStep'; import AllowConnectionForDeviceAlert from '../components/AllowConnectionForDeviceAlert'; import DeviceConnectedInfoButton from '../components/StepperPanel/DeviceConnectedInfoButton'; import ColorlibStepIcon, { StepIconPropsDeskreen, } from '../components/StepperPanel/ColorlibStepIcon'; import ColorlibConnector from '../components/StepperPanel/ColorlibConnector'; import { SettingsContext } from './SettingsProvider'; import LanguageSelector from '../components/LanguageSelector'; import { getShuffledArrayOfHello } from '../configs/i18next.config.client'; import ToggleThemeBtnGroup from '../components/ToggleThemeBtnGroup'; import { IpcEvents } from '../main/IpcEvents.enum'; const Fade = require('react-reveal/Fade'); const useStyles = makeStyles(() => createStyles({ stepContent: { display: 'flex', flexDirection: 'column', justifyContent: 'center', alignItems: 'center', }, stepLabelContent: { marginTop: '10px !important', height: '110px', }, stepperComponent: { paddingBottom: '0px', }, }) ); function getSteps(t: TFunction) { return [t('Connect'), t('Select'), t('Confirm')]; } // eslint-disable-next-line react/display-name const DeskreenStepper = React.forwardRef((_props, ref) => { const { t } = useTranslation(); const classes = useStyles(); const { isDarkTheme } = useContext(SettingsContext); const { addToast } = useToasts(); const [isAlertOpen, setIsAlertOpen] = useState(false); const [isUserAllowedConnection, setIsUserAllowedConnection] = useState(false); const [isNoWiFiError, setisNoWiFiError] = useState(false); const [isSelectLanguageDialogOpen, setIsSelectLanguageDialogOpen] = useState( false ); const [ isStandForUkraineDialogOpen, setIsStandForUkraineDialogOpen, ] = useState(true); const [isDisplayHelloWord, setIsDisplayHelloWord] = useState(true); const [helloWord, setHelloWord] = useState('Hello'); const [ pendingConnectionDevice, setPendingConnectionDevice, ] = useState(null); useEffect(() => { const ipInterval = setInterval(async () => { const gotIP = await ipcRenderer.invoke('get-local-lan-ip'); if (gotIP === undefined) { setisNoWiFiError(true); } else { setisNoWiFiError(false); } }, 1000); return () => { clearInterval(ipInterval); }; }, []); useEffect(() => { ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession); ipcRenderer.on(IpcEvents.SetPendingConnectionDevice, (_, device) => { setPendingConnectionDevice(device); setIsAlertOpen(true); }); }, []); useEffect(() => { const isFirstTimeStart = !settings.hasSync('isNotFirstTimeAppStart'); setIsSelectLanguageDialogOpen(isFirstTimeStart); if (!isFirstTimeStart) return () => {}; const helloWords = getShuffledArrayOfHello(); let pos = 0; const helloInterval = setInterval(() => { setIsDisplayHelloWord(false); if (pos + 1 === helloWords.length) { pos = 0; } else { pos += 1; } setHelloWord(helloWords[pos]); setIsDisplayHelloWord(true); }, 4000); return () => { clearInterval(helloInterval); }; }, []); const [activeStep, setActiveStep] = useState(0); const [isEntireScreenSelected, setIsEntireScreenSelected] = useState(false); const [ isApplicationWindowSelected, setIsApplicationWindowSelected, ] = useState(false); const steps = getSteps(t); const handleNext = useCallback(() => { if (activeStep === steps.length - 1) { setIsEntireScreenSelected(false); setIsApplicationWindowSelected(false); } setActiveStep((prevActiveStep) => prevActiveStep + 1); }, [activeStep, steps]); const handleNextEntireScreen = useCallback(() => { setActiveStep((prevActiveStep) => prevActiveStep + 1); setIsEntireScreenSelected(true); }, []); const handleNextApplicationWindow = useCallback(() => { setActiveStep((prevActiveStep) => prevActiveStep + 1); setIsApplicationWindowSelected(true); }, []); const handleBack = useCallback(() => { setActiveStep((prevActiveStep) => prevActiveStep - 1); }, []); const handleReset = useCallback(() => { setActiveStep(0); setPendingConnectionDevice(null); setIsUserAllowedConnection(false); ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession); }, []); const handleResetWithSharingSessionRestart = useCallback(() => { setActiveStep(0); setPendingConnectionDevice(null); setIsUserAllowedConnection(false); ipcRenderer.invoke(IpcEvents.ResetWaitingForConnectionSharingSession); ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession); }, []); React.useImperativeHandle(ref, () => ({ handleReset() { handleResetWithSharingSessionRestart(); }, })); const handleCancelAlert = async () => { setIsAlertOpen(false); ipcRenderer.invoke(IpcEvents.ResetWaitingForConnectionSharingSession); ipcRenderer.invoke(IpcEvents.CreateWaitingForConnectionSharingSession); }; const handleConfirmAlert = useCallback(async () => { setIsAlertOpen(false); setIsUserAllowedConnection(true); handleNext(); ipcRenderer.invoke(IpcEvents.SetDeviceConnectedStatus); }, [handleNext]); const handleUserClickedDeviceDisconnectButton = useCallback(async () => { handleResetWithSharingSessionRestart(); addToast( {t( 'Device is successfully disconnected by you You can connect a new device' )} , { appearance: 'info', autoDismiss: true, // @ts-ignore: works fine here isdarktheme: `${isDarkTheme}`, } ); }, [addToast, handleResetWithSharingSessionRestart, isDarkTheme, t]); const renderIntermediateOrSuccessStepContent = useCallback(() => { return activeStep === steps.length ? (
) : (
setPendingConnectionDevice(null) // eslint-disable-next-line react/jsx-curly-newline } resetUserAllowedConnection={() => setIsUserAllowedConnection(false)} />
); }, [ activeStep, steps, handleReset, handleNext, handleBack, handleNextEntireScreen, handleNextApplicationWindow, ]); const renderStepLabelContent = useCallback( (label, idx) => { return ( {pendingConnectionDevice && idx === 0 && isUserAllowedConnection ? ( ) : ( {label} )} ); }, [ classes.stepLabelContent, handleUserClickedDeviceDisconnectButton, isApplicationWindowSelected, isEntireScreenSelected, isUserAllowedConnection, pendingConnectionDevice, ] ); return ( <> } > {steps.map((label, idx) => ( {renderStepLabelContent(label, idx)} ))} {renderIntermediateOrSuccessStepContent()}

No WiFi and LAN connection.

Deskreen works only with WiFi and LAN networks.

Waiting for connection.

{helloWord}

{t('Language')}
{t('Color Theme')}

DESKREEN CREATOR IS A UKRAINIAN. πŸ‡ΊπŸ‡¦ UKRAINE πŸ‡ΊπŸ‡¦ NEEDS YOUR HELP!

If you don't live in a cave and aware of what is going on in the world 🌍 , Russian πŸ‡·πŸ‡Ί government had started global armed invasion on the territory of Ukraine on the 24th of February 2022. This is for real, this is a WAR. Russian army is killing Ukrainian soldiers, Ukrainian civil citizens and Ukrainian children RIGHT NOW because Russian government gave them an order to do so. You can search online for thousands of videos of what is going on in Ukraine.

{' '} Ukrainians fight brave for their land and will never give up. But you must understand that our country is fighting here not for our land only, but for the safety of the whole world. ❗️❗️❗️ {' '} If Ukraine fails in this war with Russian army and Russian government, the security of all countries in the world 🌍 will be under the threat! Russian government and it's vicious allies and governments from other countries will be moving their armies to YOUR land, sooner or later ❗️❗️❗

You must understand that now Ukraine has more people here willing to fight than weapons, military supplies and other inverntory for them. If you CAN and WANT to support Ukraine πŸ‡ΊπŸ‡¦ and Ukrainian army, here is a tweet with instructions from OFFICIAL βœ… account of Ukraine πŸ‡ΊπŸ‡¦

YOU MUST UNDERSTAND THAT THIS WAR WITH UKRAINE STARTED NOT THE PEOPLE OF RUSSIA, BUT THE EVIL RUSSIAN GOVERNMENT! MOST OF RUSSIAN PEOPLE ARE PEACEFUL AND VERY KIND! IT IS A RUSSIAN GOVERNMENT THAT STARTED A WAR WITH THE WORLD THAT STARTED IN UKRAINE ON THE 24TH OF FEBRUARY 2022

); }); export default DeskreenStepper;