From 41546d65d246e2dcf69aa51bc7161d57f41ddc49 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 27 May 2025 20:16:26 +0200 Subject: [PATCH] feat: full deeplink support for shell --- src/App/App.js | 16 +++++++++++----- src/common/CONSTANTS.js | 3 +++ src/common/routesRegexp.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/App/App.js b/src/App/App.js index 38be271ac..57bdaee6a 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -102,12 +102,18 @@ const App = () => { // Handle shell events React.useEffect(() => { const onOpenMedia = (data) => { - if (data.startsWith('stremio:///')) return; - if (data.startsWith('stremio://')) { - const transportUrl = data.replace('stremio://', 'https://'); - if (URL.canParse(transportUrl)) { - window.location.href = `#/addons?addon=${encodeURIComponent(transportUrl)}`; + try { + const { protocol, hostname, pathname, searchParams } = new URL(data); + if (protocol === CONSTANTS.PROTOCOL) { + if (hostname.length) { + const transportUrl = `https://${hostname}${pathname}`; + window.location.href = `#/addons?addon=${encodeURIComponent(transportUrl)}`; + } else { + window.location.href = `#${pathname}?${searchParams.toString()}`; + } } + } catch (e) { + console.error("Failed to open media:", e); } }; diff --git a/src/common/CONSTANTS.js b/src/common/CONSTANTS.js index 8e4e3efdc..92d009895 100644 --- a/src/common/CONSTANTS.js +++ b/src/common/CONSTANTS.js @@ -106,6 +106,8 @@ const EXTERNAL_PLAYERS = [ const WHITELISTED_HOSTS = ['stremio.com', 'strem.io', 'stremio.zendesk.com', 'google.com', 'youtube.com', 'twitch.tv', 'twitter.com', 'x.com', 'netflix.com', 'adex.network', 'amazon.com', 'forms.gle']; +const PROTOCOL = 'stremio:'; + module.exports = { CHROMECAST_RECEIVER_APP_ID, DEFAULT_STREAMING_SERVER_URL, @@ -127,4 +129,5 @@ module.exports = { SUPPORTED_LOCAL_SUBTITLES, EXTERNAL_PLAYERS, WHITELISTED_HOSTS, + PROTOCOL, }; diff --git a/src/common/routesRegexp.js b/src/common/routesRegexp.js index 3903da44b..43f5810b1 100644 --- a/src/common/routesRegexp.js +++ b/src/common/routesRegexp.js @@ -6,7 +6,7 @@ const routesRegexp = { urlParamsNames: [] }, board: { - regexp: /^\/?$/, + regexp: /^\/(?:board)?$/, urlParamsNames: [] }, discover: {