فهرست منبع

feat: add `focus` api

mrxiaozhuox 3 سال پیش
والد
کامیت
7ca92be015
2فایلهای تغییر یافته به همراه12 افزوده شده و 0 حذف شده
  1. 5 0
      packages/desktop/src/desktop_context.rs
  2. 7 0
      packages/desktop/src/lib.rs

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

@@ -52,6 +52,11 @@ impl DesktopContext {
     pub fn close(&self) {
     pub fn close(&self) {
         let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
         let _ = self.proxy.send_event(UserWindowEvent::CloseWindow);
     }
     }
+
+    /// set window to focus
+    pub fn focus(&self) {
+        let _ = self.proxy.send_event(UserWindowEvent::FocusWindow);
+    }
 }
 }
 
 
 /// use this function can get the `DesktopContext` context.
 /// use this function can get the `DesktopContext` context.

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

@@ -313,6 +313,12 @@ pub fn launch_with_props<P: 'static + Send>(
                             window.set_maximized(state);
                             window.set_maximized(state);
                         }
                         }
                     }
                     }
+                    UserWindowEvent::FocusWindow => {
+                        for webview in desktop.webviews.values() {
+                            let window = webview.window();
+                            window.set_focus();
+                        }
+                    }
                 }
                 }
             }
             }
             Event::MainEventsCleared => {}
             Event::MainEventsCleared => {}
@@ -329,6 +335,7 @@ pub enum UserWindowEvent {
     Update,
     Update,
     DragWindow,
     DragWindow,
     CloseWindow,
     CloseWindow,
+    FocusWindow,
     Minimize(bool),
     Minimize(bool),
     Maximize(bool),
     Maximize(bool),
 }
 }