Merge pull request #1304 from Stremio/fix/shell-open-media-ready
Some checks are pending
Build / build (push) Waiting to run

App: Correctly deeplink even when app not started
This commit is contained in:
Timothy Z. 2026-06-14 15:17:56 +03:00 committed by GitHub
commit dbad94f2ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 8 deletions

View file

@ -26,6 +26,7 @@ const App = () => {
const { i18n } = useTranslation();
const { shell } = usePlatform();
const [gamepadSupportEnabled, setGamepadSupportEnabled] = React.useState(false);
const appReadySent = React.useRef(false);
const onPathNotMatch = React.useCallback(() => {
return NotFound;
}, []);
@ -126,10 +127,15 @@ const App = () => {
shell.on('open-media', onOpenMedia);
if (shell.state.initialized && !appReadySent.current) {
appReadySent.current = true;
shell.send('app-ready');
}
return () => {
shell.off('open-media', onOpenMedia);
};
}, []);
}, [shell.state.initialized]);
React.useEffect(() => {
if (typeof profile.settings?.interfaceLanguage === 'string') {

View file

@ -21,6 +21,7 @@ interface Shell {
}
type ShellState = {
initialized: boolean;
version: string | null;
windowClosed: boolean;
windowHidden: boolean;

View file

@ -36,6 +36,7 @@ type ShellMessage = {
const useShell = (): Shell => {
const [state, setState] = useState<ShellState>({
initialized: false,
version: null,
windowClosed: false,
windowHidden: false,
@ -81,11 +82,6 @@ const useShell = (): Shell => {
}, []);
useEffect(() => {
IPC?.postMessage(JSON.stringify({
id: 0,
type: ShellEventType.INIT,
}));
const onMessage = (message: ShellMessage) => {
try {
const event = JSON.parse(message.data) as ShellEvent;
@ -94,8 +90,7 @@ const useShell = (): Shell => {
const { data } = event as ShellEventInit;
const [, [,,, version]] = data.transport.properties;
setState((state) => ({ ...state, version }));
send('app-ready');
setState((state) => ({ ...state, initialized: true, version }));
}
if (event.type === ShellEventType.SIGNAL) {
@ -109,6 +104,11 @@ const useShell = (): Shell => {
};
IPC?.addEventListener('message', onMessage);
IPC?.postMessage(JSON.stringify({
id: 0,
type: ShellEventType.INIT,
}));
return () => IPC?.removeEventListener('message', onMessage);
}, []);