/* eslint-disable jsx-a11y/anchor-is-valid */ /* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ import { ipcRenderer, remote, shell } from 'electron'; import React, { useContext, useCallback, useEffect, useState } from 'react'; import { Button, Overlay, Classes, H3, H6, H4, Tabs, Tab, Icon, HTMLSelect, Text, ControlGroup, Checkbox, } from '@blueprintjs/core'; import { useTranslation } from 'react-i18next'; import { Col, Row } from 'react-flexbox-grid'; import { createStyles, makeStyles } from '@material-ui/core/styles'; import i18n from 'i18next'; import SharingSessionService from '../../features/SharingSessionService'; import { DARK_UI_BACKGROUND, LIGHT_UI_BACKGROUND, SettingsContext, } from '../../containers/SettingsProvider'; import CloseOverlayButton from '../CloseOverlayButton'; import i18n_client, { getLangFullNameToLangISOKeyMap, getLangISOKeyToLangFullNameMap, } from '../../configs/i18next.config.client'; import SettingRowLabelAndInput from './SettingRowLabelAndInput'; import isWithReactRevealAnimations from '../../utils/isWithReactRevealAnimations'; import config from '../../api/config'; const { port } = config; const Fade = require('react-reveal/Fade'); const sharingSessionService = remote.getGlobal( 'sharingSessionService' ) as SharingSessionService; interface SettingsOverlayProps { isSettingsOpen: boolean; handleClose: () => void; } const useStylesWithTheme = (isDarkTheme: boolean) => makeStyles(() => createStyles({ checkboxSettings: { margin: '0' }, overlayInnerRoot: { width: '90%' }, overlayInsideFade: { height: '90vh', backgroundColor: isDarkTheme ? DARK_UI_BACKGROUND : LIGHT_UI_BACKGROUND, }, absoluteCloseButton: { position: 'absolute', left: 'calc(100% - 65px)' }, tabNavigationRowButton: { fontWeight: 700 }, iconInTablLeftButton: { marginRight: '5px' }, }) ); export default function SettingsOverlay(props: SettingsOverlayProps) { const { t } = useTranslation(); const { handleClose, isSettingsOpen } = props; const [latestVersion, setLatestVersion] = useState(''); const [currentVersion, setCurrentVersion] = useState(''); const { isDarkTheme, setIsDarkThemeHook, setCurrentLanguageHook, } = useContext(SettingsContext); const [languagesList, setLanguagesList] = useState([] as string[]); useEffect(() => { const getLatestVersion = async () => { const gotLatestVersion = await ipcRenderer.invoke('get-latest-version'); if (gotLatestVersion !== '') { setLatestVersion(gotLatestVersion); } }; getLatestVersion(); const getCurrentVersion = async () => { const gotCurrentVersion = await ipcRenderer.invoke('get-current-version'); if (gotCurrentVersion !== '') { setCurrentVersion(gotCurrentVersion); } }; getCurrentVersion(); }, []); useEffect(() => { const tmp: string[] = []; getLangFullNameToLangISOKeyMap().forEach((_, key) => { tmp.push(key); }); setLanguagesList(tmp); setCurrentLanguageHook(i18n_client.language); }, [setCurrentLanguageHook]); const getClassesCallback = useStylesWithTheme(isDarkTheme); const handleToggleDarkTheme = useCallback(() => { if (!isDarkTheme) { document.body.classList.toggle(Classes.DARK); setIsDarkThemeHook(true); } // TODO: call sharing sessions service here to notify all connected clients about theme change sharingSessionService.sharingSessions.forEach((sharingSession) => { sharingSession?.appThemeChanged(true); }); sharingSessionService.setAppTheme(true); }, [isDarkTheme, setIsDarkThemeHook]); const handleToggleLightTheme = useCallback(() => { if (isDarkTheme) { document.body.classList.toggle(Classes.DARK); setIsDarkThemeHook(false); } // TODO: call sharing sessions service here to notify all connected clients about theme change sharingSessionService.sharingSessions.forEach((sharingSession) => { sharingSession?.appThemeChanged(false); }); sharingSessionService.setAppTheme(false); }, [isDarkTheme, setIsDarkThemeHook]); const onChangeLangueageHTMLSelectHandler = ( event: React.ChangeEvent ) => { if ( event.currentTarget && getLangFullNameToLangISOKeyMap().has(event.currentTarget.value) ) { const newLang = getLangFullNameToLangISOKeyMap().get(event.currentTarget.value) || 'English'; i18n.changeLanguage(newLang); // TODO: call sharing sessions service here to notify all connected clients about language change sharingSessionService.sharingSessions.forEach((sharingSession) => { sharingSession?.appLanguageChanged(newLang); }); sharingSessionService.setAppLanguage(newLang); } }; const getThemeChangingControlGroupInput = () => { return (