diff --git a/src/apps/experimental/components/AppToolbar/menus/RemotePlayActiveMenu.tsx b/src/apps/experimental/components/AppToolbar/menus/RemotePlayActiveMenu.tsx index 0ea518c6c9..e184a3a25d 100644 --- a/src/apps/experimental/components/AppToolbar/menus/RemotePlayActiveMenu.tsx +++ b/src/apps/experimental/components/AppToolbar/menus/RemotePlayActiveMenu.tsx @@ -12,7 +12,7 @@ import { playbackManager } from 'components/playback/playbackmanager'; import React, { FC, useCallback, useState } from 'react'; import { Link } from 'react-router-dom'; -import { enable, isEnabled, supported } from 'scripts/autocast'; +import { enable, isEnabled } from 'scripts/autocast'; import globalize from 'scripts/globalize'; interface RemotePlayActiveMenuProps extends MenuProps { @@ -43,11 +43,10 @@ const RemotePlayActiveMenu: FC = ({ }, [ isDisplayMirrorEnabled, setIsDisplayMirrorEnabled ]); const [ isAutoCastEnabled, setIsAutoCastEnabled ] = useState(isEnabled()); - const isAutoCastSupported = supported(); const toggleAutoCast = useCallback(() => { enable(!isAutoCastEnabled); setIsAutoCastEnabled(!isAutoCastEnabled); - }, [ isAutoCastEnabled, setIsAutoCastEnabled ]); + }, [ isAutoCastEnabled ]); const remotePlayerName = playerInfo?.deviceName || playerInfo?.name; @@ -117,20 +116,18 @@ const RemotePlayActiveMenu: FC = ({ )} - {isAutoCastSupported && ( - - {isAutoCastEnabled && ( - - - - )} - - {globalize.translate('EnableAutoCast')} - - - )} + + {isAutoCastEnabled && ( + + + + )} + + {globalize.translate('EnableAutoCast')} + + - {(isDisplayMirrorSupported || isAutoCastSupported) && } + '; - html += '' + globalize.translate('EnableAutoCast') + ''; - html += ''; - } + html += '
'; html += '
'; diff --git a/src/index.jsx b/src/index.jsx index a74802cbb2..e8a3b5a3ad 100644 --- a/src/index.jsx +++ b/src/index.jsx @@ -24,6 +24,7 @@ import packageManager from './components/packageManager'; import './components/playback/displayMirrorManager.ts'; import { appRouter } from './components/router/appRouter'; import './elements/emby-button/emby-button'; +import { initialize as initializeAutoCast } from 'scripts/autocast'; import './scripts/autoThemes'; import './components/themeMediaPlayer'; import { pageClassOn, serverAddress } from './utils/dashboard'; @@ -79,6 +80,8 @@ build: ${__JF_BUILD_VERSION__}`); }).then(() => { console.debug('initAfterDependencies promises resolved'); + initializeAutoCast(ServerConnections.currentApiClient()); + loadCoreDictionary().then(function () { onGlobalizeInit(); }); diff --git a/src/scripts/autocast.js b/src/scripts/autocast.js index 2633587ba5..ead25e06eb 100644 --- a/src/scripts/autocast.js +++ b/src/scripts/autocast.js @@ -1,14 +1,7 @@ import { playbackManager } from '../components/playback/playbackmanager'; -import ServerConnections from '../components/ServerConnections'; import Events from '../utils/events.ts'; -export function supported() { - return typeof(Storage) !== 'undefined'; -} - export function enable(enabled) { - if (!supported()) return; - if (enabled) { const currentPlayerInfo = playbackManager.getPlayerInfo(); @@ -21,8 +14,6 @@ export function enable(enabled) { } export function isEnabled() { - if (!supported()) return false; - const playerId = localStorage.getItem('autocastPlayerId'); const currentPlayerInfo = playbackManager.getPlayerInfo(); @@ -42,12 +33,10 @@ function onOpen() { }); } -try { - const apiClient = ServerConnections.currentApiClient(); - - if (apiClient && supported()) { +export function initialize(apiClient) { + if (apiClient) { Events.on(apiClient, 'websocketopen', onOpen); + } else { + console.warn('[autoCast] cannot initialize missing apiClient'); } -} catch (ex) { - console.warn('Could not get current apiClient', ex); }