ソースを参照

feat: add window api

mrxiaozhuox 3 年 前
コミット
81ea7a1428
2 ファイル変更37 行追加0 行削除
  1. 14 0
      packages/desktop/src/desktop_context.rs
  2. 23 0
      packages/desktop/src/lib.rs

+ 14 - 0
packages/desktop/src/desktop_context.rs

@@ -48,6 +48,10 @@ impl DesktopContext {
         let _ = self.proxy.send_event(UserWindowEvent::Maximize(maximized));
     }
 
+    pub fn visible(&self, visible: bool) {
+        let _ = self.proxy.send_event(UserWindowEvent::Visible(visible));
+    }
+
     /// close window
     pub fn close(&self) {
         let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
@@ -63,6 +67,16 @@ impl DesktopContext {
         let _ = self.proxy.send_event(UserWindowEvent::Resizable(resizable));
     }
 
+    pub fn always_on_top(&self, top: bool) {
+        let _ = self.proxy.send_event(UserWindowEvent::AlwaysOnTop(top));
+    }
+
+    pub fn cursor_visible(&self, visible: bool) {
+        let _ = self
+            .proxy
+            .send_event(UserWindowEvent::CursorVisible(visible));
+    }
+
     /// set window title
     pub fn set_title(&self, title: &str) {
         let _ = self

+ 23 - 0
packages/desktop/src/lib.rs

@@ -299,6 +299,12 @@ pub fn launch_with_props<P: 'static + Send>(
                         // close window
                         *control_flow = ControlFlow::Exit;
                     }
+                    UserWindowEvent::Visible(state) => {
+                        for webview in desktop.webviews.values() {
+                            let window = webview.window();
+                            window.set_visible(state);
+                        }
+                    }
                     UserWindowEvent::Minimize(state) => {
                         // this loop just run once, because dioxus-desktop is unsupport multi-window.
                         for webview in desktop.webviews.values() {
@@ -333,6 +339,19 @@ pub fn launch_with_props<P: 'static + Send>(
                             window.set_resizable(state);
                         }
                     }
+                    UserWindowEvent::AlwaysOnTop(state) => {
+                        for webview in desktop.webviews.values() {
+                            let window = webview.window();
+                            window.set_always_on_top(state);
+                        }
+                    }
+
+                    UserWindowEvent::CursorVisible(state) => {
+                        for webview in desktop.webviews.values() {
+                            let window = webview.window();
+                            window.set_cursor_visible(state);
+                        }
+                    }
 
                     UserWindowEvent::SetTitle(content) => {
                         for webview in desktop.webviews.values() {
@@ -363,11 +382,15 @@ pub enum UserWindowEvent {
     DragWindow,
     CloseWindow,
     FocusWindow,
+    Visible(bool),
     Minimize(bool),
     Maximize(bool),
     Resizable(bool),
+    AlwaysOnTop(bool),
     Fullscreen(Box<Option<Fullscreen>>),
 
+    CursorVisible(bool),
+
     SetTitle(String),
     SetDecorations(bool),
 }