diff --git a/apps/web/src/common/index.ts b/apps/web/src/common/index.ts index 88f80327d..bbdad3349 100644 --- a/apps/web/src/common/index.ts +++ b/apps/web/src/common/index.ts @@ -83,9 +83,10 @@ export async function createBackup( rescueMode?: boolean; noVerify?: boolean; mode?: "full" | "partial"; + background?: boolean; } = { mode: "partial" } ) { - const { rescueMode, noVerify, mode } = options; + const { rescueMode, noVerify, mode, background } = options; const { isLoggedIn } = useUserStore.getState(); const { encryptBackups, toggleEncryptBackups } = useSettingStore.getState(); if (!isLoggedIn && encryptBackups) toggleEncryptBackups(); @@ -115,7 +116,8 @@ export async function createBackup( const encoder = new TextEncoder(); const error = await TaskManager.startTask({ - type: "modal", + type: background ? "status" : "modal", + id: "creating-backup", title: "Creating backup", subtitle: "We are creating a backup of your data. Please wait...", action: async (report) => { diff --git a/apps/web/src/common/multi-select.ts b/apps/web/src/common/multi-select.ts index 3c20e969f..f66ae69c4 100644 --- a/apps/web/src/common/multi-select.ts +++ b/apps/web/src/common/multi-select.ts @@ -46,6 +46,7 @@ async function moveNotesToTrash(ids: string[], confirm = true) { await TaskManager.startTask({ type: "status", id: "deleteNotes", + title: "Deleting notes", action: async (report) => { report({ text: `Deleting ${pluralize(items.length, "note")}...` @@ -66,6 +67,7 @@ async function moveNotebooksToTrash(ids: string[]) { await TaskManager.startTask({ type: "status", id: "deleteNotebooks", + title: "Deleting notebooks", action: async (report) => { report({ text: `Deleting ${pluralize(ids.length, "notebook")}...` @@ -92,6 +94,7 @@ async function deleteAttachments(ids: string[]) { await TaskManager.startTask({ type: "status", id: "deleteAttachments", + title: "Deleting attachments", action: async (report) => { for (let i = 0; i < ids.length; ++i) { const id = ids[i]; @@ -119,6 +122,7 @@ async function moveRemindersToTrash(ids: string[]) { await TaskManager.startTask({ type: "status", id: "deleteReminders", + title: "Deleting reminders", action: async (report) => { report({ text: `Deleting ${pluralize(ids.length, "reminder")}...` diff --git a/apps/web/src/common/notices.ts b/apps/web/src/common/notices.ts index 57e1c2639..4a4d1746a 100644 --- a/apps/web/src/common/notices.ts +++ b/apps/web/src/common/notices.ts @@ -200,7 +200,7 @@ function isIgnored(key: keyof typeof NoticesData) { let openedToast: { hide: () => void } | null = null; async function saveBackup(mode: "full" | "partial" = "partial") { if (IS_DESKTOP_APP) { - await createBackup({ noVerify: true, mode }); + await createBackup({ noVerify: true, mode, background: true }); } else if (isUserPremium() && !IS_TESTING) { if (openedToast !== null) return; openedToast = showToast( diff --git a/apps/web/src/common/task-manager.ts b/apps/web/src/common/task-manager.ts index 87e7627a0..97d504a8d 100644 --- a/apps/web/src/common/task-manager.ts +++ b/apps/web/src/common/task-manager.ts @@ -21,7 +21,7 @@ import { ProgressDialog } from "../dialogs/progress-dialog"; import { removeStatus, updateStatus } from "../hooks/use-status"; type TaskType = "status" | "modal"; -type TaskAction = (report: ProgressReportCallback) => T | Promise; +export type TaskAction = (report: ProgressReportCallback) => T | Promise; type BaseTaskDefinition = { type: TTaskType; action: TaskAction; @@ -31,6 +31,7 @@ type StatusTaskDefinition = BaseTaskDefinition< "status", TReturnType > & { + title: string; id: string; }; @@ -39,7 +40,7 @@ type ModalTaskDefinition = BaseTaskDefinition< TReturnType > & { title: string; - subtitle: string; + subtitle?: string; }; type TaskDefinition = @@ -59,6 +60,10 @@ export class TaskManager { switch (task.type) { case "status": { const statusTask = task; + updateStatus({ + key: statusTask.id, + status: task.title + }); const result = await statusTask.action((progress) => { let percentage: number | undefined = undefined; if (progress.current && progress.total) diff --git a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx index 6b0df6842..52f7a2c13 100644 --- a/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx +++ b/apps/web/src/dialogs/buy-dialog/buy-dialog.tsx @@ -175,12 +175,8 @@ function SideBar(props: SideBarProps) { const result = await TaskManager.startTask({ type: "status", id: "trialActivation", - action: (report) => { - report({ - text: "Activating trial" - }); - return db.user.activateTrial(); - } + title: "Activating trial", + action: () => db.user.activateTrial() }); if (result) onClose(); } catch (e) { diff --git a/apps/web/src/dialogs/onboarding-dialog.tsx b/apps/web/src/dialogs/onboarding-dialog.tsx index 662777e35..0140603ab 100644 --- a/apps/web/src/dialogs/onboarding-dialog.tsx +++ b/apps/web/src/dialogs/onboarding-dialog.tsx @@ -513,12 +513,8 @@ function TrialOffer({ onClose }: { onClose: () => void }) { const result = await TaskManager.startTask({ type: "status", id: "trialActivation", - action: (report) => { - report({ - text: "Activating trial" - }); - return db.user.activateTrial(); - } + title: "Activating trial", + action: () => db.user.activateTrial() }); if (result) onClose(); } catch (e) { diff --git a/apps/web/src/dialogs/progress-dialog.tsx b/apps/web/src/dialogs/progress-dialog.tsx index ee793b95d..7540f622b 100644 --- a/apps/web/src/dialogs/progress-dialog.tsx +++ b/apps/web/src/dialogs/progress-dialog.tsx @@ -29,7 +29,7 @@ type Progress = { }; type ProgressDialogProps = BaseDialogProps & { title: string; - subtitle: string; + subtitle?: string; action: (report: (progress: Progress) => void) => T; }; export const ProgressDialog = DialogManager.register(function ProgressDialog(