refactor(editor): add native clipboard extension (#9502)

Closes: [BS-2239](https://linear.app/affine-design/issue/BS-2239/不应该通过window注入affine的api)
This commit is contained in:
fundon
2025-01-06 15:36:43 +00:00
parent f778d1a28a
commit 69e73af2a8
9 changed files with 117 additions and 36 deletions

View File

@@ -55,6 +55,7 @@ import {
patchEdgelessClipboard,
patchEmbedLinkedDocBlockConfig,
patchForAttachmentEmbedViews,
patchForClipboardInElectron,
patchForMobile,
patchForSharedPage,
patchGenerateDocUrlExtension,
@@ -170,6 +171,9 @@ const usePatchSpecs = (shared: boolean, mode: DocMode) => {
if (BUILD_CONFIG.isMobileEdition) {
patched = patched.concat(patchForMobile());
}
if (BUILD_CONFIG.isElectron) {
patched = patched.concat(patchForClipboardInElectron(framework));
}
patched = patched.concat(
patchDocModeService(docService, docsService, editorService)
);

View File

@@ -9,6 +9,7 @@ import {
} from '@affine/component';
import { AIChatBlockSchema } from '@affine/core/blocksuite/blocks';
import { WorkspaceServerService } from '@affine/core/modules/cloud';
import { DesktopApiService } from '@affine/core/modules/desktop-api';
import { type DocService, DocsService } from '@affine/core/modules/doc';
import type { EditorService } from '@affine/core/modules/editor';
import { EditorSettingService } from '@affine/core/modules/editor-setting';
@@ -52,6 +53,7 @@ import {
EmbedLinkedDocBlockConfigExtension,
GenerateDocUrlExtension,
MobileSpecsPatches,
NativeClipboardExtension,
NotificationExtension,
ParseDocUrlExtension,
PeekViewExtension,
@@ -621,3 +623,10 @@ export function patchForAttachmentEmbedViews(
},
};
}
export function patchForClipboardInElectron(framework: FrameworkProvider) {
const desktopApi = framework.get(DesktopApiService);
return NativeClipboardExtension({
copyAsPNG: desktopApi.handler.clipboard.copyAsPNG,
});
}