mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user