@@ -792,19 +792,19 @@ fn main() {
792792/// Webview.
793793#[ default_runtime( crate :: Wry , wry) ]
794794pub struct Webview < R : Runtime > {
795- window_label : Arc < Mutex < String > > ,
795+ pub ( crate ) window : Arc < Mutex < Window < R > > > ,
796+ /// The webview created by the runtime.
797+ pub ( crate ) webview : DetachedWebview < EventLoopMessage , R > ,
796798 /// The manager to associate this webview with.
797799 pub ( crate ) manager : Arc < AppManager < R > > ,
798800 pub ( crate ) app_handle : AppHandle < R > ,
799- /// The webview created by the runtime.
800- pub ( crate ) webview : DetachedWebview < EventLoopMessage , R > ,
801801 pub ( crate ) resources_table : Arc < Mutex < ResourceTable > > ,
802802}
803803
804804impl < R : Runtime > std:: fmt:: Debug for Webview < R > {
805805 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
806806 f. debug_struct ( "Window" )
807- . field ( "window_label " , & self . window_label )
807+ . field ( "window " , & self . window . lock ( ) . unwrap ( ) )
808808 . field ( "webview" , & self . webview )
809809 . finish ( )
810810 }
@@ -813,10 +813,10 @@ impl<R: Runtime> std::fmt::Debug for Webview<R> {
813813impl < R : Runtime > Clone for Webview < R > {
814814 fn clone ( & self ) -> Self {
815815 Self {
816- window_label : self . window_label . clone ( ) ,
816+ window : self . window . clone ( ) ,
817+ webview : self . webview . clone ( ) ,
817818 manager : self . manager . clone ( ) ,
818819 app_handle : self . app_handle . clone ( ) ,
819- webview : self . webview . clone ( ) ,
820820 resources_table : self . resources_table . clone ( ) ,
821821 }
822822 }
@@ -842,9 +842,9 @@ impl<R: Runtime> Webview<R> {
842842 /// Create a new webview that is attached to the window.
843843 pub ( crate ) fn new ( window : Window < R > , webview : DetachedWebview < EventLoopMessage , R > ) -> Self {
844844 Self {
845- window_label : Arc :: new ( Mutex :: new ( window. label ( ) . into ( ) ) ) ,
846845 manager : window. manager . clone ( ) ,
847846 app_handle : window. app_handle . clone ( ) ,
847+ window : Arc :: new ( Mutex :: new ( window) ) ,
848848 webview,
849849 resources_table : Default :: default ( ) ,
850850 }
@@ -957,14 +957,13 @@ impl<R: Runtime> Webview<R> {
957957 pub fn reparent ( & self , window : & Window < R > ) -> crate :: Result < ( ) > {
958958 #[ cfg( not( feature = "unstable" ) ) ]
959959 {
960- let current_window = self . window ( ) ;
961- if current_window. is_webview_window ( ) || window. is_webview_window ( ) {
960+ if self . window_ref ( ) . is_webview_window ( ) || window. is_webview_window ( ) {
962961 return Err ( crate :: Error :: CannotReparentWebviewWindow ) ;
963962 }
964963 }
965964
965+ * self . window . lock ( ) . unwrap ( ) = window. clone ( ) ;
966966 self . webview . dispatcher . reparent ( window. window . id ) ?;
967- * self . window_label . lock ( ) . unwrap ( ) = window. label ( ) . to_string ( ) ;
968967 Ok ( ( ) )
969968 }
970969
@@ -1000,14 +999,16 @@ impl<R: Runtime> Webview<R> {
1000999impl < R : Runtime > Webview < R > {
10011000 /// The window that is hosting this webview.
10021001 pub fn window ( & self ) -> Window < R > {
1003- self
1004- . manager
1005- . get_window ( & self . window_label . lock ( ) . unwrap ( ) )
1006- . expect ( "could not locate webview parent window" )
1002+ self . window . lock ( ) . unwrap ( ) . clone ( )
1003+ }
1004+
1005+ /// A reference to the window that is hosting this webview.
1006+ pub fn window_ref ( & self ) -> MutexGuard < ' _ , Window < R > > {
1007+ self . window . lock ( ) . unwrap ( )
10071008 }
10081009
10091010 pub ( crate ) fn window_label ( & self ) -> String {
1010- self . window_label . lock ( ) . unwrap ( ) . clone ( )
1011+ self . window_ref ( ) . label ( ) . to_string ( )
10111012 }
10121013
10131014 /// Executes a closure, providing it with the webview handle that is specific to the current platform.
@@ -1193,7 +1194,7 @@ fn main() {
11931194 let runtime_authority = manager. runtime_authority . lock ( ) . unwrap ( ) ;
11941195 let acl = runtime_authority. resolve_access (
11951196 & request. cmd ,
1196- message. webview . window ( ) . label ( ) ,
1197+ message. webview . window_ref ( ) . label ( ) ,
11971198 message. webview . label ( ) ,
11981199 & acl_origin,
11991200 ) ;
0 commit comments