Try to fix 'The database connection is closing' issues

Browsers may rarely randomly close the IndexedDB connection, which would prevent the game from being able to save options or maps anymore until the user restarted the game.

With this commit, the game now listens for the 'onclose' event on the IDBConnection for when the connection is unexpectedly closed - and when the 'onclose' event is raised, clears the cached IndexedDB connection global so that the next call to getDB opens a fresh IndexedDB connection.

I tested this by deleting the IndexedDB database in developer tools (which triggered 'onclose' event) and seemed to work fine
This commit is contained in:
UnknownShadow200 2022-01-26 20:52:50 +11:00
parent 8b986b5ccd
commit 87bcdd1e43

View File

@ -368,6 +368,11 @@ mergeInto(LibraryManager.library, {
req.onsuccess = function() {
db = req.result;
window.IDBFS_db = db;
// browser will sometimes close connection behind the scenes
db.onclose = function(ev) {
console.log('IndexedDB connection closed unexpectedly!');
window.IDBFS_db = null;
}
callback(null, db);
};
req.onerror = function(e) {