@@ -20,10 +20,11 @@ import { waitForDisconnect } from "./waitForDisconnect";
2020import { BridgeManager } from './BridgeManager' ;
2121import { AllowAuth , DeviceInUse , NoCompatibleDevices , OculusBrowserMessage , OldOsVersion , QuestOneNotSupported , Title , UnsupportedMessage } from './AppMessages' ;
2222import { PagePinger } from './PagePinger' ;
23+ import { useDeviceStore } from './DeviceStore' ;
2324
2425type NoDeviceCause = "NoDeviceSelected" | "DeviceInUse" ;
2526
26- const MIN_SUPPORTED_ANDROID_VERSION : number = 11 ;
27+ const NON_LEGACY_ANDROID_VERSION : number = 11 ;
2728
2829/**
2930 * Connects to the ADB server using the given client and device.
@@ -121,17 +122,17 @@ enum ConnectedState {
121122 */
122123async function connectDevice ( device : Adb , { setDevicePreV51, setAuthing, setChosenDevice } : {
123124 /** State setter for indicating if the device is pre-v51 (unsupported). */
124- setDevicePreV51 : SetStateAction < boolean >
125+ setDevicePreV51 : ( isPreV51 : boolean ) => void
125126
126- /** State setter for authentication status (false when done) . */
127+ /** State setter for authentication status. */
127128 setAuthing : SetStateAction < boolean >
128129
129130 /** State setter for the currently selected device. */
130- setChosenDevice : SetStateAction < Adb | null >
131+ setChosenDevice : ( adb : Adb | null ) => void
131132} ) {
132133 const androidVersion = await getAndroidVersion ( device ) ;
133134 Log . debug ( "Device android version: " + androidVersion ) ;
134- setDevicePreV51 ( androidVersion < MIN_SUPPORTED_ANDROID_VERSION ) ;
135+ setDevicePreV51 ( androidVersion < NON_LEGACY_ANDROID_VERSION ) ;
135136 setAuthing ( false ) ;
136137 setChosenDevice ( device ) ;
137138
@@ -153,13 +154,13 @@ async function connectDevice(device: Adb, { setDevicePreV51, setAuthing, setChos
153154 */
154155async function connectBridgeDevice ( bridgeClient : AdbServerClient , device : AdbServerClient . Device , { setDevicePreV51, setAuthing, setChosenDevice, setConnectError } : {
155156 /** State setter for indicating if the device is pre-v51 (unsupported). */
156- setDevicePreV51 : SetStateAction < boolean >
157+ setDevicePreV51 : ( isPreV51 : boolean ) => void
157158
158159 /** State setter for authentication status. */
159160 setAuthing : SetStateAction < boolean >
160161
161162 /** State setter for the currently selected device. */
162- setChosenDevice : SetStateAction < Adb | null >
163+ setChosenDevice : ( adb : Adb | null ) => void
163164
164165 /** State setter for connection error messages. */
165166 setConnectError : SetStateAction < string | null >
@@ -196,7 +197,7 @@ async function connectWebUsb({ setAuthing, setDeviceInUse, setChosenDevice, setC
196197 setDeviceInUse : SetStateAction < boolean >
197198
198199 /** State setter for the currently selected device. */
199- setChosenDevice : SetStateAction < Adb | null >
200+ setChosenDevice : ( adb : Adb | null ) => void
200201
201202 /** State setter for connection error messages. */
202203 setConnectError : SetStateAction < string | null >
@@ -243,10 +244,13 @@ async function connectWebUsb({ setAuthing, setDeviceInUse, setChosenDevice, setC
243244 */
244245function ChooseDevice ( ) {
245246 const [ authing , setAuthing ] = useState ( false ) ;
246- const [ chosenDevice , setChosenDevice ] = useState ( null as Adb | null ) ;
247247 const [ connectError , setConnectError ] = useState ( null as string | null ) ;
248- const [ devicePreV51 , setDevicePreV51 ] = useState ( false ) ;
249248 const [ deviceInUse , setDeviceInUse ] = useState ( false ) ;
249+ const {
250+ devicePreV51, setDevicePreV51,
251+ device : chosenDevice , setDevice : setChosenDevice , usingBridge, setUsingBridge,
252+ androidVersion, setAndroidVersion
253+ } = useDeviceStore ( ) ;
250254 const [ bridgeClient , setBridgeClient ] = useState < AdbServerClient | null > ( null ) ;
251255 const [ adbDevices , setAdbDevices ] = useState < AdbServerClient . Device [ ] > ( [ ] ) ;
252256 const stateSetters = {
@@ -258,33 +262,28 @@ function ChooseDevice() {
258262 setBridgeClient,
259263 setAdbDevices
260264 }
261-
265+
262266 useEffect ( ( ) => {
263267 // If the user is using a bridge and there is only one device, connect to it automatically.
264268 if ( chosenDevice == null && bridgeClient != null && adbDevices . length == 1 ) {
265269 connectBridgeDevice ( bridgeClient , adbDevices [ 0 ] , stateSetters ) . catch ( err => Log . error ( "Failed to connect to device: " + err , err ) ) ;
266270 }
267-
268271 } ) ;
269272
270273 if ( chosenDevice !== null ) {
271274 Log . debug ( "Device model: " + chosenDevice . banner . model ) ;
272- if ( chosenDevice . banner . model === "Quest" ) { // "Quest" not "Quest 2/3"
273- return < QuestOneNotSupported />
274- } else if ( devicePreV51 && chosenDevice . banner . model ?. includes ( "Quest" ) ) {
275- return < OldOsVersion />
276- } else {
277- return < >
278- { bridgeClient && < PagePinger url = { bridgeData . pingAddress } interval = { 5000 } /> }
279- < DeviceModder device = { chosenDevice } usingBridge = { bridgeClient != null } quit = { ( err ) => {
280- if ( err != null ) {
281- setConnectError ( String ( err ) ) ;
282- }
283- chosenDevice . close ( ) . catch ( err => Log . error ( "Failed to close device " + err , err ) ) ;
284- setChosenDevice ( null ) ;
285- } } />
286- </ >
287- }
275+ setUsingBridge ( bridgeClient != null ) ;
276+ return < >
277+ { bridgeClient && < PagePinger url = { bridgeData . pingAddress } interval = { 5000 } /> }
278+ < DeviceModder quit = { ( err ) => {
279+ if ( err != null ) {
280+ setConnectError ( String ( err ) ) ;
281+ }
282+ chosenDevice . close ( ) . catch ( err => Log . error ( "Failed to close device " + err , err ) ) ;
283+ setChosenDevice ( null ) ;
284+ setUsingBridge ( false ) ;
285+ } } />
286+ </ >
288287 } else if ( authing ) {
289288 return < AllowAuth />
290289 } else {
0 commit comments