Skip to content

Commit f6b8680

Browse files
committed
call save every minute when game is launched
1 parent 40339dd commit f6b8680

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Diff for: frontend/js/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ function launch(active_item) {
128128
};
129129
rendermenu(config, 0);
130130
} else if (type == 'game') {
131+
// Disable keyevents and hash watching
132+
window.exit = false;
131133
$(window).off('hashchange');
132134
window.location.href = '#game';
133135
$(document).off('keydown');
136+
// Default variables for emulator
134137
var emulator = $('#i' + active_item.toString()).data('emulator');
135138
var path = $('#i' + active_item.toString()).data('path');
136139
var rom_path = 'user/' + path + '/roms/';
137140
var rom_extension = $('#i' + active_item.toString()).data('rom_extension');
138141
var bios = 'user/' + path + '/bios/' + $('#i' + active_item.toString()).data('bios');
142+
// Clear screen and add game window
139143
$('body').empty();
140144
var gameDiv = $('<div>').attr('id','game');
141145
$('body').append(gameDiv);
@@ -158,9 +162,16 @@ function launch(active_item) {
158162
document.getElementsByClassName('ejs--73f9b4e94a7a1fe74e11107d5ab2ef')[0].click();
159163
}
160164
}, 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);
161171
// Reload window if user clicks back
162172
$(window).on('hashchange', async function() {
163173
if (window.location.hash !== '#game') {
174+
window.exit = true;
164175
window.dispatchEvent(new Event('beforeunload'));
165176
setTimeout(function(){
166177
window.location.href = '#' + root + '---' + active_item;

0 commit comments

Comments
 (0)