浏览代码

apply desktop cfg fix on multiwindow example

Lucas Nogueira 2 年之前
父节点
当前提交
ba61754cfe
共有 2 个文件被更改,包括 35 次插入24 次删除
  1. 31 0
      examples/multiwindow/src/desktop.rs
  2. 4 24
      examples/multiwindow/src/main.rs

+ 31 - 0
examples/multiwindow/src/desktop.rs

@@ -0,0 +1,31 @@
+// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT
+
+use tauri::WindowBuilder;
+
+pub fn main() {
+  tauri::Builder::default()
+    .on_page_load(|window, _payload| {
+      let label = window.label().to_string();
+      window.listen("clicked".to_string(), move |_payload| {
+        println!("got 'clicked' event on window '{label}'");
+      });
+    })
+    .setup(|app| {
+      #[allow(unused_mut)]
+      let mut builder = WindowBuilder::new(
+        app,
+        "Rust".to_string(),
+        tauri::WindowUrl::App("index.html".into()),
+      );
+      #[cfg(target_os = "macos")]
+      {
+        builder = builder.tabbing_identifier("Rust");
+      }
+      let _window = builder.title("Tauri - Rust").build()?;
+      Ok(())
+    })
+    .run(tauri::build_script_context!())
+    .expect("failed to run tauri application");
+}

+ 4 - 24
examples/multiwindow/src/main.rs

@@ -4,30 +4,10 @@
 
 #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
 
-use tauri::WindowBuilder;
+#[cfg(desktop)]
+mod desktop;
 
 fn main() {
-  tauri::Builder::default()
-    .on_page_load(|window, _payload| {
-      let label = window.label().to_string();
-      window.listen("clicked".to_string(), move |_payload| {
-        println!("got 'clicked' event on window '{label}'");
-      });
-    })
-    .setup(|app| {
-      #[allow(unused_mut)]
-      let mut builder = WindowBuilder::new(
-        app,
-        "Rust".to_string(),
-        tauri::WindowUrl::App("index.html".into()),
-      );
-      #[cfg(target_os = "macos")]
-      {
-        builder = builder.tabbing_identifier("Rust");
-      }
-      let _window = builder.title("Tauri - Rust").build()?;
-      Ok(())
-    })
-    .run(tauri::build_script_context!())
-    .expect("failed to run tauri application");
+  #[cfg(desktop)]
+  desktop::main();
 }