forked from anfreire/updateMe-Mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
80 lines (73 loc) · 2.09 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
*/
import React, {useEffect} from 'react';
import {SafeAreaView, StatusBar, View} from 'react-native';
import Pages from '@/pages';
import FilesModule from '@/lib/files';
import {useTheme} from '@/theme';
import DrawerWrapper from '@/global/drawer';
import {useSettings} from '@/states/persistent/settings';
import {useDialogs} from '@/states/temporary/dialogs';
import {useApp} from '@/states/temporary/app';
import {useTips} from '@/states/temporary/tips';
import PermissionsModule from '@/lib/permissions';
import { initBackgroundTasks } from '@/lib/background';
function App(): React.JSX.Element {
const theme = useTheme();
const deleteOnLeave = useSettings(
state => state.settings.downloads.deleteOnLeave,
);
const [info, localVersion] = useApp(state => [
state.info,
state.localVersion,
]);
const openDialog = useDialogs().openDialog;
const fetchTips = useTips().fetchTips;
const [releaseNotification, updateNotification] = useSettings(state => [
state.settings.notifications.newReleaseNotification,
state.settings.notifications.updatesNotification,
]);
useEffect(() => {
if (info.version && localVersion && info.version > localVersion)
openDialog('newVersion');
}, [info]);
useEffect(() => {
if (releaseNotification || updateNotification) {
PermissionsModule.grantPostNotification().then(_ =>
initBackgroundTasks(),
);
}
const fun = () => deleteOnLeave && FilesModule.deleteAllFiles();
fun();
fetchTips();
return () => {
fun();
};
}, []);
return (
<>
<StatusBar
backgroundColor={theme.schemedTheme.surfaceContainer}
barStyle={
theme.colorScheme === 'dark' ? 'light-content' : 'dark-content'
}
/>
<SafeAreaView>
<View
style={{
width: '100%',
height: '100%',
}}>
<DrawerWrapper>
<Pages />
</DrawerWrapper>
</View>
</SafeAreaView>
</>
);
}
export default App;