File tree Expand file tree Collapse file tree 1 file changed +24
-4
lines changed
Expand file tree Collapse file tree 1 file changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -789,10 +789,30 @@ export class Emulator {
789789 return modifiers ;
790790 }
791791
792- #handleBeforeUnload = ( ) => {
793- // Mostly necessary for the fallback mode, otherwise the page can hang
794- // during reload because the worker is not yielding.
795- this . stop ( ) ;
792+ #handleBeforeUnload = ( event : Event ) => {
793+ // On macOS hosts it's too easy to accidentally close the tab due to
794+ // muscle memory for Command-W, so we'll ask for confirmation if the
795+ // navigation away is due a command+key combination.
796+ if (
797+ navigator . platform . startsWith ( "Mac" ) &&
798+ Array . from ( this . #downKeyCodes) . some ( code => code . startsWith ( "Meta" ) )
799+ ) {
800+ event . preventDefault ( ) ;
801+
802+ // We'll never get a keyup event for the command key, so we'll
803+ // need to synthesize one to avoid the guest ending up with it
804+ // stuck on.
805+ for ( const code of this . #downKeyCodes) {
806+ const adbKeyCode = this . #getAdbKeyCode( code ) ;
807+ if ( adbKeyCode !== undefined ) {
808+ this . #input. handleInput ( {
809+ type : "keyup" ,
810+ keyCode : adbKeyCode ,
811+ } ) ;
812+ }
813+ }
814+ this . #downKeyCodes. clear ( ) ;
815+ }
796816 } ;
797817
798818 #handleWorkerMessage = ( e : MessageEvent ) => {
You can’t perform that action at this time.
0 commit comments