瀏覽代碼

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) {
         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.

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

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