mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
web: take automatic backups in background
This commit is contained in:
committed by
Abdullah Atta
parent
759fba06ae
commit
b938c58b67
@@ -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<Error | void>({
|
||||
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) => {
|
||||
|
||||
@@ -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")}...`
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ProgressDialog } from "../dialogs/progress-dialog";
|
||||
import { removeStatus, updateStatus } from "../hooks/use-status";
|
||||
|
||||
type TaskType = "status" | "modal";
|
||||
type TaskAction<T> = (report: ProgressReportCallback) => T | Promise<T>;
|
||||
export type TaskAction<T> = (report: ProgressReportCallback) => T | Promise<T>;
|
||||
type BaseTaskDefinition<TTaskType extends TaskType, TReturnType> = {
|
||||
type: TTaskType;
|
||||
action: TaskAction<TReturnType>;
|
||||
@@ -31,6 +31,7 @@ type StatusTaskDefinition<TReturnType> = BaseTaskDefinition<
|
||||
"status",
|
||||
TReturnType
|
||||
> & {
|
||||
title: string;
|
||||
id: string;
|
||||
};
|
||||
|
||||
@@ -39,7 +40,7 @@ type ModalTaskDefinition<TReturnType> = BaseTaskDefinition<
|
||||
TReturnType
|
||||
> & {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
subtitle?: string;
|
||||
};
|
||||
|
||||
type TaskDefinition<TReturnType> =
|
||||
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -29,7 +29,7 @@ type Progress = {
|
||||
};
|
||||
type ProgressDialogProps<T> = BaseDialogProps<T | Error> & {
|
||||
title: string;
|
||||
subtitle: string;
|
||||
subtitle?: string;
|
||||
action: (report: (progress: Progress) => void) => T;
|
||||
};
|
||||
export const ProgressDialog = DialogManager.register(function ProgressDialog<T>(
|
||||
|
||||
Reference in New Issue
Block a user