Files
bevy/deny.toml
T
ickshonpe 41f170c0a3 Basic clipboard support (#19106)
# Objective

Add a platform-agnostic interface for interacting with the clipboard.

## Solution

New crate `bevy_clipboard` with a `ClipboardPlugin` that adds a
`Clipboard` resource. The clipboard is accessed using the methods
`fetch_text`, `fetch_image`, `set_text` and `set_image` on the
`Clipboard` resource. `fetch_text` returns a `ClipboardRead` with a
`poll_result` method that's used to get the actual value once it's
ready.

The `windows` and `unix` implementations both use the `arboard` crate.
On windows the `Clipboard` resource is a unit struct and a new arboard
clipboard instance is created and dropped for each clipboard access. On
unix targets the `Clipboard` resource holds a clipboard instance it
reuses each time. On both targets the `fetch_*` and `set_*` methods work
instantly.

On `wasm32` `Clipboard` is a unit struct. The `fetch_text` and
`set_text` functions spawn async tasks. The task spawned by `fetch_text`
updates the shared arc mutex option once the future is evaluated to get
the clipboard text. There is no image support on `wasm32`.

Everything seems to work but it feels like the design is a bit clumsy
and not very idiomatic. I don't tend to do much asynchronous
programming, maybe a reviewer can suggest an improved construction.

I also added an alternative `fetch_text_async` function for async access
that returns a `Result<String, ClipboardError>` future.

### Notes
* Doesn't support android targets yet. 
* The wasm32 implementation doesn't support images. It's much more
complicated and probably best to left to a follow up.

## Testing

The PR includes a basic example `clipboard` that can be used for
testing.
The image display will only work if the image is already in the
clipboard before the example starts.

---------

Co-authored-by: Gilles Henaux <ghx_github_priv@fastmail.com>
Co-authored-by: Andrew Zhurov <zhurov.andrew@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2026-04-23 21:18:07 +00:00

104 lines
2.4 KiB
TOML

[graph]
all-features = true
[advisories]
version = 2
ignore = [
# paste was announced as unmaintained with no explanation or replacement
# See: https://rustsec.org/advisories/RUSTSEC-2024-0436
# Bevy relies on this in multiple indirect ways, so ignoring it is the only feasible current solution
"RUSTSEC-2024-0436",
# unmaintained: postcard -> heapless -> atomic-polyfill
# See https://github.com/jamesmunns/postcard/issues/223
"RUSTSEC-2023-0089",
]
[licenses]
version = 2
allow = [
"0BSD",
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"BSD-2-Clause",
"BSD-3-Clause",
"CC0-1.0",
"CDLA-Permissive-2.0",
"ISC",
"MIT",
"MIT-0",
"Unlicense",
"Zlib",
"Unicode-3.0",
"BSL-1.0",
]
exceptions = [
{ name = "unicode-ident", allow = [
"Unicode-DFS-2016",
"Unicode-3.0",
] },
{ name = "symphonia", allow = [
"MPL-2.0",
] },
{ name = "symphonia-bundle-flac", allow = [
"MPL-2.0",
] },
{ name = "symphonia-bundle-mp3", allow = [
"MPL-2.0",
] },
{ name = "symphonia-codec-aac", allow = [
"MPL-2.0",
] },
{ name = "symphonia-codec-pcm", allow = [
"MPL-2.0",
] },
{ name = "symphonia-codec-vorbis", allow = [
"MPL-2.0",
] },
{ name = "symphonia-core", allow = [
"MPL-2.0",
] },
{ name = "symphonia-format-isomp4", allow = [
"MPL-2.0",
] },
{ name = "symphonia-format-ogg", allow = [
"MPL-2.0",
] },
{ name = "symphonia-format-riff", allow = [
"MPL-2.0",
] },
{ name = "symphonia-metadata", allow = [
"MPL-2.0",
] },
{ name = "symphonia-utils-xiph", allow = [
"MPL-2.0",
] },
]
[bans]
multiple-versions = "warn"
wildcards = "deny"
# Certain crates that we don't want multiple versions of in the dependency tree
deny = [
{ name = "ahash", deny-multiple-versions = true },
{ name = "accesskit", deny-multiple-versions = true },
{ name = "android-activity", deny-multiple-versions = true },
{ name = "parley", deny-multiple-versions = true },
{ name = "glam", deny-multiple-versions = true },
{ name = "raw-window-handle", deny-multiple-versions = true },
]
skip = [
{ name = "bevy_math", reason = "bevy_math has a path dev dependency on itself without a version" },
]
[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
allow-git = []
# thiserror is the preferred way to derive error types
[[bans.features]]
crate = "derive_more"
deny = ["error"]