@@ -128,14 +128,18 @@ function launch(active_item) {
128
128
} ;
129
129
rendermenu ( config , 0 ) ;
130
130
} else if ( type == 'game' ) {
131
+ // Disable keyevents and hash watching
132
+ window . exit = false ;
131
133
$ ( window ) . off ( 'hashchange' ) ;
132
134
window . location . href = '#game' ;
133
135
$ ( document ) . off ( 'keydown' ) ;
136
+ // Default variables for emulator
134
137
var emulator = $ ( '#i' + active_item . toString ( ) ) . data ( 'emulator' ) ;
135
138
var path = $ ( '#i' + active_item . toString ( ) ) . data ( 'path' ) ;
136
139
var rom_path = 'user/' + path + '/roms/' ;
137
140
var rom_extension = $ ( '#i' + active_item . toString ( ) ) . data ( 'rom_extension' ) ;
138
141
var bios = 'user/' + path + '/bios/' + $ ( '#i' + active_item . toString ( ) ) . data ( 'bios' ) ;
142
+ // Clear screen and add game window
139
143
$ ( 'body' ) . empty ( ) ;
140
144
var gameDiv = $ ( '<div>' ) . attr ( 'id' , 'game' ) ;
141
145
$ ( 'body' ) . append ( gameDiv ) ;
@@ -158,9 +162,16 @@ function launch(active_item) {
158
162
document . getElementsByClassName ( 'ejs--73f9b4e94a7a1fe74e11107d5ab2ef' ) [ 0 ] . click ( ) ;
159
163
}
160
164
} , 100 ) ;
165
+ // Call to save every minute the game is active
166
+ var saveEveryMinute = setInterval ( ( ) => {
167
+ if ( window . exit == false ) {
168
+ window . dispatchEvent ( new Event ( 'beforeunload' ) ) ;
169
+ } ;
170
+ } , 60000 ) ;
161
171
// Reload window if user clicks back
162
172
$ ( window ) . on ( 'hashchange' , async function ( ) {
163
173
if ( window . location . hash !== '#game' ) {
174
+ window . exit = true ;
164
175
window . dispatchEvent ( new Event ( 'beforeunload' ) ) ;
165
176
setTimeout ( function ( ) {
166
177
window . location . href = '#' + root + '---' + active_item ;
0 commit comments