xref: /expo/home/kernel/MockKernel.ts (revision 52c7ee12)
1import AsyncStorage from '@react-native-async-storage/async-storage';
2
3const STORAGE_PREFIX = '@@expo@@';
4
5/**
6 * A mock implementation of the native kernel module that can be used when loading Home as a regular
7 * project or when running it on web.
8 *
9 * Longer term, it may make sense to natively define a private, unprivileged implementation of the
10 * kernel module and use this implementation only on web.
11 */
12export default {
13  sdkVersions: '',
14
15  async getDevMenuSettingsAsync(): Promise<null> {
16    return null;
17  },
18
19  async setDevMenuSettingAsync(_key: string, _value: any): Promise<void> {},
20
21  async doesCurrentTaskEnableDevtoolsAsync(): Promise<boolean> {
22    return false;
23  },
24
25  async getDevMenuItemsToShowAsync(): Promise<unknown> {
26    return {};
27  },
28
29  async selectDevMenuItemWithKeyAsync(_key: string): Promise<void> {},
30
31  async reloadAppAsync(): Promise<void> {},
32
33  async closeDevMenuAsync(): Promise<void> {},
34
35  async goToHomeAsync(): Promise<void> {},
36
37  selectQRReader(): void {},
38
39  async getIsOnboardingFinishedAsync(): Promise<boolean> {
40    const item = await AsyncStorage.getItem(`${STORAGE_PREFIX}:onboarding`);
41    return !!item;
42  },
43
44  async setIsOnboardingFinishedAsync(finished: boolean): Promise<void> {
45    if (finished) {
46      await AsyncStorage.setItem(`${STORAGE_PREFIX}:onboarding`, '1');
47    } else {
48      await AsyncStorage.removeItem(`${STORAGE_PREFIX}:onboarding`);
49    }
50  },
51
52  async getSessionAsync(): Promise<unknown> {
53    const json = await AsyncStorage.getItem(`${STORAGE_PREFIX}:session`);
54    return json ? JSON.parse(json) : null;
55  },
56
57  async setSessionAsync(session: object): Promise<void> {
58    const json = JSON.stringify(session);
59    await AsyncStorage.setItem(`${STORAGE_PREFIX}:session`, json);
60  },
61
62  async removeSessionAsync(): Promise<void> {
63    await AsyncStorage.removeItem(`${STORAGE_PREFIX}:session`);
64  },
65
66  onEventSuccess(_eventId: string, _result: object): void {},
67
68  onEventFailure(_eventId: string, _message: string): void {},
69};
70