Skip to content

move ANDROID_APP to bevy_window #15585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ thiserror = "1.0"
uuid = { version = "1.0", features = ["v4"] }

[target.'cfg(target_os = "android")'.dependencies]
bevy_winit = { path = "../bevy_winit", version = "0.15.0-dev" }
bevy_window = { path = "../bevy_window", version = "0.15.0-dev" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2" }
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_asset/src/io/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct AndroidAssetReader;

impl AssetReader for AndroidAssetReader {
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let asset_manager = bevy_winit::ANDROID_APP
let asset_manager = bevy_window::ANDROID_APP
.get()
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
.asset_manager();
Expand All @@ -31,7 +31,7 @@ impl AssetReader for AndroidAssetReader {

async fn read_meta<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let meta_path = get_meta_path(path);
let asset_manager = bevy_winit::ANDROID_APP
let asset_manager = bevy_window::ANDROID_APP
.get()
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
.asset_manager();
Expand All @@ -47,7 +47,7 @@ impl AssetReader for AndroidAssetReader {
&'a self,
path: &'a Path,
) -> Result<Box<PathStream>, AssetReaderError> {
let asset_manager = bevy_winit::ANDROID_APP
let asset_manager = bevy_window::ANDROID_APP
.get()
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
.asset_manager();
Expand Down Expand Up @@ -76,7 +76,7 @@ impl AssetReader for AndroidAssetReader {
&'a self,
path: &'a Path,
) -> std::result::Result<bool, AssetReaderError> {
let asset_manager = bevy_winit::ANDROID_APP
let asset_manager = bevy_window::ANDROID_APP
.get()
.expect("Bevy must be setup with the #[bevy_main] macro on Android")
.asset_manager();
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_derive/src/bevy_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub fn bevy_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
TokenStream::from(quote! {
#[no_mangle]
#[cfg(target_os = "android")]
fn android_main(android_app: bevy::winit::android_activity::AndroidApp) {
let _ = bevy::winit::ANDROID_APP.set(android_app);
fn android_main(android_app: bevy::window::android_activity::AndroidApp) {
let _ = bevy::window::ANDROID_APP.set(android_app);
main();
}

Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_window/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ serde = { version = "1.0", features = ["derive"], optional = true }
raw-window-handle = "0.6"
smol_str = "0.2"

[target.'cfg(target_os = "android")'.dependencies]
android-activity = "0.6"

[lints]
workspace = true

Expand Down
9 changes: 9 additions & 0 deletions crates/bevy_window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ mod window;

pub use crate::raw_handle::*;

#[cfg(target_os = "android")]
pub use android_activity;

pub use event::*;
pub use monitor::*;
pub use system::*;
Expand Down Expand Up @@ -188,3 +191,9 @@ pub enum ExitCondition {
/// surprise your users.
DontExit,
}

/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
/// (for example lifecycle and input events).
#[cfg(target_os = "android")]
pub static ANDROID_APP: std::sync::OnceLock<android_activity::AndroidApp> =
std::sync::OnceLock::new();
10 changes: 1 addition & 9 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ use bevy_derive::Deref;
use bevy_window::{RawHandleWrapperHolder, WindowEvent};
use core::marker::PhantomData;
use winit::event_loop::EventLoop;
#[cfg(target_os = "android")]
pub use winit::platform::android::activity as android_activity;

use bevy_a11y::AccessibilityRequested;
use bevy_app::{App, Last, Plugin};
Expand Down Expand Up @@ -52,12 +50,6 @@ mod winit_config;
mod winit_monitors;
mod winit_windows;

/// [`AndroidApp`] provides an interface to query the application state as well as monitor events
/// (for example lifecycle and input events).
#[cfg(target_os = "android")]
pub static ANDROID_APP: std::sync::OnceLock<android_activity::AndroidApp> =
std::sync::OnceLock::new();

/// A [`Plugin`] that uses `winit` to create and manage windows, and receive window and input
/// events.
///
Expand Down Expand Up @@ -119,7 +111,7 @@ impl<T: Event> Plugin for WinitPlugin<T> {
{
use winit::platform::android::EventLoopBuilderExtAndroid;
let msg = "Bevy must be setup with the #[bevy_main] macro on Android";
event_loop_builder.with_android_app(ANDROID_APP.get().expect(msg).clone());
event_loop_builder.with_android_app(bevy_window::ANDROID_APP.get().expect(msg).clone());
}

app.init_non_send_resource::<WinitWindows>()
Expand Down