mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-08-16 03:17:07 +00:00
Merge pull request #1304 from Stremio/fix/shell-open-media-ready
Some checks are pending
Build / build (push) Waiting to run
Some checks are pending
Build / build (push) Waiting to run
App: Correctly deeplink even when app not started
This commit is contained in:
commit
dbad94f2ff
3 changed files with 15 additions and 8 deletions
|
|
@ -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') {
|
||||
|
|
|
|||
1
src/common/Platform/shell/shell.d.ts
vendored
1
src/common/Platform/shell/shell.d.ts
vendored
|
|
@ -21,6 +21,7 @@ interface Shell {
|
|||
}
|
||||
|
||||
type ShellState = {
|
||||
initialized: boolean;
|
||||
version: string | null;
|
||||
windowClosed: boolean;
|
||||
windowHidden: boolean;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue