Merge pull request #922 from Stremio/refactor/shell-open-external
Some checks failed
Build / build (push) Has been cancelled

refactor(common): remove use of ipc for opening external url
This commit is contained in:
Tim 2025-06-01 12:15:19 +02:00 committed by GitHub
commit 75f647e3a4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,5 @@
import React, { createContext, useContext } from 'react';
import { WHITELISTED_HOSTS } from 'stremio/common/CONSTANTS';
import useShell from 'stremio/common/useShell';
import { name, isMobile } from './device';
interface PlatformContext {
@ -16,19 +15,13 @@ type Props = {
};
const PlatformProvider = ({ children }: Props) => {
const shell = useShell();
const openExternal = (url: string) => {
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');
}
window.open(finalUrl, '_blank');
} catch (e) {
console.error('Failed to parse external url:', e);
}