@@ -38,41 +38,43 @@ export function DeviceWorkspace(props: {
3838 downloadRef . current = null ;
3939 } ;
4040 } , [ access , props . visible ] ) ;
41- const saveScreenshot = async ( ) => {
41+ const saveScreenshot = ( ) => {
4242 if ( ! access || captureRef . current || ! props . visible ) return ;
4343 const controller = new AbortController ( ) ;
4444 captureRef . current = controller ;
4545 setScreenshotPending ( true ) ;
4646 setScreenshotError ( null ) ;
47- try {
48- const image = await captureDeviceScreenshot (
49- { access, platform : props . device . platform , deviceId : props . device . id } ,
50- controller . signal ,
51- ) ;
52- if ( controller . signal . aborted ) return ;
53- if ( downloadRef . current ) URL . revokeObjectURL ( downloadRef . current ) ;
54- const url = URL . createObjectURL ( image ) ;
55- downloadRef . current = url ;
56- const link = document . createElement ( "a" ) ;
57- link . href = url ;
58- link . download = `${ props . device . name . replace ( / [ ^ a - z 0 - 9 - ] / gi, "-" ) } -${ Date . now ( ) } .png` ;
59- document . body . append ( link ) ;
60- link . click ( ) ;
61- link . remove ( ) ;
62- } catch ( cause ) {
63- if ( ! controller . signal . aborted ) {
64- if ( cause instanceof DeviceScreenshotError && cause . status === 401 )
65- refreshDeviceHubAccess ( props . environmentId ) ;
66- setScreenshotError (
67- cause instanceof Error ? cause . message : "Screenshot capture failed. Try again." ,
68- ) ;
69- }
70- } finally {
71- if ( captureRef . current === controller ) {
72- captureRef . current = null ;
73- setScreenshotPending ( false ) ;
74- }
75- }
47+ return captureDeviceScreenshot (
48+ { access, platform : props . device . platform , deviceId : props . device . id } ,
49+ controller . signal ,
50+ )
51+ . then ( ( image ) => {
52+ if ( controller . signal . aborted ) return ;
53+ if ( downloadRef . current ) URL . revokeObjectURL ( downloadRef . current ) ;
54+ const url = URL . createObjectURL ( image ) ;
55+ downloadRef . current = url ;
56+ const link = document . createElement ( "a" ) ;
57+ link . href = url ;
58+ link . download = `${ props . device . name . replace ( / [ ^ a - z 0 - 9 - ] / gi, "-" ) } -${ Date . now ( ) } .png` ;
59+ document . body . append ( link ) ;
60+ link . click ( ) ;
61+ link . remove ( ) ;
62+ } )
63+ . catch ( ( cause : unknown ) => {
64+ if ( ! controller . signal . aborted ) {
65+ if ( cause instanceof DeviceScreenshotError && cause . status === 401 )
66+ refreshDeviceHubAccess ( props . environmentId ) ;
67+ setScreenshotError (
68+ cause instanceof Error ? cause . message : "Screenshot capture failed. Try again." ,
69+ ) ;
70+ }
71+ } )
72+ . finally ( ( ) => {
73+ if ( captureRef . current === controller ) {
74+ captureRef . current = null ;
75+ setScreenshotPending ( false ) ;
76+ }
77+ } ) ;
7678 } ;
7779 return (
7880 < >
0 commit comments