mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
feat(electron): backup panel (#9738)
fix PD-2071, PD-2059, PD-2069, PD-2068
This commit is contained in:
9
packages/frontend/core/src/modules/backup/index.ts
Normal file
9
packages/frontend/core/src/modules/backup/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { type Framework } from '@toeverything/infra';
|
||||
|
||||
import { DesktopApiService } from '../desktop-api';
|
||||
import { WorkspacesService } from '../workspace';
|
||||
import { BackupService } from './services';
|
||||
|
||||
export function configureDesktopBackupModule(framework: Framework) {
|
||||
framework.service(BackupService, [DesktopApiService, WorkspacesService]);
|
||||
}
|
||||
71
packages/frontend/core/src/modules/backup/services/index.ts
Normal file
71
packages/frontend/core/src/modules/backup/services/index.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import {
|
||||
catchErrorInto,
|
||||
effect,
|
||||
fromPromise,
|
||||
LiveData,
|
||||
onComplete,
|
||||
onStart,
|
||||
Service,
|
||||
} from '@toeverything/infra';
|
||||
import { EMPTY, mergeMap, switchMap } from 'rxjs';
|
||||
|
||||
import type { DesktopApiService } from '../../desktop-api';
|
||||
import type { WorkspacesService } from '../../workspace';
|
||||
import { _addLocalWorkspace } from '../../workspace-engine';
|
||||
|
||||
type BackupWorkspaceResult = Awaited<
|
||||
ReturnType<DesktopApiService['handler']['workspace']['getBackupWorkspaces']>
|
||||
>;
|
||||
|
||||
export class BackupService extends Service {
|
||||
constructor(
|
||||
private readonly desktopApiService: DesktopApiService,
|
||||
private readonly workspacesService: WorkspacesService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
isLoading$ = new LiveData(false);
|
||||
error$ = new LiveData<any>(null);
|
||||
|
||||
pageBackupWorkspaces$ = new LiveData<BackupWorkspaceResult | undefined>(
|
||||
undefined
|
||||
);
|
||||
|
||||
readonly revalidate = effect(
|
||||
switchMap(() =>
|
||||
fromPromise(async () => {
|
||||
return this.desktopApiService.handler.workspace.getBackupWorkspaces();
|
||||
}).pipe(
|
||||
mergeMap(data => {
|
||||
this.pageBackupWorkspaces$.setValue(data);
|
||||
return EMPTY;
|
||||
}),
|
||||
catchErrorInto(this.error$),
|
||||
onStart(() => this.isLoading$.setValue(true)),
|
||||
onComplete(() => this.isLoading$.setValue(false))
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
async recoverBackupWorkspace(dbPath: string) {
|
||||
const result =
|
||||
await this.desktopApiService.handler.dialog.loadDBFile(dbPath);
|
||||
if (result.workspaceId) {
|
||||
_addLocalWorkspace(result.workspaceId);
|
||||
this.workspacesService.list.revalidate();
|
||||
}
|
||||
return result.workspaceId;
|
||||
}
|
||||
|
||||
async deleteBackupWorkspace(backupWorkspaceId: string) {
|
||||
await this.desktopApiService.handler.workspace.deleteBackupWorkspace(
|
||||
backupWorkspaceId
|
||||
);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
override dispose(): void {
|
||||
this.revalidate.unsubscribe();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ export type SettingTab =
|
||||
| 'about'
|
||||
| 'plans'
|
||||
| 'billing'
|
||||
| 'backup' // electron only
|
||||
| 'experimental-features'
|
||||
| 'editor'
|
||||
| 'account'
|
||||
|
||||
Reference in New Issue
Block a user