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
@@ -1,10 +1,12 @@
import type { IpcMainInvokeEvent } from 'electron';
import { clipboard, nativeImage } from 'electron';
import type { NamespaceHandlers } from '../type';
export const clipboardHandlers = {
copyAsImageFromString: async (_: IpcMainInvokeEvent, dataURL: string) => {
clipboard.writeImage(nativeImage.createFromDataURL(dataURL));
copyAsPNG: async (_, arrayBuffer: ArrayBuffer) => {
const image = nativeImage.createFromBuffer(Buffer.from(arrayBuffer));
if (image.isEmpty()) return false;
clipboard.writeImage(image);
return true;
},
} satisfies NamespaceHandlers;