@@ -36,14 +36,21 @@ export function DeviceAndroidFoldControls(props: {
3636 if ( ! props . visible || ! props . enabled || pending || ! props . screenWidth || ! props . screenHeight )
3737 return ;
3838 const controller = new AbortController ( ) ;
39- void readAndroidFold ( props . access , props . deviceId , controller . signal )
40- . then ( ( next ) => {
41- if ( ! controller . signal . aborted ) setFold ( next ) ;
42- } )
43- . catch ( ( ) => {
44- if ( ! controller . signal . aborted ) setFold ( null ) ;
45- } ) ;
46- return ( ) => controller . abort ( ) ;
39+ let retry : number | undefined ;
40+ const read = ( ) => {
41+ void readAndroidFold ( props . access , props . deviceId , controller . signal )
42+ . then ( ( next ) => {
43+ if ( ! controller . signal . aborted ) setFold ( next ) ;
44+ } )
45+ . catch ( ( ) => {
46+ if ( ! controller . signal . aborted ) retry = window . setTimeout ( read , 3_000 ) ;
47+ } ) ;
48+ } ;
49+ read ( ) ;
50+ return ( ) => {
51+ controller . abort ( ) ;
52+ window . clearTimeout ( retry ) ;
53+ } ;
4754 } , [
4855 props . access ,
4956 props . deviceId ,
@@ -61,15 +68,24 @@ export function DeviceAndroidFoldControls(props: {
6168 busy . current = true ;
6269 setPending ( true ) ;
6370 setError ( null ) ;
64- void setAndroidFold ( props . access , props . deviceId , posture )
71+ const controller = new AbortController ( ) ;
72+ const timeout = window . setTimeout ( ( ) => controller . abort ( ) , 12_000 ) ;
73+ void setAndroidFold ( props . access , props . deviceId , posture , controller . signal )
6574 . then ( ( next ) => {
6675 if ( mounted . current ) setFold ( next ) ;
6776 } )
6877 . catch ( ( cause : unknown ) => {
6978 if ( mounted . current )
70- setError ( cause instanceof Error ? cause . message : "Could not change fold posture." ) ;
79+ setError (
80+ controller . signal . aborted
81+ ? "Fold command timed out."
82+ : cause instanceof Error
83+ ? cause . message
84+ : "Could not change fold posture." ,
85+ ) ;
7186 } )
7287 . finally ( ( ) => {
88+ window . clearTimeout ( timeout ) ;
7389 busy . current = false ;
7490 if ( mounted . current ) setPending ( false ) ;
7591 } ) ;
0 commit comments