1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Plugins: Add support for read and writing text, HTML and images from/to clipboard

This commit is contained in:
Laurent Cozic
2021-06-20 12:03:18 +01:00
parent 8a2ca0535d
commit 50ecdc2ff1
33 changed files with 6625 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import JoplinViews from './JoplinViews';
import JoplinInterop from './JoplinInterop';
import JoplinSettings from './JoplinSettings';
import JoplinContentScripts from './JoplinContentScripts';
import JoplinClipboard from './JoplinClipboard';
/**
* This is the main entry point to the Joplin API. You can access various services using the provided accessors.
@ -35,6 +36,7 @@ export default class Joplin {
private interop_: JoplinInterop = null;
private settings_: JoplinSettings = null;
private contentScripts_: JoplinContentScripts = null;
private clipboard_: JoplinClipboard = null;
constructor(implementation: any, plugin: Plugin, store: any) {
this.data_ = new JoplinData();
@ -46,12 +48,17 @@ export default class Joplin {
this.interop_ = new JoplinInterop();
this.settings_ = new JoplinSettings(plugin);
this.contentScripts_ = new JoplinContentScripts(plugin);
this.clipboard_ = new JoplinClipboard();
}
get data(): JoplinData {
return this.data_;
}
get clipboard(): JoplinClipboard {
return this.clipboard_;
}
get plugins(): JoplinPlugins {
return this.plugins_;
}

View File

@ -0,0 +1,45 @@
const { clipboard, nativeImage } = require('electron');
export default class JoplinClipboard {
public async readText(): Promise<string> {
return clipboard.readText();
}
public async writeText(text: string): Promise<void> {
clipboard.writeText(text);
}
public async readHtml(): Promise<string> {
return clipboard.readHTML();
}
public async writeHtml(html: string): Promise<void> {
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<string> {
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<void> {
clipboard.writeImage(nativeImage.createFromDataURL(dataUrl));
}
/**
* Returns the list available formats (mime types).
*
* For example [ 'text/plain', 'text/html' ]
*/
public async availableFormats(): Promise<string[]> {
return clipboard.availableFormats();
}
}