I'm working on a Compose application which manipulates the clipboard.
So I have been using this:
val clipboardManager = LocalClipboardManager.current
This worked fine, until I hoisted it out of the Window scope.
i.e., this is OK:
if (showMainWindow) {
Window() {
val clipboardManager = LocalClipboardManager.current
}
}
While this is not OK:
val clipboardManager = LocalClipboardManager.current
if (showMainWindow) {
Window() {
// ...
}
}
Conceptually, the clipboard exists outside all windows, so it should be accessible even if there are no windows currently shown. And I certainly don't want my window to be lurking around when it isn't needed.
Where do I go from here?
- Is there a way to inject
ClipboardManagersomehow to make it accessible insideapplicationscope instead of window scope? - Should I even be using
ClipboardManager? It is a pretty bad API. Plenty of people copy/paste images and the API only supports text. Compare that with what AWT gets. (which is still limited) - Should I abandon even AWT and find a way to access the native clipboard API? :(