diff --git a/package-lock.json b/package-lock.json index 5775eb1a9..31a0fdda8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", - "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", + "stremio-translations": "github:Stremio/stremio-translations#378218c9617f3e763ba5f6755e4d39c1c158747d", "url": "0.11.0", "use-long-press": "^3.1.5" }, @@ -12470,10 +12470,9 @@ } }, "node_modules/stremio-translations": { - "version": "1.44.7", - "resolved": "git+ssh://git@github.com/Stremio/stremio-translations.git#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", - "integrity": "sha512-OtRAM3j9ie89llgI379p4utCbgnNMswE+LtL/lyLRVLfm5B+jpBLp4ozpU25iQg0O4tvN+OHBjXZ870CCHtZMA==", - "license": "MIT" + "version": "1.44.9", + "resolved": "git+ssh://git@github.com/Stremio/stremio-translations.git#378218c9617f3e763ba5f6755e4d39c1c158747d", + "integrity": "sha512-3GboN8JS2LgrdIVK/gW+n6r1kLrGG+D/tWkRv8PJo2mZLzh49HTzS2u7XXUSkNmA4AGUyEf8QRjyBhlOg8JNTQ==" }, "node_modules/string_decoder": { "version": "1.1.1", diff --git a/package.json b/package.json index 6610395a6..1339ba710 100755 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", - "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", + "stremio-translations": "github:Stremio/stremio-translations#378218c9617f3e763ba5f6755e4d39c1c158747d", "url": "0.11.0", "use-long-press": "^3.1.5" }, diff --git a/src/common/CONSTANTS.js b/src/common/CONSTANTS.js index 742c138d6..c08cf471d 100644 --- a/src/common/CONSTANTS.js +++ b/src/common/CONSTANTS.js @@ -93,6 +93,8 @@ const EXTERNAL_PLAYERS = [ }, ]; +const WHITELISTED_HOSTS = ['stremio.com', 'strem.io', 'stremio.zendesk.com', 'google.com', 'youtube.com', 'twitch.tv', 'twitter.com', 'netflix.com', 'adex.network', 'amazon.com', 'forms.gle']; + module.exports = { CHROMECAST_RECEIVER_APP_ID, SUBTITLES_SIZES, @@ -110,4 +112,5 @@ module.exports = { TYPE_PRIORITIES, ICON_FOR_TYPE, EXTERNAL_PLAYERS, + WHITELISTED_HOSTS, }; diff --git a/src/common/Platform/Platform.tsx b/src/common/Platform/Platform.tsx index c93064d78..13e8592ad 100644 --- a/src/common/Platform/Platform.tsx +++ b/src/common/Platform/Platform.tsx @@ -1,5 +1,6 @@ import React, { createContext, useContext } from 'react'; import useShell from './useShell'; +import { WHITELISTED_HOSTS } from 'stremio/common/CONSTANTS'; interface PlatformContext { openExternal: (url: string) => void, @@ -15,11 +16,19 @@ const PlatformProvider = ({ children }: Props) => { const shell = useShell(); const openExternal = (url: string) => { - if (shell.active) { - shell.send('open-external', url); - } else { - window.open(url, '_blank'); - } + try { + const { hostname } = new URL(url); + const isWhitelisted = WHITELISTED_HOSTS.some((host: string) => hostname.endsWith(host)); + const finalUrl = !isWhitelisted ? 'https://www.stremio.com/warning#' + encodeURIComponent(url) : url; + + if (shell.active) { + shell.send('open-external', finalUrl); + } else { + window.open(finalUrl, '_blank'); + } + } catch (e) { + console.error('Failed to parse external url:', e); + } }; return ( @@ -36,4 +45,4 @@ const usePlatform = () => { export { PlatformProvider, usePlatform, -}; \ No newline at end of file +}; diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 5c5d51774..3e0c4cf8e 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -11,6 +11,7 @@ const { Button, Checkbox, MainNavBars, Multiselect, ColorInput, TextInput, Modal const useProfileSettingsInputs = require('./useProfileSettingsInputs'); const useStreamingServerSettingsInputs = require('./useStreamingServerSettingsInputs'); const useDataExport = require('./useDataExport'); +const { name: platformName } = require('stremio/common/platform'); const styles = require('./styles'); const GENERAL_SECTION = 'general'; @@ -103,15 +104,16 @@ const Settings = () => { } }, [isTraktAuthenticated, profile.auth]); const subscribeCalendarOnClick = React.useCallback(() => { - const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`; + const protocol = platformName === 'ios' ? 'webcal' : 'https'; + const url = `${protocol}://www.strem.io/calendar/${profile.auth.user._id}.ics`; platform.openExternal(url); toast.show({ type: 'success', - title: 'Calendar has been added to your default caldendar app', + title: platformName === 'ios' ? t('SETTINGS_SUBSCRIBE_CALENDAR_IOS_TOAST') : t('SETTINGS_SUBSCRIBE_CALENDAR_TOAST'), timeout: 25000 }); - //Stremio 4 emits not documented event subscribeCalendar - }, []); + // Stremio 4 emits not documented event subscribeCalendar + }, [profile.auth.user._id]); const exportDataOnClick = React.useCallback(() => { loadDataExport(); }, []);