Skip to content

Commit

Permalink
fix refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
aeharding committed Jan 28, 2025
1 parent a7fbfd1 commit 725c8ef
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/core/listeners/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { isAppleDeviceInstallable, isNative } from "#/helpers/device";
* https://github.com/ionic-team/cordova-plugin-ionic-webview/issues/354#issuecomment-1305878417
*/
if (isNative() && isAppleDeviceInstallable()) {
const dbLastClosed = +(localStorage.getItem("db-closed") || 0);
const thirtySecondsAgo = Date.now() - 30_000;
App.addListener("appStateChange", async (state) => {
const dbLastClosed = +(localStorage.getItem("db-closed") || 0);
const thirtySecondsAgo = Date.now() - 30_000;

const reloadedRecently = dbLastClosed > thirtySecondsAgo;
const reloadedRecently = dbLastClosed > thirtySecondsAgo;

App.addListener("appStateChange", async (state) => {
if (!state.isActive) return;
if (reloadedRecently) return;

Expand All @@ -23,13 +23,10 @@ if (isNative() && isAppleDeviceInstallable()) {
await Dexie.exists("WefwefDB");
} catch (error) {
console.info("Failed database integrity check!", error);
if (
error instanceof Error &&
error.name === Dexie.errnames.DatabaseClosed
) {
localStorage.setItem("db-closed", Date.now().toString());
window.location.reload();
}

localStorage.setItem("db-closed", Date.now().toString());

window.location.reload();

throw error;
}
Expand Down

0 comments on commit 725c8ef

Please sign in to comment.