-
-
Notifications
You must be signed in to change notification settings - Fork 3
fix: webview tracking #54
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,10 +7,7 @@ use crate::webview::handlers::{HandlerQueries, WryEventParams}; | |||||||||
| use crate::webview::load_webview::ipc::IpcHandlerParams; | ||||||||||
| use crate::webview::load_webview::protocol::feed_uri; | ||||||||||
| use crate::webview::protocol::WryRequestSender; | ||||||||||
| use bevy::prelude::{ | ||||||||||
| App, Commands, Entity, Name, NonSend, NonSendMut, Or, Plugin, PreUpdate, Query, Res, Window, | ||||||||||
| With, Without, | ||||||||||
| }; | ||||||||||
| use bevy::prelude::*; | ||||||||||
| use bevy::winit::WinitWindows; | ||||||||||
| use bevy_webview_core::bundle::embedding::{Bounds, EmbedWithin}; | ||||||||||
| use bevy_webview_core::prelude::*; | ||||||||||
|
|
@@ -33,9 +30,9 @@ impl Plugin for LoadWebviewPlugin { | |||||||||
| { | ||||||||||
| use bevy::prelude::IntoScheduleConfigs; | ||||||||||
| app.add_systems( | ||||||||||
| PreUpdate, | ||||||||||
| (resize_webview_inner_window | ||||||||||
| .run_if(bevy::prelude::on_event::<bevy::window::WindowResized>),), | ||||||||||
| Update, | ||||||||||
| move_webview_inner_window | ||||||||||
| .run_if(on_event::<WindowMoved>.or(on_event::<bevy::window::WindowResized>)), | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
@@ -280,7 +277,6 @@ unsafe fn attach_inner_window( | |||||||||
| // SAFETY: The `webview` is a valid pointer to an `NSView`. | ||||||||||
| unsafe { | ||||||||||
| use objc2_app_kit::NSAutoresizingMaskOptions; | ||||||||||
|
|
||||||||||
| webview.removeFromSuperview(); | ||||||||||
| webview.setAutoresizingMask( | ||||||||||
| NSAutoresizingMaskOptions::ViewHeightSizable | ||||||||||
|
|
@@ -303,10 +299,8 @@ unsafe fn attach_inner_window( | |||||||||
|
|
||||||||||
| let content_rect = application_window.contentRectForFrameRect(application_window.frame()); | ||||||||||
| inner_window.setFrame_display(content_rect, true); | ||||||||||
| inner_window.setHidesOnDeactivate(false); | ||||||||||
| inner_window.setTitlebarAppearsTransparent(true); | ||||||||||
| inner_window.setTitleVisibility(objc2_app_kit::NSWindowTitleVisibility::Hidden); | ||||||||||
|
|
||||||||||
| inner_window.setContentView(Some(webview)); | ||||||||||
|
|
||||||||||
| inner_window.becomeKeyWindow(); | ||||||||||
|
|
@@ -334,18 +328,27 @@ unsafe fn attach_inner_window( | |||||||||
| } | ||||||||||
|
|
||||||||||
| #[cfg(target_os = "macos")] | ||||||||||
| fn resize_webview_inner_window( | ||||||||||
| mut er: bevy::prelude::EventReader<bevy::window::WindowResized>, | ||||||||||
| fn move_webview_inner_window( | ||||||||||
| mut er_moved: EventReader<WindowMoved>, | ||||||||||
| mut er_resized: EventReader<bevy::window::WindowResized>, | ||||||||||
| winit_windows: NonSend<WinitWindows>, | ||||||||||
| wry_web_views: NonSend<WryWebViews>, | ||||||||||
| ) { | ||||||||||
| let mut windows = bevy::platform::collections::HashSet::new(); | ||||||||||
| #[allow(deprecated)] | ||||||||||
| use wry::raw_window_handle::{HasRawWindowHandle, RawWindowHandle}; | ||||||||||
| for e in er.read() { | ||||||||||
| let Some(winit_window) = winit_windows.get_window(e.window) else { | ||||||||||
| for window in er_moved | ||||||||||
| .read() | ||||||||||
| .map(|e| e.window) | ||||||||||
| .chain(er_resized.read().map(|e| e.window)) | ||||||||||
| { | ||||||||||
| if !windows.insert(window) { | ||||||||||
| continue; // Skip if we've already processed this window | ||||||||||
| } | ||||||||||
| let Some(winit_window) = winit_windows.get_window(window) else { | ||||||||||
| continue; | ||||||||||
| }; | ||||||||||
| let Some(wry_webview) = wry_web_views.0.get(&e.window) else { | ||||||||||
| let Some(wry_webview) = wry_web_views.0.get(&window) else { | ||||||||||
| continue; | ||||||||||
| }; | ||||||||||
| #[allow(deprecated)] | ||||||||||
|
|
@@ -362,8 +365,7 @@ fn resize_webview_inner_window( | |||||||||
| let Some(ns_window) = ns_view.window() else { | ||||||||||
| continue; | ||||||||||
| }; | ||||||||||
| wry_webview | ||||||||||
| .ns_window() | ||||||||||
| .setFrame_display(ns_window.contentRectForFrameRect(ns_window.frame()), true); | ||||||||||
| let wry_ns_window = wry_webview.ns_window(); | ||||||||||
|
||||||||||
| let wry_ns_window = wry_webview.ns_window(); | |
| let wry_ns_window = wry_webview.ns_window(); | |
| // The `display` parameter is set to `false` to avoid immediate redraw of the window. | |
| // This is intentional to optimize performance, as the redraw is handled elsewhere. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using wildcard imports (
use bevy::prelude::*;) can make code less readable and may introduce naming conflicts. Consider importing only the specific items needed or using the previous explicit import style.