Skip to content

Commit b8f7e7f

Browse files
committed
Make the clipboard opt-in
1 parent 62aac50 commit b8f7e7f

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ serde = "^1"
3333
serde_json = "^1"
3434
thiserror = "^2"
3535
uuid = "1.9.1"
36-
arboard = "3.4"
36+
arboard = {version = "3.4", optional = true}
3737

3838
[features]
3939
bevy_reflect = []
4040
vpeol = []
4141
vpeol_2d = ["vpeol", "bevy/bevy_text", "bevy/bevy_sprite", "bevy/png"]
4242
vpeol_3d = ["vpeol", "bevy/bevy_pbr"]
43+
# Support clipboard with the arboard crate.
44+
arboard = ["dep:arboard"]
4345
_example2d_full = ["vpeol_2d", "bevy/bevy_gizmos", "bevy/bevy_sprite_render"]
4446
_example3d_full = [
4547
"vpeol_3d",

src/vpeol_2d.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,9 +534,13 @@ fn handle_copy_entity_key(
534534
.collect();
535535

536536
if !entities.is_empty() {
537+
#[allow(unused_variables)] // TODO: try to remove when the arboard alternative gets in
537538
if let Ok(json) = serde_json::to_string(&entities) {
538-
let mut clipboard = arboard::Clipboard::new()?;
539-
clipboard.set_text(json)?;
539+
#[cfg(feature = "arboard")]
540+
{
541+
let mut clipboard = arboard::Clipboard::new()?;
542+
clipboard.set_text(json)?;
543+
}
540544
}
541545
}
542546
}
@@ -560,8 +564,18 @@ fn handle_paste_entity_key(
560564
|| keyboard_input.pressed(KeyCode::ControlRight);
561565

562566
if ctrl_pressed && keyboard_input.just_pressed(KeyCode::KeyV) {
563-
let mut clipboard = arboard::Clipboard::new()?;
564-
if let Ok(text) = clipboard.get_text() {
567+
#[allow(unused_variables)] // TODO: try to remove when the arboard alternative gets in
568+
let text_to_paste: Option<String> = None;
569+
570+
#[cfg(feature = "arboard")]
571+
let text_to_paste = {
572+
let mut clipboard = arboard::Clipboard::new()?;
573+
clipboard.get_text().ok()
574+
};
575+
576+
// TODO: add fallback when arboard is not enabled or doesn't work
577+
578+
if let Some(text) = text_to_paste {
565579
if let Ok(entities) = serde_json::from_str::<Vec<YoleckRawEntry>>(&text) {
566580
if !entities.is_empty() {
567581
for prev_selected in query.iter() {

src/vpeol_3d.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,13 @@ fn handle_copy_entity_key(
731731
.collect();
732732

733733
if !entities.is_empty() {
734+
#[allow(unused_variables)] // TODO: try to remove when the arboard alternative gets in
734735
if let Ok(json) = serde_json::to_string(&entities) {
735-
let mut clipboard = arboard::Clipboard::new()?;
736-
clipboard.set_text(json)?;
736+
#[cfg(feature = "arboard")]
737+
{
738+
let mut clipboard = arboard::Clipboard::new()?;
739+
clipboard.set_text(json)?;
740+
}
737741
}
738742
}
739743
}
@@ -757,8 +761,18 @@ fn handle_paste_entity_key(
757761
|| keyboard_input.pressed(KeyCode::ControlRight);
758762

759763
if ctrl_pressed && keyboard_input.just_pressed(KeyCode::KeyV) {
760-
let mut clipboard = arboard::Clipboard::new()?;
761-
if let Ok(text) = clipboard.get_text() {
764+
#[allow(unused_variables)] // TODO: try to remove when the arboard alternative gets in
765+
let text_to_paste: Option<String> = None;
766+
767+
#[cfg(feature = "arboard")]
768+
let text_to_paste = {
769+
let mut clipboard = arboard::Clipboard::new()?;
770+
clipboard.get_text().ok()
771+
};
772+
773+
// TODO: add fallback when arboard is not enabled or doesn't work
774+
775+
if let Some(text) = text_to_paste {
762776
if let Ok(entities) = serde_json::from_str::<Vec<YoleckRawEntry>>(&text) {
763777
if !entities.is_empty() {
764778
for prev_selected in query.iter() {

0 commit comments

Comments
 (0)