Skip to content

Commit dbad94f

Browse files
authored
Merge pull request #1304 from Stremio/fix/shell-open-media-ready
App: Correctly deeplink even when app not started
2 parents c1ce15c + ddb3d03 commit dbad94f

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/App/App.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const App = () => {
2626
const { i18n } = useTranslation();
2727
const { shell } = usePlatform();
2828
const [gamepadSupportEnabled, setGamepadSupportEnabled] = React.useState(false);
29+
const appReadySent = React.useRef(false);
2930
const onPathNotMatch = React.useCallback(() => {
3031
return NotFound;
3132
}, []);
@@ -126,10 +127,15 @@ const App = () => {
126127

127128
shell.on('open-media', onOpenMedia);
128129

130+
if (shell.state.initialized && !appReadySent.current) {
131+
appReadySent.current = true;
132+
shell.send('app-ready');
133+
}
134+
129135
return () => {
130136
shell.off('open-media', onOpenMedia);
131137
};
132-
}, []);
138+
}, [shell.state.initialized]);
133139

134140
React.useEffect(() => {
135141
if (typeof profile.settings?.interfaceLanguage === 'string') {

src/common/Platform/shell/shell.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface Shell {
2121
}
2222

2323
type ShellState = {
24+
initialized: boolean;
2425
version: string | null;
2526
windowClosed: boolean;
2627
windowHidden: boolean;

src/common/Platform/shell/useShell.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ShellMessage = {
3636

3737
const useShell = (): Shell => {
3838
const [state, setState] = useState<ShellState>({
39+
initialized: false,
3940
version: null,
4041
windowClosed: false,
4142
windowHidden: false,
@@ -81,11 +82,6 @@ const useShell = (): Shell => {
8182
}, []);
8283

8384
useEffect(() => {
84-
IPC?.postMessage(JSON.stringify({
85-
id: 0,
86-
type: ShellEventType.INIT,
87-
}));
88-
8985
const onMessage = (message: ShellMessage) => {
9086
try {
9187
const event = JSON.parse(message.data) as ShellEvent;
@@ -94,8 +90,7 @@ const useShell = (): Shell => {
9490
const { data } = event as ShellEventInit;
9591
const [, [,,, version]] = data.transport.properties;
9692

97-
setState((state) => ({ ...state, version }));
98-
send('app-ready');
93+
setState((state) => ({ ...state, initialized: true, version }));
9994
}
10095

10196
if (event.type === ShellEventType.SIGNAL) {
@@ -109,6 +104,11 @@ const useShell = (): Shell => {
109104
};
110105

111106
IPC?.addEventListener('message', onMessage);
107+
IPC?.postMessage(JSON.stringify({
108+
id: 0,
109+
type: ShellEventType.INIT,
110+
}));
111+
112112
return () => IPC?.removeEventListener('message', onMessage);
113113
}, []);
114114

0 commit comments

Comments
 (0)