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
global: various minor behavioral changes
Abdullah Attaf24b22818ced
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsxindex 54cd511d2..50638478d 100644--- a/apps/mobile/app/screens/settings/settings-data.tsx+++ b/apps/mobile/app/screens/settings/settings-data.tsx@@ -22,7 +22,8 @@ import {SubscriptionPlan,SubscriptionProvider,SubscriptionStatus,- User+ User,+ formatDate} from "@notesnook/core";import { strings } from "@notesnook/intl";import notifee from "@notifee/react-native";@@ -85,6 +86,13 @@ import { SettingSection } from "./types";import { getTimeLeft } from "./user-section";import { useShallow } from "zustand/react/shallow";+const formatBackupDate = (date: number) =>+ formatDate(date, {+ type: "date-time",+ dateFormat: db.settings.getDateFormat(),+ timeFormat: db.settings.getTimeFormat()+ });+export function getSettingsGroups(): SettingSection[] {return [{@@ -1418,15 +1426,16 @@ export function getSettingsGroups(): SettingSection[] {{id: "backup-now",name: strings.backupNow(),- property: "lastBackupDate",- description: () => {- const last = SettingsService.get().lastBackupDate;- return last- ? `${strings.backupNowDesc()}\n${strings.lastBackupOn(- dayjs(last).format("MMM D, YYYY [at] h:mm A")- )}`- : strings.backupNowDesc();- },+ property: "lastBackupDate",+ description: () => {+ const last = SettingsService.get().lastBackupDate;+ return `${strings.backupNowDesc()}\n${strings.lastBackupOn(+ typeof last === "number" && last+ ? formatBackupDate(last)+ : strings.never(),+ "partial"+ )}`;+ },modifer: async () => {const user = useUserStore.getState().user;if (!user || SettingsService.getProperty("encryptedBackup")) {@@ -1440,15 +1449,16 @@ export function getSettingsGroups(): SettingSection[] {{id: "backup-now-with-attachments",name: strings.backupNowWithAttachments(),- property: "lastFullBackupDate",- description: () => {- const last = SettingsService.get().lastFullBackupDate;- return last- ? `${strings.backupNowWithAttachmentsDesc()}\n${strings.lastBackupOn(- dayjs(last).format("MMM D, YYYY [at] h:mm A")- )}`- : strings.backupNowWithAttachmentsDesc();- },+ property: "lastFullBackupDate",+ description: () => {+ const last = SettingsService.get().lastFullBackupDate;+ return `${strings.backupNowWithAttachmentsDesc()}\n${strings.lastBackupOn(+ typeof last === "number" && last+ ? formatBackupDate(last)+ : strings.never(),+ "full"+ )}`;+ },hidden: () => !useUserStore.getState().user,modifer: async () => {const user = useUserStore.getState().user;@@ -1466,24 +1476,25 @@ export function getSettingsGroups(): SettingSection[] {id: "auto-backups",type: "component",name: strings.automaticBackups(),- useHook: () =>- useSettingStore(- useShallow((state) => [- state.settings.reminder,- state.settings.lastBackupDate- ])- ),- description: () => {- const next = BackupService.getNextBackupTime(- SettingsService.get().reminder,- "lastBackupDate"- );- return next- ? `${strings.automaticBackupsDesc()}\n${strings.nextBackupOn(- dayjs(next).format("MMM D, YYYY [at] h:mm A")- )}`- : strings.automaticBackupsDesc();- },+ useHook: () =>+ useSettingStore(+ useShallow((state) => [+ state.settings.reminder,+ state.settings.lastBackupDate+ ])+ ),+ description: () => {+ const next = BackupService.getNextBackupTime(+ SettingsService.get().reminder,+ "lastBackupDate"+ );+ return next+ ? `${strings.automaticBackupsDesc()}\n${strings.nextBackupOn(+ formatBackupDate(next),+ "partial"+ )}`+ : strings.automaticBackupsDesc();+ },component: "autobackups"},{@@ -1491,27 +1502,28 @@ export function getSettingsGroups(): SettingSection[] {type: "component",hidden: () => !useUserStore.getState().user,name: strings.automaticBackupsWithAttachments(),- useHook: () =>- useSettingStore(- useShallow((state) => [- state.settings.fullBackupReminder,- state.settings.lastFullBackupDate- ])- ),- description: () => {- const next = BackupService.getNextBackupTime(- SettingsService.get().fullBackupReminder,- "lastFullBackupDate"- );- const base = [- ...strings.automaticBackupsWithAttachmentsDesc()- ].join("\n");- return next- ? `${base}\n${strings.nextBackupOn(- dayjs(next).format("MMM D, YYYY [at] h:mm A")- )}`- : base;- },+ useHook: () =>+ useSettingStore(+ useShallow((state) => [+ state.settings.fullBackupReminder,+ state.settings.lastFullBackupDate+ ])+ ),+ description: () => {+ const next = BackupService.getNextBackupTime(+ SettingsService.get().fullBackupReminder,+ "lastFullBackupDate"+ );+ const base = [+ ...strings.automaticBackupsWithAttachmentsDesc()+ ].join("\n");+ return next+ ? `${base}\n${strings.nextBackupOn(+ formatBackupDate(next),+ "full"+ )}`+ : base;+ },component: "autobackupsattachments"},{diff --git a/apps/mobile/app/services/backup.ts b/apps/mobile/app/services/backup.tsindex d2221adf9..c818d50c5 100644--- a/apps/mobile/app/services/backup.ts+++ b/apps/mobile/app/services/backup.ts@@ -168,11 +168,12 @@ function getNextBackupTime(if (type === "off" || type === "useroff" || type === "never" || !type) return;const lastBackupDate = SettingsService.getProperty(lastBackupDateType) as| number+ | "never"| undefined;- if (!lastBackupDate) return;+ if (typeof lastBackupDate !== "number" || !lastBackupDate) return;const interval =type === "daily" ? MS_DAY : type === "weekly" ? MS_WEEK : MONTH;- return lastBackupDate + interval;+ return Math.max(Date.now(), lastBackupDate + interval);}let backupRunning = false;diff --git a/apps/web/src/common/notices.ts b/apps/web/src/common/notices.tsindex 53da628ee..59257f51c 100644--- a/apps/web/src/common/notices.ts+++ b/apps/web/src/common/notices.ts@@ -21,6 +21,7 @@ import Config from "../utils/config";import { createBackup, verifyAccount } from "./index";import { db } from "./db";import { store as appStore } from "../stores/app-store";+import { useStore as useSettingStore } from "../stores/setting-store";import { Backup, User, Email, Warn, Icon } from "../components/icons";import dayjs from "dayjs";import { hardNavigate, hashNavigate } from "../navigation";@@ -99,6 +100,7 @@ export async function shouldAddBackupNotice() {const lastBackupTime = await db.backup.lastBackupTime();if (!lastBackupTime) {await db.backup.updateBackupTime("partial");+ await useSettingStore.getState().refreshBackupTime();return false;}@@ -211,6 +213,7 @@ async function saveBackup(mode: "full" | "partial" = "partial") {text: strings.later(),onClick: async () => {await db.backup.updateBackupTime(mode);+ await useSettingStore.getState().refreshBackupTime();openedToast?.hide();openedToast = null;},diff --git a/apps/web/src/dialogs/settings/backup-export-settings.ts b/apps/web/src/dialogs/settings/backup-export-settings.tsindex cd7559f3b..4bdc68c1c 100644--- a/apps/web/src/dialogs/settings/backup-export-settings.ts+++ b/apps/web/src/dialogs/settings/backup-export-settings.ts@@ -27,25 +27,31 @@ import { useStore as useAppStore } from "../../stores/app-store";import { useStore as useUserStore } from "../../stores/user-store";import { desktop } from "../../common/desktop-bridge";import { formatDate } from "@notesnook/core";-import { BACKUP_CRON_EXPRESSIONS, FULL_BACKUP_CRON_EXPRESSIONS } from "../../common/notices";+import {+ BACKUP_CRON_EXPRESSIONS,+ FULL_BACKUP_CRON_EXPRESSIONS+} from "../../common/notices";import { CronosExpression } from "cronosjs";-import dayjs from "dayjs";function getNextBackupTime(offset: number,- lastBackupDate?: number,- isFull: boolean = false+ type: "full" | "partial"): number | undefined {- if (offset === 0 || !lastBackupDate) return undefined;+ if (offset === 0) return undefined;try {- const cronString = isFull- ? FULL_BACKUP_CRON_EXPRESSIONS[offset as keyof typeof FULL_BACKUP_CRON_EXPRESSIONS]- : BACKUP_CRON_EXPRESSIONS[offset as keyof typeof BACKUP_CRON_EXPRESSIONS];+ const cronString =+ type === "full"+ ? FULL_BACKUP_CRON_EXPRESSIONS[+ offset as keyof typeof FULL_BACKUP_CRON_EXPRESSIONS+ ]+ : BACKUP_CRON_EXPRESSIONS[+ offset as keyof typeof BACKUP_CRON_EXPRESSIONS+ ];if (!cronString) return undefined;const expr = CronosExpression.parse(cronString);- const nextDate = expr.nextDate(new Date(lastBackupDate));+ const nextDate = expr.nextDate(new Date());return nextDate ? nextDate.getTime() : undefined;} catch (e) {return undefined;@@ -66,15 +72,24 @@ export const BackupExportSettings: SettingsGroup[] = [title: strings.backupNow(),description: () => {const s = useSettingStore.getState();- const partial = s.lastBackupTime || 0;- const full = s.lastFullBackupTime || 0;- const last = Math.max(partial, full);-- if (!last) return strings.backupNowDesc();-- const formattedDate = formatDate(last, { type: "date-time", dateFormat: s.dateFormat, timeFormat: s.timeFormat });- const backupStr = last === full ? strings.lastFullBackupOn(formattedDate) : strings.lastPartialBackupOn(formattedDate);- return `${strings.backupNowDesc()}\n${backupStr}`;+ const formattedFullBackupTime = s.lastFullBackupTime+ ? formatDate(s.lastFullBackupTime, {+ type: "date-time",+ dateFormat: s.dateFormat,+ timeFormat: s.timeFormat+ })+ : strings.never();+ const formattedPartialBackupTime = s.lastBackupTime+ ? formatDate(s.lastBackupTime, {+ type: "date-time",+ dateFormat: s.dateFormat,+ timeFormat: s.timeFormat+ })+ : strings.never();+ return `${strings.backupNowDesc()}\n${strings.lastBackupOn(+ formattedFullBackupTime,+ "full"+ )}\n${strings.lastBackupOn(formattedPartialBackupTime, "partial")}`;},onStateChange: (listener) =>useSettingStore.subscribe(@@ -121,18 +136,15 @@ export const BackupExportSettings: SettingsGroup[] = [title: strings.automaticBackups(),description: () => {const s = useSettingStore.getState();- const next = getNextBackupTime(- s.backupReminderOffset,- s.lastBackupTime,- false- );+ const next = getNextBackupTime(s.backupReminderOffset, "partial");return next? `${strings.automaticBackupsDesc()}\n${strings.nextBackupOn(formatDate(next, {type: "date-time",dateFormat: s.dateFormat,timeFormat: s.timeFormat- })+ }),+ "partial")}`: strings.automaticBackupsDesc();},@@ -169,11 +181,7 @@ export const BackupExportSettings: SettingsGroup[] = [title: strings.automaticBackupsWithAttachments(),description: () => {const s = useSettingStore.getState();- const next = getNextBackupTime(- s.fullBackupReminderOffset,- s.lastFullBackupTime,- true- );+ const next = getNextBackupTime(s.fullBackupReminderOffset, "full");const base = strings.automaticBackupsWithAttachmentsDesc().join("\n\n");@@ -183,7 +191,8 @@ export const BackupExportSettings: SettingsGroup[] = [type: "date-time",dateFormat: s.dateFormat,timeFormat: s.timeFormat- })+ }),+ "full")}`: base;},diff --git a/packages/core/src/database/backup.ts b/packages/core/src/database/backup.tsindex 11f76c46f..17c5ef062 100644--- a/packages/core/src/database/backup.ts+++ b/packages/core/src/database/backup.ts@@ -141,6 +141,7 @@ const invalidKeys = ["t","v","lastBackupTime",+ "lastFullBackupTime","lastSynced",// all indexes"notes",@@ -196,11 +197,10 @@ export default class Backup {}async updateBackupTime(mode: "full" | "partial" = "partial") {- if (mode === "full") {- await this.db.kv().write("lastFullBackupTime", Date.now());- } else {- await this.db.kv().write("lastBackupTime", Date.now());- }+ const now = Date.now();+ // a full backup is a superset of a partial one+ await this.db.kv().write("lastBackupTime", now);+ if (mode === "full") await this.db.kv().write("lastFullBackupTime", now);}/**diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.poindex 93cf2bb5e..f0c0b5def 100644--- a/packages/intl/locale/en.po+++ b/packages/intl/locale/en.po@@ -4509,22 +4509,18 @@ msgstr "Languages"msgid "Last"msgstr "Last"-#: src/strings.ts:3278-msgid "Last backup: {date}"-msgstr "Last backup: {date}"--#: src/strings.ts:3281-msgid "Last backup: {date} (Full)"-msgstr "Last backup: {date} (Full)"--#: src/strings.ts:3280-msgid "Last backup: {date} (Partial)"-msgstr "Last backup: {date} (Partial)"-#: src/strings.ts:2029msgid "Last edited at"msgstr "Last edited at"+#: src/strings.ts:3284+msgid "Last full backup: {date}"+msgstr "Last full backup: {date}"++#: src/strings.ts:3285+msgid "Last partial backup: {date}"+msgstr "Last partial backup: {date}"+#: src/strings.ts:2469msgid "Last used on"msgstr "Last used on"@@ -5193,9 +5189,9 @@ msgstr "Newly created notes will be uncategorized"msgid "Next"msgstr "Next"-#: src/strings.ts:3279-msgid "Next backup: {date}"-msgstr "Next backup: {date}"+#: src/strings.ts:3280+msgid "Next full backup: {date}"+msgstr "Next full backup: {date}"#: src/strings.ts:2174msgid "Next match"@@ -5205,6 +5201,10 @@ msgstr "Next match"msgid "Next month"msgstr "Next month"+#: src/strings.ts:3281+msgid "Next partial backup: {date}"+msgstr "Next partial backup: {date}"+#: src/strings.ts:2220msgid "Next tab"msgstr "Next tab"diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.poindex 827b52ad3..ccea34045 100644--- a/packages/intl/locale/pseudo-LOCALE.po+++ b/packages/intl/locale/pseudo-LOCALE.po@@ -4509,22 +4509,18 @@ msgstr "Languages"msgid "Last"msgstr "Last"-#: src/strings.ts:3278-msgid "Last backup: {date}"-msgstr ""+#: src/strings.ts:2029+msgid "Last edited at"+msgstr "Last edited at"-#: src/strings.ts:3281-msgid "Last backup: {date} (Full)"+#: src/strings.ts:3284+msgid "Last full backup: {date}"msgstr ""-#: src/strings.ts:3280-msgid "Last backup: {date} (Partial)"+#: src/strings.ts:3285+msgid "Last partial backup: {date}"msgstr ""-#: src/strings.ts:2029-msgid "Last edited at"-msgstr "Last edited at"-#: src/strings.ts:2469msgid "Last used on"msgstr "Last used on"@@ -5193,8 +5189,8 @@ msgstr "Newly created notes will be uncategorized"msgid "Next"msgstr "Next"-#: src/strings.ts:3279-msgid "Next backup: {date}"+#: src/strings.ts:3280+msgid "Next full backup: {date}"msgstr ""#: src/strings.ts:2174@@ -5205,6 +5201,10 @@ msgstr "Next match"msgid "Next month"msgstr ""+#: src/strings.ts:3281+msgid "Next partial backup: {date}"+msgstr ""+#: src/strings.ts:2220msgid "Next tab"msgstr "Next tab"diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.tsindex d1d29881b..79fb817a9 100644--- a/packages/intl/src/strings.ts+++ b/packages/intl/src/strings.ts@@ -3275,8 +3275,12 @@ Continue without attachments?`,t`Please wait for the previous download to finish or cancel it.`,checkingAttachmentsProgress: (current: number, total: number) =>t`Checking attachments (${current}/${total})`,- lastBackupOn: (date: string) => t`Last backup: ${date}`,- nextBackupOn: (date: string) => t`Next backup: ${date}`,- lastPartialBackupOn: (date: string) => t`Last backup: ${date} (Partial)`,- lastFullBackupOn: (date: string) => t`Last backup: ${date} (Full)`+ nextBackupOn: (date: string, type: "full" | "partial") =>+ type === "full"+ ? t`Next full backup: ${date}`+ : t`Next partial backup: ${date}`,+ lastBackupOn: (date: string, type: "full" | "partial") =>+ type === "full"+ ? t`Last full backup: ${date}`+ : t`Last partial backup: ${date}`};