Close db on version change
This commit is contained in:
@@ -24,6 +24,9 @@ class DBManager {
|
|||||||
|
|
||||||
request.onsuccess = (event) => {
|
request.onsuccess = (event) => {
|
||||||
var db = event.target.result;
|
var db = event.target.result;
|
||||||
|
db.onversionchange = function(event) {
|
||||||
|
db.close();
|
||||||
|
};
|
||||||
db.onerror = function(errorEvent) {
|
db.onerror = function(errorEvent) {
|
||||||
console.log("Database error: " + errorEvent.target.errorCode);
|
console.log("Database error: " + errorEvent.target.errorCode);
|
||||||
}
|
}
|
||||||
@@ -130,14 +133,16 @@ class DBManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clearAllItems(callback) {
|
clearAllItems(callback) {
|
||||||
this.openDatabase((db) => {
|
var deleteRequest = window.indexedDB.deleteDatabase("standardnotes");
|
||||||
var request = db.transaction("items", "readwrite").objectStore("items").clear();
|
|
||||||
request.onsuccess = function(event) {
|
deleteRequest.onerror = function(event) {
|
||||||
db.close();
|
console.log("Error deleting database.");
|
||||||
window.indexedDB.deleteDatabase("standardnotes");
|
callback();
|
||||||
callback();
|
};
|
||||||
};
|
deleteRequest.onsuccess = function(event) {
|
||||||
}, null)
|
console.log("Database deleted successfully");
|
||||||
|
callback();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,9 @@ class AccountMenu {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
dbManager.clearAllItems(function(){
|
dbManager.clearAllItems(function(){
|
||||||
block();
|
$timeout(function(){
|
||||||
|
block();
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
class SyncManager {
|
class SyncManager {
|
||||||
|
|
||||||
constructor($rootScope, modelManager, authManager, dbManager, httpManager, $interval) {
|
constructor($rootScope, modelManager, authManager, dbManager, httpManager, $interval, $timeout) {
|
||||||
this.$rootScope = $rootScope;
|
this.$rootScope = $rootScope;
|
||||||
this.httpManager = httpManager;
|
this.httpManager = httpManager;
|
||||||
this.modelManager = modelManager;
|
this.modelManager = modelManager;
|
||||||
this.authManager = authManager;
|
this.authManager = authManager;
|
||||||
this.dbManager = dbManager;
|
this.dbManager = dbManager;
|
||||||
this.$interval = $interval;
|
this.$interval = $interval;
|
||||||
|
this.$timeout = $timeout;
|
||||||
this.syncStatus = {};
|
this.syncStatus = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,9 +328,11 @@ class SyncManager {
|
|||||||
this.dbManager.clearAllItems(function(){
|
this.dbManager.clearAllItems(function(){
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
if(callback) {
|
if(callback) {
|
||||||
callback();
|
this.$timeout(function(){
|
||||||
|
callback();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
}.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user