A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
common: add toolbar migration
Abdullah Attaa003e396b8e1
diff --git a/packages/common/src/utils/index.ts b/packages/common/src/utils/index.tsindex 66300ddc9..bcb1a17e1 100644--- a/packages/common/src/utils/index.ts+++ b/packages/common/src/utils/index.ts@@ -24,3 +24,4 @@ export * from "./debounce";export * from "./random";export * from "./string";export * from "./resolve-items";+export * from "./migrate-toolbar";diff --git a/packages/common/src/utils/migrate-toolbar.ts b/packages/common/src/utils/migrate-toolbar.tsnew file mode 100644index 000000000..4501b63d8--- /dev/null+++ b/packages/common/src/utils/migrate-toolbar.ts@@ -0,0 +1,51 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { ToolbarConfig, ToolbarConfigPlatforms } from "@notesnook/core";+import { database } from "../database";++export const CURRENT_TOOLBAR_VERSION = 1;+export async function migrateToolbar(+ platform: ToolbarConfigPlatforms,+ tools: ToolbarConfig+) {+ const version = tools.version || 0;+ if (version === CURRENT_TOOLBAR_VERSION) return tools;++ tools = runMigration(version, platform, tools);+ await database.settings.setToolbarConfig(platform, tools);+ return tools;+}++function runMigration(+ version: number,+ platform: ToolbarConfigPlatforms,+ tools: ToolbarConfig+) {+ switch (version) {+ case 0: {+ tools.config?.push(["checkList"]);+ return runMigration(1, platform, tools);+ }+ case CURRENT_TOOLBAR_VERSION:+ default:+ break;+ }+ return tools;+}diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex e70390ee0..a9f700f4e 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -410,7 +410,11 @@ export interface SessionContentItem extends BaseItem<"sessioncontent"> {}export type TrashCleanupInterval = 1 | 7 | 30 | 365 | -1;-export type ToolbarConfig = { preset: string; config?: any[] };+export type ToolbarConfig = {+ version: number | undefined;+ preset: string;+ config?: any[];+};export type DefaultNotebook = { id: string; topic?: string };/*** @deprecated only kept here for migration purposes