@@ -6,7 +6,7 @@ import { ServerConfig } from "../core/configuration/Config";
66import { getServerConfigFromClient } from "../core/configuration/ConfigLoader" ;
77import { UserSettings } from "../core/game/UserSettings" ;
88import "./AccountModal" ;
9- import { joinLobby , shouldPreventUnload } from "./ClientGameRunner" ;
9+ import { joinLobby } from "./ClientGameRunner" ;
1010import { fetchCosmetics } from "./Cosmetics" ;
1111import "./DarkModeButton" ;
1212import { DarkModeButton } from "./DarkModeButton" ;
@@ -80,7 +80,7 @@ export interface JoinLobbyEvent {
8080}
8181
8282class Client {
83- private gameStop : ( ( ) => void ) | null = null ;
83+ private gameStop : ( ( ) => boolean ) | null = null ;
8484 private eventBus : EventBus = new EventBus ( ) ;
8585
8686 private usernameInput : UsernameInput | null = null ;
@@ -154,16 +154,11 @@ class Client {
154154 this . publicLobby = document . querySelector ( "public-lobby" ) as PublicLobby ;
155155
156156 window . addEventListener ( "beforeunload" , ( e ) => {
157- // Check if we should prevent unload (player is alive)
158- if ( shouldPreventUnload ( ) ) {
157+ if ( this . gameStop && ! this . gameStop ( ) ) {
159158 e . preventDefault ( ) ;
160159 return "" ;
161160 }
162- // Otherwise, cleanup the game normally
163161 console . log ( "Browser is closing" ) ;
164- if ( this . gameStop !== null ) {
165- this . gameStop ( ) ;
166- }
167162 } ) ;
168163
169164 document . addEventListener ( "join-lobby" , this . handleJoinLobby . bind ( this ) ) ;
0 commit comments