Open ktwrd opened 1 month ago
Hi there @ktwrd, thanks for opening an issue.
AFAICT the code you are showing is behaving as expected. On Linux, the process which puts values on the clipboard is responsible for serving them to other processes/apps forever. In your code, copy_text
makes a temporary instance of Clipboard
which gets Drop
ed after the function returns. To avoid the immediate issue, you could pass a &mut Clipboard
into copy_text
instead. However when your main
function returns, the clipboard contents would vanish as well. I don't know if it would work in your use case, but the wait method exists to help with cases like this.
When the last Clipboard
instance in a process is dropped, arboard
attempts to quickly handoff any clipboard contents its been instructed to serve (via .set_text()
, etc) to the desktop environment's clipboard manager to preserve them to be copied later. If this times out or if there is no clipboard manager, the clipboard is "reset" as the background thread which used to serve incoming requests has now exited.
FWIW I'm trying to explain this more clearly in #149 so it is less confusing to users in the future.
When using a different function for handling the creation of
Clipboard
and usage ofset_text
, the clipboard content is not set.I do not want to put a
sleep
inside ofcopy_text
since I want stuff to run instantly after that and only wait 2s before actually exiting the application.