// Copyright (C) 2017-2022 Smart code 203358507 const React = require('react'); const classnames = require('classnames'); const throttle = require('lodash.throttle'); const Icon = require('@stremio/stremio-icons/dom'); const { useRouteFocused } = require('stremio-router'); const { useServices } = require('stremio/services'); const { Button, Checkbox, MainNavBars, Multiselect, ColorInput, TextInput, ModalDialog, useProfile, useStreamingServer, useBinaryState, withCoreSuspender } = require('stremio/common'); const useProfileSettingsInputs = require('./useProfileSettingsInputs'); const useStreamingServerSettingsInputs = require('./useStreamingServerSettingsInputs'); const styles = require('./styles'); const GENERAL_SECTION = 'general'; const PLAYER_SECTION = 'player'; const STREAMING_SECTION = 'streaming'; const Settings = () => { const { core } = useServices(); const { routeFocused } = useRouteFocused(); const profile = useProfile(); const streamingServer = useStreamingServer(); const { interfaceLanguageSelect, subtitlesLanguageSelect, subtitlesSizeSelect, subtitlesTextColorInput, subtitlesBackgroundColorInput, subtitlesOutlineColorInput, seekTimeDurationSelect, bingeWatchingCheckbox, playInBackgroundCheckbox, playInExternalPlayerCheckbox, hardwareDecodingCheckbox, streamingServerUrlInput } = useProfileSettingsInputs(profile); const { cacheSizeSelect, torrentProfileSelect } = useStreamingServerSettingsInputs(streamingServer); const [configureServerUrlModalOpen, openConfigureServerUrlModal, closeConfigureServerUrlModal] = useBinaryState(false); const configureServerUrlInputRef = React.useRef(null); const configureServerUrlOnSubmit = React.useCallback(() => { streamingServerUrlInput.onChange(configureServerUrlInputRef.current.value); closeConfigureServerUrlModal(); }, [streamingServerUrlInput]); const configureServerUrlModalButtons = React.useMemo(() => { return [ { className: styles['cancel-button'], label: 'Cancel', props: { onClick: closeConfigureServerUrlModal } }, { label: 'Submit', props: { onClick: configureServerUrlOnSubmit, } } ]; }, [configureServerUrlOnSubmit]); const logoutButtonOnClick = React.useCallback(() => { core.transport.dispatch({ action: 'Ctx', args: { action: 'Logout' } }); }, []); const authenticateTraktOnClick = React.useCallback(() => { // TODO }, []); const importFacebookOnClick = React.useCallback(() => { // TODO }, []); const subscribeCalendarOnClick = React.useCallback(() => { // TODO }, []); const exportDataOnClick = React.useCallback(() => { // TODO }, []); const reloadStreamingServer = React.useCallback(() => { core.transport.dispatch({ action: 'StreamingServer', args: { action: 'Reload' } }); }, []); const sectionsContainerRef = React.useRef(null); const generalSectionRef = React.useRef(null); const playerSectionRef = React.useRef(null); const streamingServerSectionRef = React.useRef(null); const sections = React.useMemo(() => ([ { ref: generalSectionRef, id: GENERAL_SECTION }, { ref: playerSectionRef, id: PLAYER_SECTION }, { ref: streamingServerSectionRef, id: STREAMING_SECTION }, ]), []); const [selectedSectionId, setSelectedSectionId] = React.useState(GENERAL_SECTION); const updateSelectedSectionId = React.useCallback(() => { if (sectionsContainerRef.current.scrollTop + sectionsContainerRef.current.clientHeight >= sectionsContainerRef.current.scrollHeight - 50) { setSelectedSectionId(sections[sections.length - 1].id); } else { for (let i = sections.length - 1; i >= 0; i--) { if (sections[i].ref.current.offsetTop - sectionsContainerRef.current.offsetTop <= sectionsContainerRef.current.scrollTop) { setSelectedSectionId(sections[i].id); break; } } } }, []); const sideMenuButtonOnClick = React.useCallback((event) => { const section = sections.find((section) => { return section.id === event.currentTarget.dataset.section; }); sectionsContainerRef.current.scrollTo({ top: section.ref.current.offsetTop - sectionsContainerRef.current.offsetTop, behavior: 'smooth' }); }, []); const sectionsContainerOnScorll = React.useCallback(throttle(() => { updateSelectedSectionId(); }, 50), []); React.useLayoutEffect(() => { if (routeFocused) { updateSelectedSectionId(); } closeConfigureServerUrlModal(); }, [routeFocused]); return (
App Version: {process.env.VERSION}
{ streamingServer.settings !== null && streamingServer.settings.type === 'Ready' ?
Server Version: {streamingServer.settings.content.serverVersion}
: null }
General
{profile.auth === null ? 'Anonymous user' : profile.auth.user.email}
{ profile.auth !== null ? : null }
{ profile.auth === null ?
: null }
Interface language
Trakt Scrobbling
Facebook
Calendar
Player
Subtitles language
Subtitles size
Subtitles text color
Subtitles background color
Subtitles outline color
Rewind & Fast-forward duration
Auto-play next episode
Play in background
Play in external player
Hardware-accelerated decoding
Streaming Server
Status
{ streamingServer.settings === null ? 'NotLoaded' : streamingServer.settings.type === 'Ready' ? 'Online' : streamingServer.settings.type === 'Error' ? `Error: (${streamingServer.settings.content})` : streamingServer.settings.type }
Url
{streamingServerUrlInput.value}
{ cacheSizeSelect !== null ?
Cache size
: null } { torrentProfileSelect !== null ?
Torrent profile
: null }
{ configureServerUrlModalOpen ? : null } ); }; const SettingsFallback = () => ( ); module.exports = withCoreSuspender(Settings, SettingsFallback);