fix(electron): export and import (#9767)

This commit is contained in:
forehalo
2025-01-20 08:48:03 +00:00
parent 2e18ae59e3
commit cb53baca89
26 changed files with 332 additions and 453 deletions
@@ -7,6 +7,7 @@ import { DesktopApiService } from '@affine/core/modules/desktop-api';
import { WorkspacePermissionService } from '@affine/core/modules/permissions';
import type { Workspace } from '@affine/core/modules/workspace';
import { useI18n } from '@affine/i18n';
import { universalId } from '@affine/nbstore';
import track from '@affine/track';
import { useLiveData, useService } from '@toeverything/infra';
import { useState } from 'react';
@@ -16,7 +17,6 @@ interface ExportPanelProps {
}
export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
const workspaceId = workspace.id;
const workspacePermissionService = useService(
WorkspacePermissionService
).permission;
@@ -43,7 +43,14 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
await workspace.engine.blob.fullSync();
}
const result = await desktopApi.handler?.dialog.saveDBFileAs(workspaceId);
const result = await desktopApi.handler?.dialog.saveDBFileAs(
universalId({
peer: workspace.flavour,
type: 'workspace',
id: workspace.id,
}),
workspace.name$.getValue() ?? 'db'
);
if (result?.error) {
throw new Error(result.error);
} else if (!result?.canceled) {
@@ -54,7 +61,7 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
} finally {
setSaving(false);
}
}, [desktopApi, isOnline, saving, t, workspace, workspaceId]);
}, [desktopApi, isOnline, saving, t, workspace]);
if (isTeam && !isOwner && !isAdmin) {
return null;
@@ -120,6 +120,7 @@ class CloudWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
id: id,
},
});
// TODO(@forehalo): when deleting cloud workspace, should we delete the workspace folder in local?
this.revalidate();
await this.waitForLoaded();
}
@@ -1,5 +1,9 @@
import { DebugLogger } from '@affine/debug';
import type { BlobStorage, DocStorage } from '@affine/nbstore';
import {
type BlobStorage,
type DocStorage,
universalId,
} from '@affine/nbstore';
import {
IndexedDBBlobStorage,
IndexedDBDocStorage,
@@ -101,11 +105,13 @@ class LocalWorkspaceFlavourProvider implements WorkspaceFlavourProvider {
async deleteWorkspace(id: string): Promise<void> {
setLocalWorkspaceIds(ids => ids.filter(x => x !== id));
// TODO(@forehalo): deleting logic for indexeddb workspaces
if (BUILD_CONFIG.isElectron) {
const electronApi = this.framework.get(DesktopApiService);
await electronApi.handler.workspace.delete(id);
await electronApi.handler.workspace.moveToTrash(
universalId({ peer: 'local', type: 'workspace', id })
);
}
// notify all browser tabs, so they can update their workspace list
this.notifyChannel.postMessage(id);
}