Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: improve sync resilience

thecodrr6aac907ba57e
diff --git a/apps/web/package.json b/apps/web/package.json
index d4ae80494..1179de3bf 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -36,6 +36,7 @@
"localforage-getitems": "https://github.com/thecodrr/localForage-getItems.git",
"nncryptoworker": "file:packages/nncryptoworker",
"notes-core": "npm:@streetwriters/notesnook-core@latest",
+ "page-lifecycle": "^0.1.2",
"platform": "^1.3.6",
"print-js": "^1.6.0",
"qclone": "^1.0.4",
diff --git a/apps/web/src/app-effects.js b/apps/web/src/app-effects.js
index 1cd983b66..e3ab033aa 100644
--- a/apps/web/src/app-effects.js
+++ b/apps/web/src/app-effects.js
@@ -71,7 +71,6 @@ export default function AppEffects({ setShow }) {
await updateLastSynced();
if (await initUser()) {
showUpgradeReminderDialogs();
- await sync();
}
await resetReminders();
setIsVaultCreated(await db.vault.exists());
diff --git a/apps/web/src/components/announcements/body.js b/apps/web/src/components/announcements/body.js
index 5fd019bb6..79fbfc61d 100644
--- a/apps/web/src/components/announcements/body.js
+++ b/apps/web/src/components/announcements/body.js
@@ -202,7 +202,7 @@ function InlineCalltoActions({ item }) {
)
)
.map((action, index) => (
- <CalltoAction action={action} index={index} />
+ <CalltoAction key={action.title} action={action} index={index} />
))}
</Flex>
);
@@ -266,6 +266,7 @@ export function Features({ item }) {
>
{features.map((feature) => (
<Flex
+ key={feature.title}
p={1}
sx={{
borderRadius: "default",
diff --git a/apps/web/src/stores/user-store.js b/apps/web/src/stores/user-store.js
index b7cbbaaac..e5447759f 100644
--- a/apps/web/src/stores/user-store.js
+++ b/apps/web/src/stores/user-store.js
@@ -66,8 +66,8 @@ class UserStore extends BaseStore {
hashNavigate("/confirmed");
});
- EV.subscribe(EVENTS.databaseSyncRequested, async () => {
- await appStore.sync(false);
+ EV.subscribe(EVENTS.databaseSyncRequested, async (full, force) => {
+ await appStore.sync(full, force);
});
EV.subscribe(EVENTS.userLoggedOut, async (reason) => {
@@ -83,9 +83,9 @@ class UserStore extends BaseStore {
}
});
- onPageVisibilityChanged(async (documentHidden) => {
+ onPageVisibilityChanged(async function (type, documentHidden) {
if (!documentHidden) {
- await db.connectSSE();
+ await db.connectSSE({ force: type === "online" });
}
});
diff --git a/apps/web/src/utils/page-visibility.js b/apps/web/src/utils/page-visibility.js
index d25831941..82a2a160d 100644
--- a/apps/web/src/utils/page-visibility.js
+++ b/apps/web/src/utils/page-visibility.js
@@ -11,15 +11,17 @@ if (typeof document.hidden !== "undefined") {
visibilityChange = "webkitvisibilitychange";
}
-// // If the page is hidden, pause the video;
-// // if the page is shown, play the video
-// function handleVisibilityChange() {
-// if (document[hidden]) {
-// } else {
-// }
-// }
-
export function onPageVisibilityChanged(handler) {
+ onDeviceOnline(() => handler("online", false));
+
// Handle page visibility change
- document.addEventListener(visibilityChange, () => handler(document[hidden]));
+ document.addEventListener(visibilityChange, () =>
+ handler("visibilitychange", document[hidden])
+ );
+}
+
+function onDeviceOnline(handler) {
+ window.addEventListener("online", function () {
+ handler && handler();
+ });
}