()
| 61 | } |
| 62 | |
| 63 | static async _removeDatabaseIfCorrupt(): Promise<void> { |
| 64 | const databases = await window.indexedDB.databases(); |
| 65 | if ( |
| 66 | !databases.find( |
| 67 | database => database.name === CLOUD_PROJECT_AUTOSAVE_CACHE_KEY |
| 68 | ) |
| 69 | ) { |
| 70 | // The database does not exist so it cannot be corrupt. |
| 71 | return; |
| 72 | } |
| 73 | // Check that the database is not in a corrupt state where the object store does |
| 74 | // not exist. If it does not exist, the autosave feature won't work and the database |
| 75 | // needs to be removed and recreated. |
| 76 | await new Promise((resolve, reject) => { |
| 77 | const request = window.indexedDB.open(CLOUD_PROJECT_AUTOSAVE_CACHE_KEY); |
| 78 | request.onsuccess = event => { |
| 79 | const db = event.target.result; |
| 80 | if (db.objectStoreNames.contains(objectStoreScope)) { |
| 81 | // The object store exists, there is nothing else to do. |
| 82 | resolve(); |
| 83 | } else { |
| 84 | console.warn( |
| 85 | 'The cloud project autosave indexed db exist but the object store is not available. Deleting the indexedDB...' |
| 86 | ); |
| 87 | db.close(); |
| 88 | const req = window.indexedDB.deleteDatabase( |
| 89 | CLOUD_PROJECT_AUTOSAVE_CACHE_KEY |
| 90 | ); |
| 91 | |
| 92 | req.onsuccess = function() { |
| 93 | console.warn('Deleted indexedDB successfully!'); |
| 94 | resolve(); |
| 95 | }; |
| 96 | req.onerror = function(event) { |
| 97 | console.error("Couldn't delete indexedDB: ", event); |
| 98 | reject(); |
| 99 | }; |
| 100 | req.onblocked = function() { |
| 101 | console.error( |
| 102 | "Couldn't delete indexedDB due to the operation being blocked." |
| 103 | ); |
| 104 | reject(); |
| 105 | }; |
| 106 | } |
| 107 | }; |
| 108 | }); |
| 109 | } |
| 110 | |
| 111 | _initializeDatabase(): any { |
| 112 | if (!this.databasePromise) { |
no test coverage detected