Skip to content

Commit 50e1d47

Browse files
committed
fix: add safeSelect for preload context and guard getInternalVideoChatWindowEnabled
select() has no null guard by design — it crashes loudly if called before store initialization, which is correct for the main process where the store is always ready before any select() call. Add safeSelect() for preload contexts where the store may not yet be initialized. Unlike select(), it returns T | undefined and TypeScript enforces that callers handle the undefined case. Use safeSelect in getInternalVideoChatWindowEnabled() with an explicit ?? false fallback, so early calls before store init return false (safe default) instead of crashing or silently returning undefined-as-boolean.
1 parent 14d4a56 commit 50e1d47

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/servers/preload/internalVideoChatWindow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { ipcRenderer } from 'electron';
22

3-
import { select } from '../../store';
3+
import { safeSelect } from '../../store';
44
import { openExternal } from '../../utils/browserLauncher';
55

66
export const getInternalVideoChatWindowEnabled = (): boolean =>
7-
select(
7+
safeSelect(
88
({ isInternalVideoChatWindowEnabled }) => isInternalVideoChatWindowEnabled
9-
);
9+
) ?? false;
1010

1111
export type videoCallWindowOptions = {
1212
providerName?: string | undefined;

src/store/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ type Selector<T> = (state: RootState) => T;
6666
export const select = <T>(selector: Selector<T>): T =>
6767
selector(reduxStore.getState());
6868

69+
export const safeSelect = <T>(selector: Selector<T>): T | undefined => {
70+
if (!reduxStore) return undefined;
71+
return selector(reduxStore.getState());
72+
};
73+
6974
export const watch = <T>(
7075
selector: Selector<T>,
7176
watcher: (curr: T, prev: T | undefined) => void

0 commit comments

Comments
 (0)