TiddlyDesktop icon indicating copy to clipboard operation
TiddlyDesktop copied to clipboard

[Idea] can we have a copy-from-clipboard macro/message within tiddlydesktop?

Open BurningTreeC opened this issue 2 years ago • 3 comments

https://docs.nwjs.io/en/latest/References/Clipboard suggests that we could make clipboard access available within TiddlyDesktop

A copy-from-clipboard macro or message would be very great, what do you think? Is it even possible?

BurningTreeC avatar Aug 08 '21 14:08 BurningTreeC

Hi @BurningTreeC good idea, and yes, I think it would be possible.

A widget message would presumably take a parameter to specify a tiddler into which the clipboard content would be copied. An alternative might be to have an <$action-readclipboard> widget that works like this:

<$action-readclipboard>
<!-- The contents of the clipboard are available here via variables like `clipboardText`, `clipboardHTML` etc -->
<$action-createtiddler text=<<clipboardText>>/>
</$action-readclipboard>

Jermolene avatar Aug 09 '21 17:08 Jermolene

Thanks for your reply @Jermolene , what I don't know yet is how nw is exposed within a wiki in TiddlyDesktop

BurningTreeC avatar Aug 12 '21 09:08 BurningTreeC

Hi @BurningTreeC wiki files are loaded in an iframe which has the special "nwdisable" and "nwfaketop" attributes which mean that nw.js functionality isn't available to code within the iframe.

To handle saving we use the same approach as TiddlyFox: communicating via event handles on DOM elements. See source/js/saving.js for the details.

In this case, I think we'll need to inject a global JS function into the iframe. We can do that along the same lines as injectClassicOverrides() in the same file. Rather than using the DOM event technique, it might be more convenient to use window.postMessage(); you'll find lots of example code for communicating between an iframe and its host.

Having said all of that, there is a strange anomaly: the core browse widget code includes the nwsaveas and nwdirectory attributes and gets a path in event.target.files as per the nwjs docs, even though the "nwdisable" and "nwfaketop" attributes would imply that file paths should be hidden.

So, the point is that you might find that the API is available within the iframe anyway, without us having to do anything special. Definitely worth checking.

Jermolene avatar Aug 12 '21 15:08 Jermolene