Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Clipboard change event to clipboard API #2280

Closed
gratmann opened this issue Jul 20, 2015 · 41 comments
Closed

Add Clipboard change event to clipboard API #2280

gratmann opened this issue Jul 20, 2015 · 41 comments

Comments

@gratmann
Copy link

I'd like to write a clipboard manager that monitors the systems' clipboard. Searching for an event in the clipboard I didn't found one.

I know there exists the HTML5 clipboard API, but my application needs to monitor the clipboard when it does not have focus.

I mean like QClipboard's void selectionChanged() and void dataChanged() or like GTK's owner-changed.

Currently I'm retrieving the contents of the clipboard and look manually whether the content has changed every 20ms, which should not be the preferred way. It works but I really shouldn't resort to a busy polling loop...

@afc163
Copy link

afc163 commented Aug 11, 2015

Need that too

@destan
Copy link
Contributor

destan commented Sep 9, 2015

👍

@mikesurowiec
Copy link

👍 would be useful for me too

@alejandroSuch
Copy link

@senior-sigan
Copy link

👍

1 similar comment
@johnRivs
Copy link

+1

@edokeh
Copy link

edokeh commented Nov 17, 2015

+1
I need this!

@anaisbetts
Copy link
Contributor

This isn't possible on OS X, you have to poll. It works on Windows, and miiiight work on Linux?

@destan
Copy link
Contributor

destan commented Jan 5, 2016

@paulcbetts what do you mean by isn't possible? Did you take a look into how Qt implements this functionality?

@destan
Copy link
Contributor

destan commented Feb 24, 2016

@zcbenz any plans in roadmap to implement this?

@anaisbetts
Copy link
Contributor

@destan As far as I can see from https://github.com/qtproject/qtbase/blob/dev/src/plugins/platforms/cocoa/qmacclipboard.mm, it doesn't implement it at all, the event just doesn't fire.

@destan
Copy link
Contributor

destan commented Mar 24, 2016

@paulcbetts I don't know about mac but it works on windows and linux (currently I am using it). Moreover you may be misinterpreting the source code because if it wasn't available on mac it would have been stated here http://doc.qt.io/qt-5/qclipboard.html#changed

@nwestbury
Copy link

+1, I could use this

@zcbenz
Copy link
Member

zcbenz commented Jun 22, 2016

Chromium is going to add this feature, we will be able to use it Electron after it gets finished:
https://bugs.chromium.org/p/chromium/issues/detail?id=460610

@anaisbetts
Copy link
Contributor

I'm not so sure, it looks like only X11 and ChromeOS get it

@wangxiexe
Copy link

want it badly! thx.

@destan
Copy link
Contributor

destan commented Nov 3, 2016

@zcbenz https://bugs.chromium.org/p/chromium/issues/detail?id=460610 seems fixed, do you have time to check it out?

@iDaN5x
Copy link

iDaN5x commented Jan 2, 2017

@zcbenz any updates?

@toaco
Copy link

toaco commented Jan 19, 2017

+1

@anaisbetts
Copy link
Contributor

anaisbetts commented Jan 19, 2017

@destan Still only implemented for X11 and ChromeOS

@zh99998
Copy link

zh99998 commented Jan 22, 2017

+1 for this request

phuedx added a commit to phuedx/copypasta that referenced this issue Jan 22, 2017
End: Make the workflow more natural.
Means: Remove the Ctrl/Cmd+Shift+C shortcut.

Electron's clipboard API doesn't expose a change event or observable
event stream (see electron/electron#2280).
Until it does, we're forced to busy wait, checking the contents of the
clipboard every N ms.

Fortunately, electron-clipboard-watcher already implements this.
However, it's API isn't ideal. It's as important to start a conversation
with that module's author, @joshwnj, as it is to meet the stated end.

With the above in mind, add the observable-clipboard module, which uses
the wraps the electron-clipboard-watcher with zen-observable, an
implementation of the Observable spec (see
https://tc39.github.io/proposal-observable/).
@twang2218
Copy link

Blocking issue https://bugs.chromium.org/p/chromium/issues/detail?id=460610#c22 has been fixed, but in chromium stable 56, I think that is why this issue hasn't been fixed yet, as libchromiumcontent hadn't been upgraded to Chromium 56 back then.

But now it's upgraded to 56 via PR electron/libchromiumcontent#258. This issue might be able to be fixed this time.

ping @zcbenz

@kevinsawicki
Copy link
Contributor

kevinsawicki commented Feb 9, 2017

@twang2218 this is still only implemented on Linux in Chromium.

https://cs.chromium.org/search/?q=NotifyClipboardDataChanged&type=cs

@LewdEwe-ErikWallace
Copy link

I'm also wishing Electron had clipboard events. 👍

@twang2218
Copy link

Oh, that's unfortunately. For my case, I got performance hit of keep checking for new clipboard on Linux, which is 10-20 times slower than macOS. It would be great even if only implemented this feature on Linux.

@LewdEwe-ErikWallace
Copy link

LewdEwe-ErikWallace commented Feb 11, 2017

For now I've simply used some preload code in a frameless hidden window as a kind of clipboard manager utility. I'm using an interval timer of 250ms to read the clipboard and compare it to the last value; if it has changed I send an IPC message to the main Node Electron process, which decides if it's relevant and if it is then sends an IPC message to the visible UI window to update the display. It suits my needs and is very responsive, as soon as I copy text in another application it immediately appears in my Electron app. I don't have access to a Mac so I've only tested this on linux.

@JonasGroeger
Copy link

@LewdEwe-ErikWallace Do you have that code somewhere?

@iDaN5x
Copy link

iDaN5x commented Mar 7, 2017

Correct me if I'm wrong, but it should be possible to write a native node add-on to support this.

Native add-ons are written in C/C++ and compiled by node-gyp;
Using conditional preprocessor directives, we can have cross-platform support.

The add-on would subscribe to the system's native clipboard events & call stored callback JS functions when en event rises.

@LewdEwe-ErikWallace
Copy link

@JonasGroeger

Sorry I didn't see your comment sooner. Here is an example extracted from my project:

https://gist.github.com/LewdEwe-ErikWallace/d6e36f899a77a4f05e46388c254d014f

@dsantratlock
Copy link

This would also be very useful to an electron application I am working on.

@LewdEwe-ErikWallace
Copy link

@dsantratlock
Feel free to copy anything in the gist if it helps you.

@codebytere
Copy link
Member

As this is still only implemented in Chromium for Linux, I also believe this is better as a native addon rather then implemented in such a platform-specific capacity. As such, i'm labeling this a wontfix, but should something change on the Chromium side we can revisit this!

@PovarovDenis
Copy link

Hey folks, any updates?

@sudhakar3697
Copy link

Hey folks, check my npm module (node-clipboard-event) out.
Thank you.

@318097
Copy link

318097 commented Apr 1, 2021

I need this tooo

@akash07k
Copy link

I too need this badly. any update on this?
@hokein
@zcbenz

@akash07k
Copy link

Hey bro, your module is awesome, is there any way to get the data/text which has been changed?

Hey folks, check my npm module (node-clipboard-event) out.
Thank you.

@akash07k
Copy link

@hokein
@zcbenz
any update on it guys?

@felipecrs
Copy link

Hey bro, your module is awesome, is there any way to get the data/text which has been changed?

https://github.com/electron/electron/blob/main/docs/api/clipboard.md#clipboard

@felipecrs
Copy link

For anyone interested in this feature, I suggest you star this crbug: https://bugs.chromium.org/p/chromium/issues/detail?id=933608

@akash07k
Copy link

starred.

For anyone interested in this feature, I suggest you star this crbug: https://bugs.chromium.org/p/chromium/issues/detail?id=933608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests