const { clipboard, nativeImage } = require('electron'); export default class JoplinClipboard { public async readText(): Promise { return clipboard.readText(); } public async writeText(text: string): Promise { clipboard.writeText(text); } public async readHtml(): Promise { return clipboard.readHTML(); } public async writeHtml(html: string): Promise { clipboard.writeHTML(html); } /** * Returns the image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format. */ public async readImage(): Promise { const image = clipboard.readImage(); return image ? image.toDataURL() : ''; } /** * Takes an image in [data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format. */ public async writeImage(dataUrl: string): Promise { clipboard.writeImage(nativeImage.createFromDataURL(dataUrl)); } /** * Returns the list available formats (mime types). * * For example [ 'text/plain', 'text/html' ] */ public async availableFormats(): Promise { return clipboard.availableFormats(); } }