2021-06-20 13:03:18 +02:00
|
|
|
export default class JoplinClipboard {
|
|
|
|
|
2021-06-20 14:46:50 +02:00
|
|
|
private electronClipboard_: any = null;
|
|
|
|
private electronNativeImage_: any = null;
|
|
|
|
|
|
|
|
public constructor(electronClipboard: any, electronNativeImage: any) {
|
|
|
|
this.electronClipboard_ = electronClipboard;
|
|
|
|
this.electronNativeImage_ = electronNativeImage;
|
|
|
|
}
|
|
|
|
|
2021-06-20 13:03:18 +02:00
|
|
|
public async readText(): Promise<string> {
|
2021-06-20 14:46:50 +02:00
|
|
|
return this.electronClipboard_.readText();
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async writeText(text: string): Promise<void> {
|
2021-06-20 14:46:50 +02:00
|
|
|
this.electronClipboard_.writeText(text);
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async readHtml(): Promise<string> {
|
2021-06-20 14:46:50 +02:00
|
|
|
return this.electronClipboard_.readHTML();
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public async writeHtml(html: string): Promise<void> {
|
2021-06-20 14:46:50 +02:00
|
|
|
this.electronClipboard_.writeHTML(html);
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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<string> {
|
2021-06-20 14:46:50 +02:00
|
|
|
const image = this.electronClipboard_.readImage();
|
2021-06-20 13:03:18 +02:00
|
|
|
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<void> {
|
2021-06-20 14:46:50 +02:00
|
|
|
this.electronClipboard_.writeImage(this.electronNativeImage_.createFromDataURL(dataUrl));
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list available formats (mime types).
|
|
|
|
*
|
|
|
|
* For example [ 'text/plain', 'text/html' ]
|
|
|
|
*/
|
|
|
|
public async availableFormats(): Promise<string[]> {
|
2021-06-20 14:46:50 +02:00
|
|
|
return this.electronClipboard_.availableFormats();
|
2021-06-20 13:03:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|