diff --git a/packages/common/infra/src/modules/workspace/index.ts b/packages/common/infra/src/modules/workspace/index.ts index ee707e8a0e..74ed0a81b7 100644 --- a/packages/common/infra/src/modules/workspace/index.ts +++ b/packages/common/infra/src/modules/workspace/index.ts @@ -66,6 +66,7 @@ export function configureWorkspaceModule(framework: Framework) { .service(WorkspaceRepositoryService, [ [WorkspaceFlavourProvider], WorkspaceProfileService, + WorkspaceListService, ]) .scope(WorkspaceScope) .service(WorkspaceService) diff --git a/packages/common/infra/src/modules/workspace/services/repo.ts b/packages/common/infra/src/modules/workspace/services/repo.ts index a38652f079..e404745390 100644 --- a/packages/common/infra/src/modules/workspace/services/repo.ts +++ b/packages/common/infra/src/modules/workspace/services/repo.ts @@ -11,6 +11,7 @@ import type { WorkspaceFlavourProvider, } from '../providers/flavour'; import { WorkspaceScope } from '../scopes/workspace'; +import type { WorkspaceListService } from './list'; import type { WorkspaceProfileService } from './profile'; import { WorkspaceService } from './workspace'; @@ -19,7 +20,8 @@ const logger = new DebugLogger('affine:workspace-repository'); export class WorkspaceRepositoryService extends Service { constructor( private readonly providers: WorkspaceFlavourProvider[], - private readonly profileRepo: WorkspaceProfileService + private readonly profileRepo: WorkspaceProfileService, + private readonly workspacesListService: WorkspaceListService ) { super(); } @@ -77,6 +79,12 @@ export class WorkspaceRepositoryService extends Service { }; }; + openByWorkspaceId = (workspaceId: string) => { + const workspaceMetadata = + this.workspacesListService.list.workspace$(workspaceId).value; + return workspaceMetadata && this.open({ metadata: workspaceMetadata }); + }; + instantiate( openOptions: WorkspaceOpenOptions, customProvider?: WorkspaceEngineProvider diff --git a/packages/common/infra/src/modules/workspace/services/workspaces.ts b/packages/common/infra/src/modules/workspace/services/workspaces.ts index 56cf35cc1f..625b2fc9d0 100644 --- a/packages/common/infra/src/modules/workspace/services/workspaces.ts +++ b/packages/common/infra/src/modules/workspace/services/workspaces.ts @@ -41,6 +41,10 @@ export class WorkspacesService extends Service { return this.workspaceRepo.open; } + get openByWorkspaceId() { + return this.workspaceRepo.openByWorkspaceId; + } + get create() { return this.workspaceFactory.create; } diff --git a/packages/frontend/apps/electron/renderer/app.tsx b/packages/frontend/apps/electron/renderer/app.tsx index 75a5d3d061..99a9efca34 100644 --- a/packages/frontend/apps/electron/renderer/app.tsx +++ b/packages/frontend/apps/electron/renderer/app.tsx @@ -137,12 +137,9 @@ events?.applicationMenu.onNewPageAction(() => { .get(GlobalContextService) .globalContext.workspaceId.get(); const workspacesService = frameworkProvider.get(WorkspacesService); - const workspaceMetadata = currentWorkspaceId - ? workspacesService.list.workspace$(currentWorkspaceId).value + const workspaceRef = currentWorkspaceId + ? workspacesService.openByWorkspaceId(currentWorkspaceId) : null; - const workspaceRef = - workspaceMetadata && - workspacesService.open({ metadata: workspaceMetadata }); if (!workspaceRef) { return; } diff --git a/packages/frontend/apps/ios/App/Podfile.lock b/packages/frontend/apps/ios/App/Podfile.lock index 21f407e744..3117ca8896 100644 --- a/packages/frontend/apps/ios/App/Podfile.lock +++ b/packages/frontend/apps/ios/App/Podfile.lock @@ -44,4 +44,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 1b0d3fe81862c0e9ce712ddd0c5a0accd0097698 -COCOAPODS: 1.16.2 +COCOAPODS: 1.15.2 diff --git a/packages/frontend/apps/ios/capacitor.config.ts b/packages/frontend/apps/ios/capacitor.config.ts index 8712cc2f95..916df9c225 100644 --- a/packages/frontend/apps/ios/capacitor.config.ts +++ b/packages/frontend/apps/ios/capacitor.config.ts @@ -9,7 +9,7 @@ const config: CapacitorConfig = { path: '.', }, server: { - // url: 'http://localhost:8080', + url: 'http://localhost:8080', }, plugins: { CapacitorCookies: { diff --git a/packages/frontend/apps/ios/src/app.tsx b/packages/frontend/apps/ios/src/app.tsx index 47863507ca..009625bafb 100644 --- a/packages/frontend/apps/ios/src/app.tsx +++ b/packages/frontend/apps/ios/src/app.tsx @@ -19,13 +19,22 @@ import { configureBrowserWorkspaceFlavours, configureIndexedDBWorkspaceEngineStorageProvider, } from '@affine/core/modules/workspace-engine'; +import { + docLinkBaseURLMiddleware, + MarkdownAdapter, + titleMiddleware, +} from '@blocksuite/affine/blocks'; +import { Job } from '@blocksuite/affine/store'; import { App as CapacitorApp } from '@capacitor/app'; import { Browser } from '@capacitor/browser'; import { + DocsService, Framework, FrameworkRoot, getCurrentStore, + GlobalContextService, LifecycleService, + WorkspacesService, } from '@toeverything/infra'; import { Suspense } from 'react'; import { RouterProvider } from 'react-router-dom'; @@ -86,8 +95,55 @@ framework.impl(AIButtonProvider, { return Intelligents.dismissIntelligentsButton(); }, }); + const frameworkProvider = framework.provider(); +(window as any).getCurrentDocContentInMarkdown = async () => { + const globalContextService = frameworkProvider.get(GlobalContextService); + const currentWorkspaceId = + globalContextService.globalContext.workspaceId.get(); + const currentDocId = globalContextService.globalContext.docId.get(); + const workspacesService = frameworkProvider.get(WorkspacesService); + const workspaceRef = currentWorkspaceId + ? workspacesService.openByWorkspaceId(currentWorkspaceId) + : null; + if (!workspaceRef) { + return; + } + const { workspace, dispose: disposeWorkspace } = workspaceRef; + + const docsService = workspace.scope.get(DocsService); + const docRef = currentDocId ? docsService.open(currentDocId) : null; + if (!docRef) { + return; + } + const { doc, release: disposeDoc } = docRef; + + try { + const blockSuiteDoc = doc.blockSuiteDoc; + + const job = new Job({ + collection: blockSuiteDoc.collection, + middlewares: [docLinkBaseURLMiddleware, titleMiddleware], + }); + const snapshot = await job.docToSnapshot(blockSuiteDoc); + + const adapter = new MarkdownAdapter(job); + if (!snapshot) { + return; + } + + const markdownResult = await adapter.fromDocSnapshot({ + snapshot, + assets: job.assetsManager, + }); + return markdownResult.file; + } finally { + disposeDoc(); + disposeWorkspace(); + } +}; + // setup application lifecycle events, and emit application start event window.addEventListener('focus', () => { frameworkProvider.get(LifecycleService).applicationFocus();