File tree Expand file tree Collapse file tree
packages/happy-app/sources/hooks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,19 +65,35 @@ export function useConnectAccount(options?: UseConnectAccountOptions) {
6565 } , [ processAuthUrl ] ) ;
6666
6767 // Set up barcode scanner listener
68+ const isProcessingRef = React . useRef ( false ) ;
6869 React . useEffect ( ( ) => {
6970 if ( CameraView . isModernBarcodeScannerAvailable ) {
7071 const subscription = CameraView . onModernBarcodeScanned ( async ( event ) => {
72+ if ( isProcessingRef . current ) return ;
7173 if ( event . data . startsWith ( 'happy:///account?' ) ) {
72- // Dismiss scanner on Android is called automatically when barcode is scanned
73- if ( Platform . OS === 'ios' ) {
74- await CameraView . dismissScanner ( ) ;
74+ isProcessingRef . current = true ;
75+ try {
76+ if ( Platform . OS === 'ios' ) {
77+ try {
78+ await CameraView . dismissScanner ( ) ;
79+ } catch ( e ) {
80+ console . warn ( 'Failed to dismiss scanner' , e ) ;
81+ }
82+ }
83+ await processAuthUrl ( event . data ) ;
84+ } finally {
85+ isProcessingRef . current = false ;
7586 }
76- await processAuthUrl ( event . data ) ;
7787 }
7888 } ) ;
7989 return ( ) => {
8090 subscription . remove ( ) ;
91+ isProcessingRef . current = false ;
92+ if ( Platform . OS === 'ios' ) {
93+ CameraView . dismissScanner ( ) . catch ( ( e : unknown ) => {
94+ console . warn ( 'Failed to dismiss scanner during cleanup' , e ) ;
95+ } ) ;
96+ }
8197 } ;
8298 }
8399 } , [ processAuthUrl ] ) ;
Original file line number Diff line number Diff line change @@ -70,19 +70,35 @@ export function useConnectTerminal(options?: UseConnectTerminalOptions) {
7070 } , [ processAuthUrl ] ) ;
7171
7272 // Set up barcode scanner listener
73+ const isProcessingRef = React . useRef ( false ) ;
7374 React . useEffect ( ( ) => {
7475 if ( CameraView . isModernBarcodeScannerAvailable ) {
7576 const subscription = CameraView . onModernBarcodeScanned ( async ( event ) => {
77+ if ( isProcessingRef . current ) return ;
7678 if ( event . data . startsWith ( 'happy://terminal?' ) ) {
77- // Dismiss scanner on Android is called automatically when barcode is scanned
78- if ( Platform . OS === 'ios' ) {
79- await CameraView . dismissScanner ( ) ;
79+ isProcessingRef . current = true ;
80+ try {
81+ if ( Platform . OS === 'ios' ) {
82+ try {
83+ await CameraView . dismissScanner ( ) ;
84+ } catch ( e ) {
85+ console . warn ( 'Failed to dismiss scanner' , e ) ;
86+ }
87+ }
88+ await processAuthUrl ( event . data ) ;
89+ } finally {
90+ isProcessingRef . current = false ;
8091 }
81- await processAuthUrl ( event . data ) ;
8292 }
8393 } ) ;
8494 return ( ) => {
8595 subscription . remove ( ) ;
96+ isProcessingRef . current = false ;
97+ if ( Platform . OS === 'ios' ) {
98+ CameraView . dismissScanner ( ) . catch ( ( e : unknown ) => {
99+ console . warn ( 'Failed to dismiss scanner during cleanup' , e ) ;
100+ } ) ;
101+ }
86102 } ;
87103 }
88104 } , [ processAuthUrl ] ) ;
You can’t perform that action at this time.
0 commit comments