forked from minhealthnz/nzcovidtracer-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ts
97 lines (82 loc) · 2.8 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
import config from "./src/config";
if (__DEV__ || config.IsDev) {
import("./reactotronConfig");
}
import "react-native-gesture-handler";
import "./i18n";
import Auth from "@aws-amplify/auth";
import Amplify from "@aws-amplify/core";
import covidTracker from "@db/covidTracerMigration";
import { createPublic } from "@db/create";
import { formatEnv } from "@features/debugging/commands/copyEnvVar";
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, Platform } from "react-native";
import DeviceInfo from "react-native-device-info";
import { enableScreens } from "react-native-screens";
import { configure as configurePush } from "./src/notifications";
enableScreens();
const { logError, logInfo } = createLogger("setup");
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);
//Configure AWS pinpoint
Amplify.configure({
Auth: {
identityPoolId: config.CognitoIdentityPoolId,
region: config.CognitoUserPoolRegion,
},
Analytics: {
disabled: false,
autoSessionRecord: true,
AWSPinpoint: {
appId: config.PinpointApplicationId,
region: config.PinpointRegion,
mandatorySignIn: false,
endpoint: {
address: DeviceInfo.getUniqueId(),
channelType: Platform.OS === "ios" ? "APNS" : "GCM",
demographic: {
appVersion: config.APP_VERSION,
make: DeviceInfo.getBrand(),
model: DeviceInfo.getModel(),
platform: DeviceInfo.getSystemName(),
platformVersion: DeviceInfo.getSystemVersion(),
},
},
},
},
});
// Need to call this line. See https://github.com/aws-amplify/amplify-js/issues/4448
Auth.currentCredentials();
configurePush();
logInfo(`app state ${AppState.currentState}`);
AppState.addEventListener("change", (value: AppStateStatus) => {
logInfo(`app state ${value}`);
});