Skip to content

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

feat: add db migration progress dialog

thecodrrbd8d9bf642a9
diff --git a/apps/web/src/common/db.js b/apps/web/src/common/db.js
index 930bf18a8..0b735ade6 100644
--- a/apps/web/src/common/db.js
+++ b/apps/web/src/common/db.js
@@ -1,4 +1,6 @@
import { EventSourcePolyfill as EventSource } from "event-source-polyfill";
+import { EVENTS } from "notes-core/common";
+import { TaskManager } from "./task-manager";
/**
* @type {import("notes-core/api").default}
@@ -11,27 +13,42 @@ async function initializeDatabase(persistence) {
db = new Database(new NNStorage(persistence), EventSource, FS);
// if (isTesting()) {
- // db.host({
- // API_HOST: "https://api.notesnook.com",
- // AUTH_HOST: "https://auth.streetwriters.co",
- // SSE_HOST: "https://events.streetwriters.co",
- // });
+ db.host({
+ API_HOST: "https://api.notesnook.com",
+ AUTH_HOST: "https://auth.streetwriters.co",
+ SSE_HOST: "https://events.streetwriters.co",
+ });
// } else {
// db.host({
// API_HOST: "http://localhost:5264",
// AUTH_HOST: "http://localhost:8264",
// SSE_HOST: "http://localhost:7264",
// });
- const base = `http://${process.env.REACT_APP_LOCALHOST}`;
- db.host({
- API_HOST: `${base}:5264`,
- AUTH_HOST: `${base}:8264`,
- SSE_HOST: `${base}:7264`,
- ISSUES_HOST: `${base}:2624`,
- SUBSCRIPTIONS_HOST: `${base}:9264`,
- });
+ // const base = `http://${process.env.REACT_APP_LOCALHOST}`;
+ // db.host({
+ // API_HOST: `${base}:5264`,
+ // AUTH_HOST: `${base}:8264`,
+ // SSE_HOST: `${base}:7264`,
+ // ISSUES_HOST: `${base}:2624`,
+ // SUBSCRIPTIONS_HOST: `${base}:9264`,
+ // });
// }
+ db.eventManager.subscribe(EVENTS.databaseMigrating, async ({ from, to }) => {
+ await TaskManager.startTask({
+ type: "modal",
+ title: `Migrating your database`,
+ subtitle:
+ "Please do not close your browser/app before the migration is done.",
+ action: (task) => {
+ task({ text: `Migrating database from v${from} to v${to}` });
+ return new Promise((resolve) => {
+ db.eventManager.subscribe(EVENTS.databaseMigrated, resolve);
+ });
+ },
+ });
+ });
+
await db.init();
return db;
}