Skip to content

Commit

Permalink
disable manage clipboard for wasm32 AND android (#241)
Browse files Browse the repository at this point in the history
* disable manage_clipboard feature
if target = android

* Implement CI for the mobile platform

* Fix formatting

---------

Co-authored-by: mvlabat <mvlabat@gmail.com>
  • Loading branch information
Hellzbellz123 and mvlabat committed Jan 7, 2024
1 parent 00dece3 commit eee3aae
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,73 @@ jobs:
cache-wasm32-cargo
- run: cargo clippy --no-default-features --target=wasm32-unknown-unknown --all-targets --features=${{ matrix.features }} -- -D warnings

clippy_android:
name: Clippy check (android)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
features:
[
"immutable_ctx",
"manage_clipboard",
"open_url",
"manage_clipboard,open_url",
]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
targets: aarch64-linux-android
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cache-android-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
cache-android-cargo-${{ hashFiles('**/Cargo.toml') }}
cache-android-cargo
- run: |
CC=$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang \
AR=$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar \
cargo clippy --target=aarch64-linux-android --no-default-features --all-targets --features=${{ matrix.features }} -- -D warnings
clippy_ios:
name: Clippy check (ios)
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
features:
[
"immutable_ctx",
"manage_clipboard",
"open_url",
"manage_clipboard,open_url",
]
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: clippy
targets: aarch64-apple-ios
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cache-ios-cargo-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
cache-ios-cargo-${{ hashFiles('**/Cargo.toml') }}
cache-ios-cargo
- run: cargo clippy --target=aarch64-apple-ios --no-default-features --all-targets --features=${{ matrix.features }} -- -D warnings

doc:
name: Check documentation
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bevy = { version = "0.12", default-features = false, features = [
egui = { version = "0.24.0", default-features = false, features = ["bytemuck"] }
webbrowser = { version = "0.8.2", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
[target.'cfg(not(any(target_arch = "wasm32", target_os = "android")))'.dependencies]
arboard = { version = "3.2.0", optional = true }
thread_local = { version = "1.1.0", optional = true }

Expand Down
21 changes: 15 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ use crate::{
render_systems::{EguiTransforms, ExtractedEguiManagedTextures},
systems::*,
};
#[cfg(all(feature = "manage_clipboard", not(target_arch = "wasm32")))]
#[cfg(all(
feature = "manage_clipboard",
not(any(target_arch = "wasm32", target_os = "android"))
))]
use arboard::Clipboard;
use bevy::{
app::{App, Last, Plugin, PostUpdate, PreStartup, PreUpdate},
Expand Down Expand Up @@ -94,9 +97,15 @@ use bevy::{
window::{PrimaryWindow, Window},
};
use std::borrow::Cow;
#[cfg(all(feature = "manage_clipboard", not(target_arch = "wasm32")))]
#[cfg(all(
feature = "manage_clipboard",
not(any(target_arch = "wasm32", target_os = "android"))
))]
use std::cell::{RefCell, RefMut};
#[cfg(all(feature = "manage_clipboard", not(target_arch = "wasm32")))]
#[cfg(all(
feature = "manage_clipboard",
not(any(target_arch = "wasm32", target_os = "android"))
))]
use thread_local::ThreadLocal;

/// Adds all Egui resources and render graph nodes.
Expand Down Expand Up @@ -189,7 +198,7 @@ pub struct EguiInput(pub egui::RawInput);
/// A resource for accessing clipboard.
///
/// The resource is available only if `manage_clipboard` feature is enabled.
#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
#[derive(Default, Resource)]
pub struct EguiClipboard {
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -198,7 +207,7 @@ pub struct EguiClipboard {
clipboard: String,
}

#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
impl EguiClipboard {
/// Sets clipboard contents.
pub fn set_contents(&mut self, contents: &str) {
Expand Down Expand Up @@ -578,7 +587,7 @@ impl Plugin for EguiPlugin {
let world = &mut app.world;
world.init_resource::<EguiSettings>();
world.init_resource::<EguiManagedTextures>();
#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
world.init_resource::<EguiClipboard>();
world.init_resource::<EguiUserTextures>();
world.init_resource::<EguiMousePosition>();
Expand Down
9 changes: 5 additions & 4 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct TouchId(pub Option<u64>);
#[allow(missing_docs)]
#[derive(SystemParam)]
pub struct InputResources<'w, 's> {
#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
pub egui_clipboard: Res<'w, crate::EguiClipboard>,
pub keyboard_input: Res<'w, Input<KeyCode>>,
#[system_param(ignore)]
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn process_input_system(

// We also check that it's an `ButtonState::Pressed` event, as we don't want to
// copy, cut or paste on the key release.
#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
if command && pressed {
match key {
egui::Key::C => {
Expand Down Expand Up @@ -416,7 +416,8 @@ pub fn process_output_system(
EguiSettings,
>,
mut contexts: Query<EguiContextQuery>,
#[cfg(feature = "manage_clipboard")] mut egui_clipboard: ResMut<crate::EguiClipboard>,
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
mut egui_clipboard: ResMut<crate::EguiClipboard>,
mut event: EventWriter<RequestRedraw>,
#[cfg(windows)] mut last_cursor_icon: Local<bevy::utils::HashMap<Entity, egui::CursorIcon>>,
) {
Expand All @@ -437,7 +438,7 @@ pub fn process_output_system(

context.egui_output.platform_output = platform_output.clone();

#[cfg(feature = "manage_clipboard")]
#[cfg(all(feature = "manage_clipboard", not(target_os = "android")))]
if !platform_output.copied_text.is_empty() {
egui_clipboard.set_contents(&platform_output.copied_text);
}
Expand Down

0 comments on commit eee3aae

Please sign in to comment.