浏览代码

refactor(core): remove window APIs on mobile (#5713)

Lucas Fernandes Nogueira 2 年之前
父节点
当前提交
fa6d10e39c
共有 3 个文件被更改,包括 51 次插入39 次删除
  1. 27 22
      core/tauri-runtime-wry/src/lib.rs
  2. 15 11
      core/tauri/src/window.rs
  3. 9 6
      examples/api/src-tauri/src/lib.rs

+ 27 - 22
core/tauri-runtime-wry/src/lib.rs

@@ -696,17 +696,7 @@ impl WindowBuilder for WindowBuilderWrapper {
   }
 
   fn with_config(config: WindowConfig) -> Self {
-    let mut window = WindowBuilderWrapper::new()
-      .title(config.title.to_string())
-      .inner_size(config.width, config.height)
-      .visible(config.visible)
-      .resizable(config.resizable)
-      .fullscreen(config.fullscreen)
-      .decorations(config.decorations)
-      .maximized(config.maximized)
-      .always_on_top(config.always_on_top)
-      .skip_taskbar(config.skip_taskbar)
-      .theme(config.theme);
+    let mut window = WindowBuilderWrapper::new();
 
     #[cfg(target_os = "macos")]
     {
@@ -734,18 +724,33 @@ impl WindowBuilder for WindowBuilderWrapper {
       ");
     }
 
-    if let (Some(min_width), Some(min_height)) = (config.min_width, config.min_height) {
-      window = window.min_inner_size(min_width, min_height);
-    }
-    if let (Some(max_width), Some(max_height)) = (config.max_width, config.max_height) {
-      window = window.max_inner_size(max_width, max_height);
-    }
-    if let (Some(x), Some(y)) = (config.x, config.y) {
-      window = window.position(x, y);
-    }
+    #[cfg(desktop)]
+    {
+      window = window
+        .title(config.title.to_string())
+        .inner_size(config.width, config.height)
+        .visible(config.visible)
+        .resizable(config.resizable)
+        .fullscreen(config.fullscreen)
+        .decorations(config.decorations)
+        .maximized(config.maximized)
+        .always_on_top(config.always_on_top)
+        .skip_taskbar(config.skip_taskbar)
+        .theme(config.theme);
+
+      if let (Some(min_width), Some(min_height)) = (config.min_width, config.min_height) {
+        window = window.min_inner_size(min_width, min_height);
+      }
+      if let (Some(max_width), Some(max_height)) = (config.max_width, config.max_height) {
+        window = window.max_inner_size(max_width, max_height);
+      }
+      if let (Some(x), Some(y)) = (config.x, config.y) {
+        window = window.position(x, y);
+      }
 
-    if config.center {
-      window = window.center();
+      if config.center {
+        window = window.center();
+      }
     }
 
     window

+ 15 - 11
core/tauri/src/window.rs

@@ -262,9 +262,11 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
 
     Ok(window)
   }
+}
 
-  // --------------------------------------------- Window builder ---------------------------------------------
-
+/// Desktop APIs.
+#[cfg(desktop)]
+impl<'a, R: Runtime> WindowBuilder<'a, R> {
   /// Sets the menu for the window.
   #[must_use]
   pub fn menu(mut self, menu: Menu) -> Self {
@@ -475,8 +477,16 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
     self
   }
 
-  // ------------------------------------------- Webview attributes -------------------------------------------
+  /// Sets whether clicking an inactive window also clicks through to the webview.
+  #[must_use]
+  pub fn accept_first_mouse(mut self, accept: bool) -> Self {
+    self.webview_attributes.accept_first_mouse = accept;
+    self
+  }
+}
 
+/// Webview attributes.
+impl<'a, R: Runtime> WindowBuilder<'a, R> {
   /// Adds the provided JavaScript to a list of scripts that should be run after the global object has been created,
   /// but before the HTML document has been parsed and before any other script included by the HTML document is run.
   ///
@@ -548,13 +558,6 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
     self.webview_attributes.clipboard = true;
     self
   }
-
-  /// Sets whether clicking an inactive window also clicks through to the webview.
-  #[must_use]
-  pub fn accept_first_mouse(mut self, accept: bool) -> Self {
-    self.webview_attributes.accept_first_mouse = accept;
-    self
-  }
 }
 
 // TODO: expand these docs since this is a pretty important type
@@ -1016,7 +1019,8 @@ impl<R: Runtime> Window<R> {
   }
 }
 
-/// Window setters and actions.
+/// Desktop window setters and actions.
+#[cfg(desktop)]
 impl<R: Runtime> Window<R> {
   /// Centers the window.
   pub fn center(&self) -> crate::Result<()> {

+ 9 - 6
examples/api/src-tauri/src/lib.rs

@@ -65,12 +65,15 @@ impl AppBuilder {
           (setup)(app)?;
         }
 
-        #[allow(unused_mut)]
-        let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default())
-          .user_agent("Tauri API")
-          .title("Tauri API Validation")
-          .inner_size(1000., 800.)
-          .min_inner_size(600., 400.);
+        let mut window_builder = WindowBuilder::new(app, "main", WindowUrl::default());
+        #[cfg(desktop)]
+        {
+          window_builder = window_builder
+            .user_agent("Tauri API")
+            .title("Tauri API Validation")
+            .inner_size(1000., 800.)
+            .min_inner_size(600., 400.);
+        }
 
         #[cfg(target_os = "windows")]
         {