This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup.ts
101 lines (83 loc) · 2.75 KB
/
setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import config from "./src/config";
if (__DEV__ || config.IsDev) {
import("./reactotronConfig");
}
import "react-native-gesture-handler";
import "./i18n";
import covidTracker from "@db/covidTracerMigration";
import { createPublic } from "@db/create";
import { formatEnv } from "@features/debugging/commands/copyEnvVar";
import { recordLaunch } from "@features/device/recordLaunch";
import { processPushNotification } from "@features/exposure/service/processPushNotification";
import { createLogger } from "@logger/createLogger";
import messaging, {
FirebaseMessagingTypes,
} from "@react-native-firebase/messaging";
import { dirname } from "path";
import { AppState, AppStateStatus, LogBox, Platform } from "react-native";
import ExposureNotificationModule from "react-native-exposure-notification-service";
import { enableScreens } from "react-native-screens";
import { setupAnalytics } from "./src/analytics/setupAnalytics";
import { configure as configurePush } from "./src/notifications";
const { logError, logInfo } = createLogger("setup");
if (config.HideLogs) {
LogBox.ignoreAllLogs();
}
LogBox.ignoreLogs([
/AsyncStorage has been extracted from .*/,
/Require cycle: .*ws-amplify.*/,
]);
enableScreens();
logInfo("app launched with env variables:" + "\n" + formatEnv(true));
async function applyPublicDbFileProtection() {
if (Platform.OS === "ios" && covidTracker.applyPublicFileProtection != null) {
const db = await createPublic();
const dir = dirname(db.path);
db.close();
await covidTracker.applyPublicFileProtection(dir);
}
}
messaging().setBackgroundMessageHandler(
async (message: FirebaseMessagingTypes.RemoteMessage) => {
logInfo("message being processed in background!");
await applyPublicDbFileProtection();
try {
await processPushNotification(
message,
// TODO figure out how to translate this
"You may have been in contact with COVID-19. Tap for more information.",
);
} catch (err) {
logError(err);
}
},
);
applyPublicDbFileProtection().catch(logError);
setupAnalytics();
configurePush();
logInfo(`app state ${AppState.currentState}`);
AppState.addEventListener("change", (value: AppStateStatus) => {
logInfo(`app state ${value}`);
if (value === "active") {
ExposureNotificationModule.exposureEnabled()
.then((isENFEnabled) => {
logInfo(
`Update isENFEnabled via Analytics.updateEndpoint with value: ${isENFEnabled}`,
);
const { Analytics } = require("aws-amplify");
return Analytics.updateEndpoint({
attributes: {
isENFEnabled: [isENFEnabled],
},
});
})
.catch(logError);
}
});
(async () => {
try {
await recordLaunch();
} catch (err) {
logError(err);
}
})();