forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.tsx
More file actions
54 lines (49 loc) · 1.67 KB
/
Copy pathMain.tsx
File metadata and controls
54 lines (49 loc) · 1.67 KB
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
import * as React from 'react';
import { SafeAreaView, StyleSheet, View, Text } from 'react-native';
import { RoundButton } from './components/RoundButton';
import { Theme } from './components/theme';
import { useDevice } from '../modules/useDevice';
import { DeviceView } from './DeviceView';
import { startAudio } from '../modules/openai';
export const Main = React.memo(() => {
const [device, connectDevice, isAutoConnecting] = useDevice();
const [isConnecting, setIsConnecting] = React.useState(false);
// Handle connection attempt
const handleConnect = React.useCallback(async () => {
setIsConnecting(true);
try {
await connectDevice();
} finally {
setIsConnecting(false);
}
}, [connectDevice]);
return (
<SafeAreaView style={styles.container}>
{!device && (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', alignSelf: 'center' }}>
{isConnecting ? (
<Text style={styles.statusText}>Connecting to OpenGlass...</Text>
) : (
<RoundButton title="Connect to the device" action={handleConnect} />
)}
</View>
)}
{device && (
<DeviceView device={device} />
)}
</SafeAreaView>
);
});
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: Theme.background,
alignItems: 'stretch',
justifyContent: 'center',
},
statusText: {
color: Theme.text,
fontSize: 18,
marginBottom: 16,
}
});