From a95459efd3567b8f8ad5e42edc14c7c7f2ba71ed Mon Sep 17 00:00:00 2001 From: Felipe Pontes Date: Mon, 3 Jul 2023 09:42:45 -0300 Subject: [PATCH 1/7] feat: Add ability to start with custom streming server --- src/App/App.js | 2 ++ src/App/DefaultSettingsHandler.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/App/DefaultSettingsHandler.js diff --git a/src/App/App.js b/src/App/App.js index 77a4b5824..5be4754b7 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -9,6 +9,7 @@ const { NotFound } = require('stremio/routes'); const { ToastProvider, CONSTANTS } = require('stremio/common'); const ServicesToaster = require('./ServicesToaster'); const DeepLinkHandler = require('./DeepLinkHandler'); +const DefaultSettingsHandler = require('./DefaultSettingsHandler'); const ErrorDialog = require('./ErrorDialog'); const routerViewsConfig = require('./routerViewsConfig'); const styles = require('./styles'); @@ -152,6 +153,7 @@ const App = () => { + { + const profile = useProfile(); + + const { streamingServerUrlInput } = useProfileSettingsInputs(profile); + + React.useLayoutEffect(() => { + const searchParams = new URLSearchParams(window.location.search); + if (searchParams.has('streamingServerUrl')) { + streamingServerUrlInput.onChange(searchParams.get('streamingServerUrl')); + } + }, []); + + return null; +}; + +module.exports = withCoreSuspender(DefaultSettingsHandler); From a2eca60e4561858eec093489e8633bfbe6602312 Mon Sep 17 00:00:00 2001 From: Felipe Pontes Date: Thu, 10 Aug 2023 17:15:21 -0300 Subject: [PATCH 2/7] feat: Reload streming server after update --- src/App/DefaultSettingsHandler.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/App/DefaultSettingsHandler.js b/src/App/DefaultSettingsHandler.js index e47f93431..42cc8165d 100644 --- a/src/App/DefaultSettingsHandler.js +++ b/src/App/DefaultSettingsHandler.js @@ -6,16 +6,27 @@ const { useProfile, } = require('stremio/common'); const useProfileSettingsInputs = require('stremio/routes/Settings/useProfileSettingsInputs'); +const { useServices } = require('stremio/services'); const DefaultSettingsHandler = () => { + const { core } = useServices(); + const profile = useProfile(); const { streamingServerUrlInput } = useProfileSettingsInputs(profile); - React.useLayoutEffect(() => { + React.useEffect(() => { const searchParams = new URLSearchParams(window.location.search); if (searchParams.has('streamingServerUrl')) { streamingServerUrlInput.onChange(searchParams.get('streamingServerUrl')); + setTimeout(() => { + core.transport.dispatch({ + action: 'StreamingServer', + args: { + action: 'Reload' + } + }); + }, 2000); } }, []); From e7f3b0846627f71fdd1bd783b3a5bc9aaecdee10 Mon Sep 17 00:00:00 2001 From: Felipe Pontes Date: Thu, 10 Aug 2023 17:23:07 -0300 Subject: [PATCH 3/7] feat: Use core dispatch directly --- src/App/DefaultSettingsHandler.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/App/DefaultSettingsHandler.js b/src/App/DefaultSettingsHandler.js index 42cc8165d..47bc329e9 100644 --- a/src/App/DefaultSettingsHandler.js +++ b/src/App/DefaultSettingsHandler.js @@ -5,7 +5,6 @@ const { withCoreSuspender, useProfile, } = require('stremio/common'); -const useProfileSettingsInputs = require('stremio/routes/Settings/useProfileSettingsInputs'); const { useServices } = require('stremio/services'); const DefaultSettingsHandler = () => { @@ -13,12 +12,19 @@ const DefaultSettingsHandler = () => { const profile = useProfile(); - const { streamingServerUrlInput } = useProfileSettingsInputs(profile); - React.useEffect(() => { const searchParams = new URLSearchParams(window.location.search); if (searchParams.has('streamingServerUrl')) { - streamingServerUrlInput.onChange(searchParams.get('streamingServerUrl')); + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'UpdateSettings', + args: { + ...profile.settings, + streamingServerUrl: searchParams.get('streamingServerUrl') + } + } + }); setTimeout(() => { core.transport.dispatch({ action: 'StreamingServer', @@ -26,7 +32,7 @@ const DefaultSettingsHandler = () => { action: 'Reload' } }); - }, 2000); + }, 1000); } }, []); From fb7963c09e37d2e9c70cd4fb2030be901ba8a66b Mon Sep 17 00:00:00 2001 From: Felipe Pontes Date: Thu, 10 Aug 2023 17:27:23 -0300 Subject: [PATCH 4/7] feat: Show toast notification --- src/App/DefaultSettingsHandler.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/App/DefaultSettingsHandler.js b/src/App/DefaultSettingsHandler.js index 47bc329e9..c963db130 100644 --- a/src/App/DefaultSettingsHandler.js +++ b/src/App/DefaultSettingsHandler.js @@ -4,24 +4,28 @@ const React = require('react'); const { withCoreSuspender, useProfile, + useToast, } = require('stremio/common'); const { useServices } = require('stremio/services'); const DefaultSettingsHandler = () => { const { core } = useServices(); + const toast = useToast(); const profile = useProfile(); React.useEffect(() => { const searchParams = new URLSearchParams(window.location.search); if (searchParams.has('streamingServerUrl')) { + const streamingServerUrl = searchParams.get('streamingServerUrl'); + core.transport.dispatch({ action: 'Ctx', args: { action: 'UpdateSettings', args: { ...profile.settings, - streamingServerUrl: searchParams.get('streamingServerUrl') + streamingServerUrl } } }); @@ -33,6 +37,11 @@ const DefaultSettingsHandler = () => { } }); }, 1000); + toast.show({ + type: 'info', + title: `Using streaming server at ${streamingServerUrl}`, + timeout: 4000 + }); } }, []); From bf11195d0e67a719fbf62e151f45f16a16ed4a89 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 30 Jan 2024 04:05:36 +0100 Subject: [PATCH 5/7] refactor(App): use SearchParamsHandler --- src/App/App.js | 3 +- src/App/SearchParamsHandler.js | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/App/SearchParamsHandler.js diff --git a/src/App/App.js b/src/App/App.js index 79efaf0fd..b5f67a658 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -9,7 +9,7 @@ const { NotFound } = require('stremio/routes'); const { ToastProvider, TooltipProvider, CONSTANTS, withCoreSuspender } = require('stremio/common'); const ServicesToaster = require('./ServicesToaster'); const DeepLinkHandler = require('./DeepLinkHandler'); -const DefaultSettingsHandler = require('./DefaultSettingsHandler'); +const SearchParamsHandler = require('./SearchParamsHandler'); const ErrorDialog = require('./ErrorDialog'); const withProtectedRoutes = require('./withProtectedRoutes'); const routerViewsConfig = require('./routerViewsConfig'); @@ -165,6 +165,7 @@ const App = () => { + { + const { core } = useServices(); + const profile = useProfile(); + const toast = useToast(); + + const [searchParams, setSearchParams] = React.useState({}); + + const onLocationChange = () => { + const { origin, hash, search } = window.location; + const { searchParams } = new URL(`${origin}${search.length ? search : hash.replace('#', '')}`); + + setSearchParams((previousSearchParams) => { + const currentSearchParams = Object.fromEntries(searchParams.entries()); + return isEqual(previousSearchParams, currentSearchParams) ? previousSearchParams : currentSearchParams; + }); + }; + + React.useEffect(() => { + const { streamingServerUrl } = searchParams; + + if (streamingServerUrl) { + core.transport.dispatch({ + action: 'Ctx', + args: { + action: 'UpdateSettings', + args: { + ...profile.settings, + streamingServerUrl, + }, + }, + }); + + toast.show({ + type: 'success', + title: `Using streaming server at ${streamingServerUrl}`, + timeout: 4000, + }); + } + }, [searchParams]); + + React.useEffect(() => { + onLocationChange(); + window.addEventListener('hashchange', onLocationChange); + return () => window.removeEventListener('hashchange', onLocationChange); + }, []); + + return null; +}; + +module.exports = withCoreSuspender(SearchParamsHandler); From 2b8dc5589378b8e2aaaa2775399feadbfaf2f55e Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 30 Jan 2024 08:50:29 +0100 Subject: [PATCH 6/7] refactor(App): remove DefaultSettingsHandler --- src/App/DefaultSettingsHandler.js | 51 ------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 src/App/DefaultSettingsHandler.js diff --git a/src/App/DefaultSettingsHandler.js b/src/App/DefaultSettingsHandler.js deleted file mode 100644 index c963db130..000000000 --- a/src/App/DefaultSettingsHandler.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2017-2023 Smart code 203358507 - -const React = require('react'); -const { - withCoreSuspender, - useProfile, - useToast, -} = require('stremio/common'); -const { useServices } = require('stremio/services'); - -const DefaultSettingsHandler = () => { - const { core } = useServices(); - const toast = useToast(); - - const profile = useProfile(); - - React.useEffect(() => { - const searchParams = new URLSearchParams(window.location.search); - if (searchParams.has('streamingServerUrl')) { - const streamingServerUrl = searchParams.get('streamingServerUrl'); - - core.transport.dispatch({ - action: 'Ctx', - args: { - action: 'UpdateSettings', - args: { - ...profile.settings, - streamingServerUrl - } - } - }); - setTimeout(() => { - core.transport.dispatch({ - action: 'StreamingServer', - args: { - action: 'Reload' - } - }); - }, 1000); - toast.show({ - type: 'info', - title: `Using streaming server at ${streamingServerUrl}`, - timeout: 4000 - }); - } - }, []); - - return null; -}; - -module.exports = withCoreSuspender(DefaultSettingsHandler); From 8f71788f4e15c32339007a04e489438e38fc4a87 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 30 Jan 2024 09:32:52 +0100 Subject: [PATCH 7/7] refactor(SearchParamsHandler): simplify URL parsing --- src/App/SearchParamsHandler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App/SearchParamsHandler.js b/src/App/SearchParamsHandler.js index 64faa36b0..cdaa44517 100644 --- a/src/App/SearchParamsHandler.js +++ b/src/App/SearchParamsHandler.js @@ -14,7 +14,7 @@ const SearchParamsHandler = () => { const onLocationChange = () => { const { origin, hash, search } = window.location; - const { searchParams } = new URL(`${origin}${search.length ? search : hash.replace('#', '')}`); + const { searchParams } = new URL(`${origin}${hash.replace('#', '')}${search}`); setSearchParams((previousSearchParams) => { const currentSearchParams = Object.fromEntries(searchParams.entries());