From 56da0b606f942dffddfbb782d26125453d05c7e5 Mon Sep 17 00:00:00 2001 From: elm <71685838+not-elm@users.noreply.github.com> Date: Mon, 11 Aug 2025 01:23:13 +0900 Subject: [PATCH] Add CLI.yaml (#2) --- .github/workflows/ci.yml | 79 +++++++++++++++++++ .gitignore | 1 + Cargo.toml | 2 +- .../src/browser_process/browsers.rs | 5 +- .../src/browser_process/display_handler.rs | 4 +- .../localhost/data_responser.rs | 2 +- .../src/browser_process/renderer_handler.rs | 14 ---- crates/bevy_cef_core/src/lib.rs | 2 + .../bevy_cef_debug_render_process/src/main.rs | 2 +- src/common/message_loop.rs | 6 +- 10 files changed, 95 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4367708 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +name: CI + +on: + pull_request: + push: + +jobs: + test: + strategy: + matrix: + os: [windows-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + if: runner.os == 'linux' + - name: Build & run tests + run: | + cargo test --workspace --no-default-features + all-doc-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ubuntu-latest-cargo-all-doc-tests-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - name: Run doc tests with all features (this also compiles README examples) + run: cargo test --doc + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ubuntu-latest-cargo-lint-${{ hashFiles('**/Cargo.toml') }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: rustfmt, clippy + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - name: Run clippy + run: cargo clippy --workspace --all-targets --all-features -- -Dwarnings + - name: Check format + run: cargo fmt --all -- --check + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true diff --git a/.gitignore b/.gitignore index 5535a2e..66d6cb2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target/ .idea/ book/ +.DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 49798f7..014fac4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ serde_json = { workspace = true } raw-window-handle = "0.6" [dev-dependencies] -bevy = { workspace = true, features = ["tonemapping_luts", "multi_threaded", "file_watcher"]} +bevy = { workspace = true, default-features = true, features = ["file_watcher"]} bevy_cef = { workspace = true, features = ["debug"] } [target.'cfg(target_os = "macos")'.dependencies] diff --git a/crates/bevy_cef_core/src/browser_process/browsers.rs b/crates/bevy_cef_core/src/browser_process/browsers.rs index 7569392..8f58ca7 100644 --- a/crates/bevy_cef_core/src/browser_process/browsers.rs +++ b/crates/bevy_cef_core/src/browser_process/browsers.rs @@ -62,7 +62,7 @@ impl Browsers { ipc_event_sender: Sender, brp_sender: Sender, system_cursor_icon_sender: SystemCursorIconSenderInner, - window_handle: Option, + _window_handle: Option, ) { let mut context = Self::request_context(requester); let size = Rc::new(Cell::new(webview_size)); @@ -70,7 +70,8 @@ impl Browsers { Some(&WindowInfo { windowless_rendering_enabled: true as _, external_begin_frame_enabled: true as _, - parent_view: match window_handle { + #[cfg(target_os = "macos")] + parent_view: match _window_handle { Some(RawWindowHandle::AppKit(handle)) => handle.ns_view.as_ptr(), Some(RawWindowHandle::Win32(handle)) => handle.hwnd.get() as _, Some(RawWindowHandle::Xlib(handle)) => handle.window as _, diff --git a/crates/bevy_cef_core/src/browser_process/display_handler.rs b/crates/bevy_cef_core/src/browser_process/display_handler.rs index 1969dec..8b6c1ad 100644 --- a/crates/bevy_cef_core/src/browser_process/display_handler.rs +++ b/crates/bevy_cef_core/src/browser_process/display_handler.rs @@ -91,7 +91,9 @@ impl ImplDisplayHandler for DisplayHandlerBuilder { fn on_cursor_change( &self, _browser: Option<&mut Browser>, - _cursor: *mut u8, + #[cfg(target_os = "macos")] _cursor: *mut u8, + #[cfg(target_os = "windows")] _cursor: *mut cef_dll_sys::HICON__, + #[cfg(target_os = "linux")] _cursor: u64, type_: CursorType, _: Option<&CursorInfo>, ) -> c_int { diff --git a/crates/bevy_cef_core/src/browser_process/localhost/data_responser.rs b/crates/bevy_cef_core/src/browser_process/localhost/data_responser.rs index a50f52d..1e27083 100644 --- a/crates/bevy_cef_core/src/browser_process/localhost/data_responser.rs +++ b/crates/bevy_cef_core/src/browser_process/localhost/data_responser.rs @@ -114,4 +114,4 @@ mod tests { assert_eq!(responser.offset, 2); assert_eq!(responser.end_offset, 7); } -} \ No newline at end of file +} diff --git a/crates/bevy_cef_core/src/browser_process/renderer_handler.rs b/crates/bevy_cef_core/src/browser_process/renderer_handler.rs index 56c0702..77e220d 100644 --- a/crates/bevy_cef_core/src/browser_process/renderer_handler.rs +++ b/crates/bevy_cef_core/src/browser_process/renderer_handler.rs @@ -146,20 +146,6 @@ impl ImplRenderHandler for RenderHandlerBuilder { let _ = self.texture_sender.send_blocking(texture); } - /// MEMO: This method only supports on Windows - /// - /// In Windows, this method is more performant than `on_paint`? - #[cfg(target_os = "windows")] - fn on_accelerated_paint( - &self, - _browser: Option<&mut Browser>, - _type_: PaintElementType, - _dirty_rects_count: usize, - _dirty_rects: Option<&Rect>, - _: Option<&AcceleratedPaintInfo>, - ) { - } - #[inline] fn get_raw(&self) -> *mut sys::_cef_render_handler_t { self.object.cast() diff --git a/crates/bevy_cef_core/src/lib.rs b/crates/bevy_cef_core/src/lib.rs index a50b869..51bf0be 100644 --- a/crates/bevy_cef_core/src/lib.rs +++ b/crates/bevy_cef_core/src/lib.rs @@ -1,10 +1,12 @@ mod browser_process; +#[cfg(target_os = "macos")] mod debug; mod render_process; mod util; pub mod prelude { pub use crate::browser_process::*; + #[cfg(target_os = "macos")] pub use crate::debug::*; pub use crate::render_process::app::*; pub use crate::render_process::brp::*; diff --git a/crates/bevy_cef_debug_render_process/src/main.rs b/crates/bevy_cef_debug_render_process/src/main.rs index b5374f7..54c7bb7 100644 --- a/crates/bevy_cef_debug_render_process/src/main.rs +++ b/crates/bevy_cef_debug_render_process/src/main.rs @@ -1,4 +1,4 @@ -use bevy_cef_core::prelude::{DebugLibraryLoader, RenderProcessAppBuilder}; +use bevy_cef_core::prelude::*; use cef::{args::Args, *}; fn main() { diff --git a/src/common/message_loop.rs b/src/common/message_loop.rs index bbe2fbb..962b29b 100644 --- a/src/common/message_loop.rs +++ b/src/common/message_loop.rs @@ -2,7 +2,7 @@ use crate::RunOnMainThread; use bevy::prelude::*; use bevy_cef_core::prelude::*; use cef::args::Args; -use cef::{Settings, api_hash, do_message_loop_work, execute_process, initialize, shutdown, sys}; +use cef::{Settings, api_hash, execute_process, initialize, shutdown, sys}; /// Controls the CEF message loop. /// @@ -28,6 +28,7 @@ impl Plugin for MessageLoopPlugin { impl Default for MessageLoopPlugin { fn default() -> Self { + #[cfg(target_os = "macos")] let _loader = { macos::install_cef_app_protocol(); #[cfg(all(target_os = "macos", feature = "debug"))] @@ -84,8 +85,9 @@ impl Default for MessageLoopPlugin { } } +#[cfg(target_os = "macos")] fn cef_do_message_loop_work(_: NonSend) { - do_message_loop_work(); + cef::do_message_loop_work(); } fn cef_shutdown(_: NonSend) {