소스 검색

feat: add window api

mrxiaozhuox 3 년 전
부모
커밋
01435d6aff
2개의 변경된 파일20개의 추가작업 그리고 11개의 파일을 삭제
  1. 4 2
      packages/desktop/src/desktop_context.rs
  2. 16 9
      packages/desktop/src/lib.rs

+ 4 - 2
packages/desktop/src/desktop_context.rs

@@ -71,8 +71,10 @@ impl DesktopContext {
     }
 
     /// hide the menu
-    pub fn hide_menu(&self) {
-        let _ = self.proxy.send_event(UserWindowEvent::HideMenu);
+    pub fn set_decorations(&self, decoration: bool) {
+        let _ = self
+            .proxy
+            .send_event(UserWindowEvent::SetDecorations(decoration));
     }
 }
 

+ 16 - 9
packages/desktop/src/lib.rs

@@ -72,7 +72,7 @@ use tao::{
 pub use wry;
 pub use wry::application as tao;
 use wry::{
-    application::event_loop::EventLoopProxy,
+    application::{event_loop::EventLoopProxy, window::Fullscreen},
     webview::RpcRequest,
     webview::{WebView, WebViewBuilder},
 };
@@ -315,17 +315,16 @@ pub fn launch_with_props<P: 'static + Send>(
                             window.set_maximized(state);
                         }
                     }
-                    UserWindowEvent::FocusWindow => {
+                    UserWindowEvent::Fullscreen(fullscreen) => {
                         for webview in desktop.webviews.values() {
                             let window = webview.window();
-                            window.set_focus();
+                            window.set_fullscreen(*fullscreen.clone());
                         }
                     }
-
-                    UserWindowEvent::SetTitle(content) => {
+                    UserWindowEvent::FocusWindow => {
                         for webview in desktop.webviews.values() {
                             let window = webview.window();
-                            window.set_title(&content);
+                            window.set_focus();
                         }
                     }
                     UserWindowEvent::Resizable(state) => {
@@ -334,10 +333,17 @@ pub fn launch_with_props<P: 'static + Send>(
                             window.set_resizable(state);
                         }
                     }
-                    UserWindowEvent::HideMenu => {
+
+                    UserWindowEvent::SetTitle(content) => {
+                        for webview in desktop.webviews.values() {
+                            let window = webview.window();
+                            window.set_title(&content);
+                        }
+                    }
+                    UserWindowEvent::SetDecorations(state) => {
                         for webview in desktop.webviews.values() {
                             let window = webview.window();
-                            window.hide_menu();
+                            window.set_decorations(state);
                         }
                     }
                 }
@@ -360,9 +366,10 @@ pub enum UserWindowEvent {
     Minimize(bool),
     Maximize(bool),
     Resizable(bool),
+    Fullscreen(Box<Option<Fullscreen>>),
 
     SetTitle(String),
-    HideMenu,
+    SetDecorations(bool),
 }
 
 pub struct DesktopController {