Jelajahi Sumber

feat(core): prepare build for mobile targets (#4830)

Co-authored-by: Yu-Wei Wu <wusyong9104@gmail.com>
Lucas Fernandes Nogueira 3 tahun lalu
induk
melakukan
c04d0340e2

+ 5 - 0
.changes/build-platform-alias.md

@@ -0,0 +1,5 @@
+---
+"tauri-build": patch
+---
+
+Create the `desktop` and `mobile` cfg aliases.

+ 5 - 0
core/tauri-build/src/lib.rs

@@ -203,6 +203,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
   #[cfg(feature = "config-json5")]
   println!("cargo:rerun-if-changed=tauri.conf.json5");
 
+  let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
+  let mobile = target_os == "ios" || target_os == "android";
+  cfg_alias("desktop", !mobile);
+  cfg_alias("mobile", mobile);
+
   let mut config = serde_json::from_value(tauri_utils::config::parse::read_from(
     std::env::current_dir().unwrap(),
   )?)?;

+ 1 - 0
core/tauri-codegen/src/context.rs

@@ -523,6 +523,7 @@ fn png_icon<P: AsRef<Path>>(
   Ok(icon)
 }
 
+#[cfg(any(windows, target_os = "macos", target_os = "linux"))]
 fn find_icon<F: Fn(&&String) -> bool>(
   config: &Config,
   config_parent: &Path,

+ 18 - 0
core/tauri-runtime-wry/build.rs

@@ -0,0 +1,18 @@
+// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT
+
+// creates a cfg alias if `has_feature` is true.
+// `alias` must be a snake case string.
+fn alias(alias: &str, has_feature: bool) {
+  if has_feature {
+    println!("cargo:rustc-cfg={}", alias);
+  }
+}
+
+fn main() {
+  let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
+  let mobile = target_os == "ios" || target_os == "android";
+  alias("desktop", !mobile);
+  alias("mobile", mobile);
+}

+ 3 - 3
core/tauri-runtime-wry/src/global_shortcut.rs

@@ -16,10 +16,10 @@ use std::{
 use crate::{getter, Context, Message};
 
 use tauri_runtime::{Error, GlobalShortcutManager, Result, UserEvent};
-pub use wry::application::global_shortcut::ShortcutManager as WryShortcutManager;
-use wry::application::{
+#[cfg(desktop)]
+pub use wry::application::{
   accelerator::{Accelerator, AcceleratorId},
-  global_shortcut::GlobalShortcut,
+  global_shortcut::{GlobalShortcut, ShortcutManager as WryShortcutManager},
 };
 
 pub type GlobalShortcutListeners = Arc<Mutex<HashMap<AcceleratorId, Box<dyn Fn() + Send>>>>;

+ 77 - 66
core/tauri-runtime-wry/src/lib.rs

@@ -22,7 +22,7 @@ use tauri_runtime::{
 };
 
 use tauri_runtime::window::MenuEvent;
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 use tauri_runtime::{SystemTray, SystemTrayEvent};
 #[cfg(windows)]
 use webview2_com::FocusChangedEventHandler;
@@ -37,7 +37,7 @@ use wry::application::platform::unix::{WindowBuilderExtUnix, WindowExtUnix};
 #[cfg(windows)]
 use wry::application::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 use wry::application::system_tray::{SystemTray as WrySystemTray, SystemTrayBuilder};
 
 use tauri_utils::{config::WindowConfig, debug_eprintln, Theme};
@@ -105,17 +105,19 @@ pub type WebviewId = u64;
 type IpcHandler = dyn Fn(&Window, String) + 'static;
 type FileDropHandler = dyn Fn(&Window, WryFileDropEvent) -> bool + 'static;
 
+#[cfg(desktop)]
 mod webview;
+#[cfg(desktop)]
 pub use webview::Webview;
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 mod system_tray;
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 use system_tray::*;
 
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 mod global_shortcut;
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 use global_shortcut::*;
 
 #[cfg(feature = "clipboard")]
@@ -173,12 +175,12 @@ fn send_user_message<T: UserEvent>(context: &Context<T>, message: Message<T>) ->
       UserMessageContext {
         marker: &PhantomData,
         webview_id_map: context.webview_id_map.clone(),
-        #[cfg(feature = "global-shortcut")]
+        #[cfg(all(desktop, feature = "global-shortcut"))]
         global_shortcut_manager: context.main_thread.global_shortcut_manager.clone(),
         #[cfg(feature = "clipboard")]
         clipboard_manager: context.main_thread.clipboard_manager.clone(),
         windows: context.main_thread.windows.clone(),
-        #[cfg(feature = "system-tray")]
+        #[cfg(all(desktop, feature = "system-tray"))]
         tray_context: &context.main_thread.tray_context,
       },
       &context.main_thread.web_context,
@@ -248,12 +250,12 @@ impl<T: UserEvent> Context<T> {
 pub struct DispatcherMainThreadContext<T: UserEvent> {
   pub window_target: EventLoopWindowTarget<Message<T>>,
   pub web_context: WebContextStore,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
   #[cfg(feature = "clipboard")]
   pub clipboard_manager: Arc<Mutex<Clipboard>>,
   pub windows: Arc<Mutex<HashMap<WebviewId, WindowWrapper>>>,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   pub tray_context: TrayContext,
 }
 
@@ -898,7 +900,7 @@ impl WindowBuilder for WindowBuilderWrapper {
     self
   }
 
-  #[cfg(target_os = "macos")]
+  #[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
   fn skip_taskbar(self, _skip: bool) -> Self {
     self
   }
@@ -996,6 +998,7 @@ pub struct RawWindowHandle(pub raw_window_handle::RawWindowHandle);
 unsafe impl Send for RawWindowHandle {}
 
 pub enum WindowMessage {
+  #[cfg(desktop)]
   WithWebview(Box<dyn FnOnce(Webview) + Send>),
   AddEventListener(Uuid, Box<dyn Fn(&WindowEvent) + Send>),
   AddMenuEventListener(Uuid, Box<dyn Fn(&MenuEvent) + Send>),
@@ -1078,7 +1081,7 @@ pub enum WebviewEvent {
   Focused(bool),
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 #[derive(Debug, Clone)]
 pub enum TrayMessage {
   UpdateItem(u16, MenuUpdate),
@@ -1097,7 +1100,7 @@ pub enum Message<T: 'static> {
   Task(Box<dyn FnOnce() + Send>),
   Window(WebviewId, WindowMessage),
   Webview(WebviewId, WebviewMessage),
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   Tray(TrayMessage),
   CreateWebview(WebviewId, CreateWebviewClosure<T>),
   CreateWindow(
@@ -1105,7 +1108,7 @@ pub enum Message<T: 'static> {
     Box<dyn FnOnce() -> (String, WryWindowBuilder) + Send>,
     Sender<Result<Weak<Window>>>,
   ),
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   GlobalShortcut(GlobalShortcutMessage),
   #[cfg(feature = "clipboard")]
   Clipboard(ClipboardMessage),
@@ -1116,9 +1119,9 @@ impl<T: UserEvent> Clone for Message<T> {
   fn clone(&self) -> Self {
     match self {
       Self::Webview(i, m) => Self::Webview(*i, m.clone()),
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       Self::Tray(m) => Self::Tray(m.clone()),
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       Self::GlobalShortcut(m) => Self::GlobalShortcut(m.clone()),
       #[cfg(feature = "clipboard")]
       Self::Clipboard(m) => Self::Clipboard(m.clone()),
@@ -1140,6 +1143,7 @@ pub struct WryDispatcher<T: UserEvent> {
 unsafe impl<T: UserEvent> Sync for WryDispatcher<T> {}
 
 impl<T: UserEvent> WryDispatcher<T> {
+  #[cfg(desktop)]
   pub fn with_webview<F: FnOnce(Webview) + Send + 'static>(&self, f: F) -> Result<()> {
     send_user_message(
       &self.context,
@@ -1524,7 +1528,7 @@ impl<T: UserEvent> Dispatch<T> for WryDispatcher<T> {
   }
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 #[derive(Clone, Default)]
 pub struct TrayContext {
   tray: Arc<Mutex<Option<Arc<Mutex<WrySystemTray>>>>>,
@@ -1532,7 +1536,7 @@ pub struct TrayContext {
   items: SystemTrayItems,
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 impl fmt::Debug for TrayContext {
   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     f.debug_struct("TrayContext")
@@ -1595,6 +1599,10 @@ impl fmt::Debug for WindowWrapper {
 #[derive(Debug, Clone)]
 pub struct EventProxy<T: UserEvent>(WryEventLoopProxy<Message<T>>);
 
+#[cfg(target_os = "ios")]
+#[allow(clippy::non_send_fields_in_send_ty)]
+unsafe impl<T: UserEvent> Sync for EventProxy<T> {}
+
 impl<T: UserEvent> EventLoopProxy<T> for EventProxy<T> {
   fn send_event(&self, event: T) -> Result<()> {
     self
@@ -1627,7 +1635,7 @@ pub struct Wry<T: UserEvent> {
 
   plugins: Vec<Box<dyn Plugin<T>>>,
 
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   global_shortcut_manager_handle: GlobalShortcutManagerHandle<T>,
 
   #[cfg(feature = "clipboard")]
@@ -1644,9 +1652,10 @@ impl<T: UserEvent> fmt::Debug for Wry<T> {
       .field("windows", &self.context.main_thread.windows)
       .field("web_context", &self.context.main_thread.web_context);
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     d.field("tray_context", &self.context.main_thread.tray_context);
 
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     #[cfg(feature = "global-shortcut")]
     d.field(
       "global_shortcut_manager",
@@ -1750,7 +1759,7 @@ impl<T: UserEvent> Wry<T> {
     let main_thread_id = current_thread().id();
     let web_context = WebContextStore::default();
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager = Arc::new(Mutex::new(WryShortcutManager::new(&event_loop)));
 
     #[cfg(feature = "clipboard")]
@@ -1759,7 +1768,7 @@ impl<T: UserEvent> Wry<T> {
     let windows = Arc::new(Mutex::new(HashMap::default()));
     let webview_id_map = WebviewIdStore::default();
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     let tray_context = TrayContext::default();
 
     let context = Context {
@@ -1769,17 +1778,17 @@ impl<T: UserEvent> Wry<T> {
       main_thread: DispatcherMainThreadContext {
         window_target: event_loop.deref().clone(),
         web_context,
-        #[cfg(feature = "global-shortcut")]
+        #[cfg(all(desktop, feature = "global-shortcut"))]
         global_shortcut_manager,
         #[cfg(feature = "clipboard")]
         clipboard_manager,
         windows,
-        #[cfg(feature = "system-tray")]
+        #[cfg(all(desktop, feature = "system-tray"))]
         tray_context,
       },
     };
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager_handle = GlobalShortcutManagerHandle {
       context: context.clone(),
       shortcuts: Default::default(),
@@ -1797,7 +1806,7 @@ impl<T: UserEvent> Wry<T> {
 
       plugins: Default::default(),
 
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       global_shortcut_manager_handle,
 
       #[cfg(feature = "clipboard")]
@@ -1818,13 +1827,13 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
   type Dispatcher = WryDispatcher<T>;
   type Handle = WryHandle<T>;
 
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   type GlobalShortcutManager = GlobalShortcutManagerHandle<T>;
 
   #[cfg(feature = "clipboard")]
   type ClipboardManager = ClipboardManagerWrapper<T>;
 
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   type TrayHandler = SystemTrayHandle<T>;
 
   type EventLoopProxy = EventProxy<T>;
@@ -1854,7 +1863,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
     }
   }
 
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   fn global_shortcut_manager(&self) -> Self::GlobalShortcutManager {
     self.global_shortcut_manager_handle.clone()
   }
@@ -1899,7 +1908,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
     })
   }
 
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   fn system_tray(&self, system_tray: SystemTray) -> Result<Self::TrayHandler> {
     let icon = TrayIcon::try_from(system_tray.icon.expect("tray icon not set"))?;
 
@@ -1932,7 +1941,7 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
     })
   }
 
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   fn on_system_tray_event<F: Fn(&SystemTrayEvent) + Send + 'static>(&mut self, f: F) -> Uuid {
     let id = Uuid::new_v4();
     self
@@ -1958,18 +1967,19 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
       });
   }
 
+  #[cfg(desktop)]
   fn run_iteration<F: FnMut(RunEvent<T>) + 'static>(&mut self, mut callback: F) -> RunIteration {
     use wry::application::platform::run_return::EventLoopExtRunReturn;
     let windows = self.context.main_thread.windows.clone();
     let webview_id_map = self.context.webview_id_map.clone();
     let web_context = &self.context.main_thread.web_context;
     let plugins = &mut self.plugins;
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     let tray_context = self.context.main_thread.tray_context.clone();
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager = self.context.main_thread.global_shortcut_manager.clone();
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager_handle = self.global_shortcut_manager_handle.clone();
 
     #[cfg(feature = "clipboard")]
@@ -1996,13 +2006,13 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
               callback: &mut callback,
               webview_id_map: webview_id_map.clone(),
               windows: windows.clone(),
-              #[cfg(feature = "global-shortcut")]
+              #[cfg(all(desktop, feature = "global-shortcut"))]
               global_shortcut_manager: global_shortcut_manager.clone(),
-              #[cfg(feature = "global-shortcut")]
+              #[cfg(all(desktop, feature = "global-shortcut"))]
               global_shortcut_manager_handle: &global_shortcut_manager_handle,
               #[cfg(feature = "clipboard")]
               clipboard_manager: clipboard_manager.clone(),
-              #[cfg(feature = "system-tray")]
+              #[cfg(all(desktop, feature = "system-tray"))]
               tray_context: &tray_context,
             },
             web_context,
@@ -2020,13 +2030,13 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
             callback: &mut callback,
             windows: windows.clone(),
             webview_id_map: webview_id_map.clone(),
-            #[cfg(feature = "global-shortcut")]
+            #[cfg(all(desktop, feature = "global-shortcut"))]
             global_shortcut_manager: global_shortcut_manager.clone(),
-            #[cfg(feature = "global-shortcut")]
+            #[cfg(all(desktop, feature = "global-shortcut"))]
             global_shortcut_manager_handle: &global_shortcut_manager_handle,
             #[cfg(feature = "clipboard")]
             clipboard_manager: clipboard_manager.clone(),
-            #[cfg(feature = "system-tray")]
+            #[cfg(all(desktop, feature = "system-tray"))]
             tray_context: &tray_context,
           },
           web_context,
@@ -2042,12 +2052,12 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
     let web_context = self.context.main_thread.web_context;
     let mut plugins = self.plugins;
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     let tray_context = self.context.main_thread.tray_context;
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager = self.context.main_thread.global_shortcut_manager.clone();
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager_handle = self.global_shortcut_manager_handle.clone();
 
     #[cfg(feature = "clipboard")]
@@ -2066,13 +2076,13 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
             callback: &mut callback,
             webview_id_map: webview_id_map.clone(),
             windows: windows.clone(),
-            #[cfg(feature = "global-shortcut")]
+            #[cfg(all(desktop, feature = "global-shortcut"))]
             global_shortcut_manager: global_shortcut_manager.clone(),
-            #[cfg(feature = "global-shortcut")]
+            #[cfg(all(desktop, feature = "global-shortcut"))]
             global_shortcut_manager_handle: &global_shortcut_manager_handle,
             #[cfg(feature = "clipboard")]
             clipboard_manager: clipboard_manager.clone(),
-            #[cfg(feature = "system-tray")]
+            #[cfg(all(desktop, feature = "system-tray"))]
             tray_context: &tray_context,
           },
           &web_context,
@@ -2089,13 +2099,13 @@ impl<T: UserEvent> Runtime<T> for Wry<T> {
           callback: &mut callback,
           webview_id_map: webview_id_map.clone(),
           windows: windows.clone(),
-          #[cfg(feature = "global-shortcut")]
+          #[cfg(all(desktop, feature = "global-shortcut"))]
           global_shortcut_manager: global_shortcut_manager.clone(),
-          #[cfg(feature = "global-shortcut")]
+          #[cfg(all(desktop, feature = "global-shortcut"))]
           global_shortcut_manager_handle: &global_shortcut_manager_handle,
           #[cfg(feature = "clipboard")]
           clipboard_manager: clipboard_manager.clone(),
-          #[cfg(feature = "system-tray")]
+          #[cfg(all(desktop, feature = "system-tray"))]
           tray_context: &tray_context,
         },
         &web_context,
@@ -2108,13 +2118,13 @@ pub struct EventLoopIterationContext<'a, T: UserEvent> {
   pub callback: &'a mut (dyn FnMut(RunEvent<T>) + 'static),
   pub webview_id_map: WebviewIdStore,
   pub windows: Arc<Mutex<HashMap<WebviewId, WindowWrapper>>>,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   pub global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   pub global_shortcut_manager_handle: &'a GlobalShortcutManagerHandle<T>,
   #[cfg(feature = "clipboard")]
   pub clipboard_manager: Arc<Mutex<Clipboard>>,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   pub tray_context: &'a TrayContext,
 }
 
@@ -2122,12 +2132,12 @@ struct UserMessageContext<'a> {
   #[allow(dead_code)]
   marker: &'a PhantomData<()>,
   webview_id_map: WebviewIdStore,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   global_shortcut_manager: Arc<Mutex<WryShortcutManager>>,
   #[cfg(feature = "clipboard")]
   clipboard_manager: Arc<Mutex<Clipboard>>,
   windows: Arc<Mutex<HashMap<WebviewId, WindowWrapper>>>,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   tray_context: &'a TrayContext,
 }
 
@@ -2140,12 +2150,12 @@ fn handle_user_message<T: UserEvent>(
   let UserMessageContext {
     marker: _,
     webview_id_map,
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     global_shortcut_manager,
     #[cfg(feature = "clipboard")]
     clipboard_manager,
     windows,
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     tray_context,
   } = context;
   match message {
@@ -2184,6 +2194,7 @@ fn handle_user_message<T: UserEvent>(
         {
           drop(windows_lock);
           match window_message {
+            #[cfg(desktop)]
             WindowMessage::WithWebview(f) => {
               if let WindowHandle::Webview(w) = window {
                 #[cfg(any(
@@ -2449,7 +2460,7 @@ fn handle_user_message<T: UserEvent>(
       }
     }
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     Message::Tray(tray_message) => match tray_message {
       TrayMessage::UpdateItem(menu_id, update) => {
         let mut tray = tray_context.items.as_ref().lock().unwrap();
@@ -2493,7 +2504,7 @@ fn handle_user_message<T: UserEvent>(
         tray_context.items.lock().unwrap().clear();
       }
     },
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     Message::GlobalShortcut(message) => {
       handle_global_shortcut_message(message, &global_shortcut_manager)
     }
@@ -2519,13 +2530,13 @@ fn handle_event_loop<T: UserEvent>(
     callback,
     webview_id_map,
     windows,
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     global_shortcut_manager,
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     global_shortcut_manager_handle,
     #[cfg(feature = "clipboard")]
     clipboard_manager,
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     tray_context,
   } = context;
   if *control_flow != ControlFlow::Exit {
@@ -2549,7 +2560,7 @@ fn handle_event_loop<T: UserEvent>(
       callback(RunEvent::Exit);
     }
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     Event::GlobalShortcutEvent(accelerator_id) => {
       for (id, handler) in &*global_shortcut_manager_handle.listeners.lock().unwrap() {
         if accelerator_id == *id {
@@ -2599,7 +2610,7 @@ fn handle_event_loop<T: UserEvent>(
         handler(&event);
       }
     }
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     Event::MenuEvent {
       window_id: _,
       menu_id,
@@ -2612,7 +2623,7 @@ fn handle_event_loop<T: UserEvent>(
         handler(&event);
       }
     }
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     Event::TrayEvent {
       bounds,
       event,
@@ -2712,12 +2723,12 @@ fn handle_event_loop<T: UserEvent>(
           UserMessageContext {
             marker: &PhantomData,
             webview_id_map,
-            #[cfg(feature = "global-shortcut")]
+            #[cfg(all(desktop, feature = "global-shortcut"))]
             global_shortcut_manager,
             #[cfg(feature = "clipboard")]
             clipboard_manager,
             windows,
-            #[cfg(feature = "system-tray")]
+            #[cfg(all(desktop, feature = "system-tray"))]
             tray_context,
           },
           web_context,

+ 18 - 0
core/tauri-runtime/build.rs

@@ -0,0 +1,18 @@
+// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-License-Identifier: MIT
+
+// creates a cfg alias if `has_feature` is true.
+// `alias` must be a snake case string.
+fn alias(alias: &str, has_feature: bool) {
+  if has_feature {
+    println!("cargo:rustc-cfg={}", alias);
+  }
+}
+
+fn main() {
+  let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
+  let mobile = target_os == "ios" || target_os == "android";
+  alias("desktop", !mobile);
+  alias("mobile", mobile);
+}

+ 11 - 10
core/tauri-runtime/src/lib.rs

@@ -34,7 +34,7 @@ use crate::http::{
   InvalidUri,
 };
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 #[non_exhaustive]
 #[derive(Debug, Default)]
 pub struct SystemTray {
@@ -46,7 +46,7 @@ pub struct SystemTray {
   pub menu_on_left_click: bool,
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 impl SystemTray {
   /// Creates a new system tray that only renders an icon.
   pub fn new() -> Self {
@@ -124,7 +124,7 @@ pub enum Error {
   #[error("JSON error: {0}")]
   Json(#[from] serde_json::Error),
   /// Encountered an error creating the app system tray.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   #[error("error encountered during tray setup: {0}")]
   SystemTray(Box<dyn std::error::Error + Send + Sync>),
@@ -135,7 +135,7 @@ pub enum Error {
   #[error("failed to get monitor")]
   FailedToGetMonitor,
   /// Global shortcut error.
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   #[error(transparent)]
   GlobalShortcut(Box<dyn std::error::Error + Send + Sync>),
   #[error("Invalid header name: {0}")]
@@ -269,7 +269,7 @@ pub trait RuntimeHandle<T: UserEvent>: Debug + Clone + Send + Sync + Sized + 'st
 }
 
 /// A global shortcut manager.
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 pub trait GlobalShortcutManager: Debug + Clone + Send + Sync {
   /// Whether the application has registered the given `accelerator`.
   fn is_registered(&self, accelerator: &str) -> Result<bool>;
@@ -304,13 +304,13 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
   /// The runtime handle type.
   type Handle: RuntimeHandle<T, Runtime = Self>;
   /// The global shortcut manager type.
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   type GlobalShortcutManager: GlobalShortcutManager;
   /// The clipboard manager type.
   #[cfg(feature = "clipboard")]
   type ClipboardManager: ClipboardManager;
   /// The tray handler type.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   type TrayHandler: menu::TrayHandle;
   /// The proxy type.
   type EventLoopProxy: EventLoopProxy<T>;
@@ -330,7 +330,7 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
   fn handle(&self) -> Self::Handle;
 
   /// Gets the global shortcut manager.
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   fn global_shortcut_manager(&self) -> Self::GlobalShortcutManager;
 
   /// Gets the clipboard manager.
@@ -341,12 +341,12 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
   fn create_window(&self, pending: PendingWindow<T, Self>) -> Result<DetachedWindow<T, Self>>;
 
   /// Adds the icon to the system tray with the specified menu items.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   fn system_tray(&self, system_tray: SystemTray) -> Result<Self::TrayHandler>;
 
   /// Registers a system tray event handler.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   fn on_system_tray_event<F: Fn(&SystemTrayEvent) + Send + 'static>(&mut self, f: F) -> Uuid;
 
@@ -356,6 +356,7 @@ pub trait Runtime<T: UserEvent>: Debug + Sized + 'static {
   fn set_activation_policy(&mut self, activation_policy: ActivationPolicy);
 
   /// Runs the one step of the webview runtime event loop and returns control flow to the caller.
+  #[cfg(desktop)]
   fn run_iteration<F: Fn(RunEvent<T>) + 'static>(&mut self, callback: F) -> RunIteration;
 
   /// Run the webview runtime.

+ 7 - 5
core/tauri/Cargo.toml

@@ -73,14 +73,12 @@ dirs-next = "2.0"
 percent-encoding = "2.1"
 base64 = { version = "0.13", optional = true }
 clap = { version = "3", optional = true }
-notify-rust = { version = "4.5", default-features = false, features = [ "d" ], optional = true }
 reqwest = { version = "0.11", features = [ "json", "stream" ], optional = true }
 bytes = { version = "1", features = [ "serde" ], optional = true }
 attohttpc = { version = "0.19", features = [ "json", "form" ], optional = true }
 open = { version = "3.0", optional = true }
 shared_child = { version = "1.0", optional = true }
 os_pipe = { version = "1.0", optional = true }
-rfd = { version = "0.10", optional = true }
 raw-window-handle = "0.5"
 minisign-verify = { version = "0.2", optional = true }
 time = { version = "0.3", features = [ "parsing", "formatting" ], optional = true }
@@ -95,6 +93,10 @@ png = { version = "0.17", optional = true }
 ico = { version = "0.1", optional = true }
 encoding_rs = "0.8.31"
 
+[target."cfg(any(target_os = \"macos\", windows, target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
+rfd = { version = "0.10", optional = true }
+notify-rust = { version = "4.5", default-features = false, features = [ "d" ], optional = true }
+
 [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
 gtk = { version = "0.15", features = [ "v3_20" ] }
 glib = "0.15"
@@ -109,9 +111,9 @@ objc = "0.2"
 webview2-com = "0.16.0"
 win7-notifications = { version = "0.3.0", optional = true }
 
-  [target."cfg(windows)".dependencies.windows]
-  version = "0.37.0"
-  features = [ "Win32_Foundation" ]
+[target."cfg(windows)".dependencies.windows]
+version = "0.37.0"
+features = [ "Win32_Foundation" ]
 
 [build-dependencies]
 heck = "0.4"

+ 16 - 7
core/tauri/build.rs

@@ -40,6 +40,11 @@ fn main() {
   alias("dev", !has_feature("custom-protocol"));
   alias("updater", has_feature("updater"));
 
+  let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
+  let mobile = target_os == "ios" || target_os == "android";
+  alias("desktop", !mobile);
+  alias("mobile", mobile);
+
   let api_all = has_feature("api-all");
   alias("api_all", api_all);
 
@@ -99,18 +104,22 @@ fn main() {
   alias("shell_script", shell_script);
   alias("shell_scope", has_feature("shell-open-api") || shell_script);
 
-  alias_module(
-    "dialog",
-    &["open", "save", "message", "ask", "confirm"],
-    api_all,
-  );
+  if !mobile {
+    alias_module(
+      "dialog",
+      &["open", "save", "message", "ask", "confirm"],
+      api_all,
+    );
+  }
 
   alias_module("http", &["request"], api_all);
 
   alias("cli", has_feature("cli"));
 
-  alias_module("notification", &[], api_all);
-  alias_module("global-shortcut", &[], api_all);
+  if !mobile {
+    alias_module("notification", &[], api_all);
+    alias_module("global-shortcut", &[], api_all);
+  }
   alias_module("os", &[], api_all);
   alias_module("path", &[], api_all);
 

+ 4 - 4
core/tauri/src/api/mod.rs

@@ -4,8 +4,8 @@
 
 //! The Tauri API interface.
 
-#[cfg(feature = "dialog")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "dialog")))]
+#[cfg(all(desktop, feature = "dialog"))]
+#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "dialog"))))]
 pub mod dialog;
 pub mod dir;
 pub mod file;
@@ -28,8 +28,8 @@ pub mod cli;
 #[cfg_attr(doc_cfg, doc(cfg(feature = "cli")))]
 pub use clap;
 
-#[cfg(feature = "notification")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "notification")))]
+#[cfg(all(desktop, feature = "notification"))]
+#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "notification"))))]
 pub mod notification;
 
 mod error;

+ 25 - 24
core/tauri/src/app.rs

@@ -2,7 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 // SPDX-License-Identifier: MIT
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 pub(crate) mod tray;
 
 use crate::{
@@ -47,7 +47,7 @@ use std::{
 use crate::runtime::menu::{Menu, MenuId, MenuIdRef};
 
 use crate::runtime::RuntimeHandle;
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 use crate::runtime::SystemTrayEvent as RuntimeSystemTrayEvent;
 
 #[cfg(updater)]
@@ -58,7 +58,7 @@ use crate::ActivationPolicy;
 
 pub(crate) type GlobalMenuEventListener<R> = Box<dyn Fn(WindowMenuEvent<R>) + Send + Sync>;
 pub(crate) type GlobalWindowEventListener<R> = Box<dyn Fn(GlobalWindowEvent<R>) + Send + Sync>;
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 type SystemTrayEventListener<R> = Box<dyn Fn(&AppHandle<R>, tray::SystemTrayEvent) + Send + Sync>;
 
 /// Api exposed on the `ExitRequested` event.
@@ -323,11 +323,11 @@ impl<R: Runtime> AssetResolver<R> {
 pub struct AppHandle<R: Runtime> {
   runtime_handle: R::Handle,
   pub(crate) manager: WindowManager<R>,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   global_shortcut_manager: R::GlobalShortcutManager,
   #[cfg(feature = "clipboard")]
   clipboard_manager: R::ClipboardManager,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   tray_handle: Option<tray::SystemTrayHandle<R>>,
   /// The updater configuration.
   #[cfg(updater)]
@@ -376,11 +376,11 @@ impl<R: Runtime> Clone for AppHandle<R> {
     Self {
       runtime_handle: self.runtime_handle.clone(),
       manager: self.manager.clone(),
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       global_shortcut_manager: self.global_shortcut_manager.clone(),
       #[cfg(feature = "clipboard")]
       clipboard_manager: self.clipboard_manager.clone(),
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       tray_handle: self.tray_handle.clone(),
       #[cfg(updater)]
       updater_settings: self.updater_settings.clone(),
@@ -542,11 +542,11 @@ impl<R: Runtime> ManagerBase<R> for AppHandle<R> {
 pub struct App<R: Runtime> {
   runtime: Option<R>,
   manager: WindowManager<R>,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   global_shortcut_manager: R::GlobalShortcutManager,
   #[cfg(feature = "clipboard")]
   clipboard_manager: R::ClipboardManager,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   tray_handle: Option<tray::SystemTrayHandle<R>>,
   handle: AppHandle<R>,
 }
@@ -608,7 +608,7 @@ macro_rules! shared_app_impl {
         updater::builder(self.app_handle())
       }
 
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
       /// Gets a handle handle to the system tray.
       pub fn tray_handle(&self) -> tray::SystemTrayHandle<R> {
@@ -628,7 +628,7 @@ macro_rules! shared_app_impl {
       }
 
       /// Gets a copy of the global shortcut manager instance.
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       #[cfg_attr(doc_cfg, doc(cfg(feature = "global-shortcut")))]
       pub fn global_shortcut_manager(&self) -> R::GlobalShortcutManager {
         self.global_shortcut_manager.clone()
@@ -765,6 +765,7 @@ impl<R: Runtime> App<R> {
   ///   }
   /// }
   /// ```
+  #[cfg(desktop)]
   pub fn run_iteration(&mut self) -> crate::runtime::RunIteration {
     let manager = self.manager.clone();
     let app_handle = self.handle();
@@ -884,11 +885,11 @@ pub struct Builder<R: Runtime> {
   window_event_listeners: Vec<GlobalWindowEventListener<R>>,
 
   /// The app system tray.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   system_tray: Option<tray::SystemTray>,
 
   /// System tray event handlers.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   system_tray_event_listeners: Vec<SystemTrayEventListener<R>>,
 
   /// The updater configuration.
@@ -916,9 +917,9 @@ impl<R: Runtime> Builder<R> {
       enable_macos_default_menu: true,
       menu_event_listeners: Vec::new(),
       window_event_listeners: Vec::new(),
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       system_tray: None,
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       system_tray_event_listeners: Vec::new(),
       #[cfg(updater)]
       updater_settings: Default::default(),
@@ -1150,7 +1151,7 @@ impl<R: Runtime> Builder<R> {
   }
 
   /// Adds the icon configured on `tauri.conf.json` to the system tray with the specified menu items.
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   #[must_use]
   pub fn system_tray(mut self, system_tray: tray::SystemTray) -> Self {
@@ -1262,7 +1263,7 @@ impl<R: Runtime> Builder<R> {
   ///     _ => {}
   ///   });
   /// ```
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   #[must_use]
   pub fn on_system_tray_event<
@@ -1349,7 +1350,7 @@ impl<R: Runtime> Builder<R> {
       self.menu = Some(Menu::os_default(&context.package_info().name));
     }
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     let system_tray_icon = context.system_tray_icon.clone();
 
     #[cfg(all(feature = "system-tray", target_os = "macos"))]
@@ -1405,7 +1406,7 @@ impl<R: Runtime> Builder<R> {
 
     let runtime_handle = runtime.handle();
 
-    #[cfg(feature = "global-shortcut")]
+    #[cfg(all(desktop, feature = "global-shortcut"))]
     let global_shortcut_manager = runtime.global_shortcut_manager();
 
     #[cfg(feature = "clipboard")]
@@ -1414,20 +1415,20 @@ impl<R: Runtime> Builder<R> {
     let mut app = App {
       runtime: Some(runtime),
       manager: manager.clone(),
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       global_shortcut_manager: global_shortcut_manager.clone(),
       #[cfg(feature = "clipboard")]
       clipboard_manager: clipboard_manager.clone(),
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       tray_handle: None,
       handle: AppHandle {
         runtime_handle,
         manager,
-        #[cfg(feature = "global-shortcut")]
+        #[cfg(all(desktop, feature = "global-shortcut"))]
         global_shortcut_manager,
         #[cfg(feature = "clipboard")]
         clipboard_manager,
-        #[cfg(feature = "system-tray")]
+        #[cfg(all(desktop, feature = "system-tray"))]
         tray_handle: None,
         #[cfg(updater)]
         updater_settings: self.updater_settings,
@@ -1480,7 +1481,7 @@ impl<R: Runtime> Builder<R> {
       }
     }
 
-    #[cfg(feature = "system-tray")]
+    #[cfg(all(desktop, feature = "system-tray"))]
     if let Some(system_tray) = self.system_tray {
       let mut ids = HashMap::new();
       if let Some(menu) = system_tray.menu() {

+ 2 - 0
core/tauri/src/endpoints/operating_system.rs

@@ -76,6 +76,8 @@ fn os_type() -> &'static str {
   return "Windows_NT";
   #[cfg(target_os = "macos")]
   return "Darwin";
+  #[cfg(target_os = "ios")]
+  return "iOS";
 }
 
 #[cfg(os_all)]

+ 2 - 2
core/tauri/src/lib.rs

@@ -201,7 +201,7 @@ pub use runtime::http;
 #[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
 pub use runtime::{menu::NativeImage, ActivationPolicy};
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
 pub use {
   self::app::tray::{SystemTrayEvent, SystemTrayHandle},
@@ -248,7 +248,7 @@ pub use {
 #[cfg_attr(doc_cfg, doc(cfg(feature = "clipboard")))]
 pub use self::runtime::ClipboardManager;
 
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 #[cfg_attr(doc_cfg, doc(cfg(feature = "global-shortcut")))]
 pub use self::runtime::GlobalShortcutManager;
 

+ 23 - 14
core/tauri/src/test/mock_runtime.rs

@@ -15,7 +15,7 @@ use tauri_runtime::{
   Dispatch, EventLoopProxy, Icon, Result, RunEvent, Runtime, RuntimeHandle, UserAttentionType,
   UserEvent,
 };
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 use tauri_runtime::{
   menu::{SystemTrayMenu, TrayHandle},
   SystemTray, SystemTrayEvent,
@@ -96,13 +96,13 @@ pub struct MockDispatcher {
   context: RuntimeContext,
 }
 
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 #[derive(Debug, Clone)]
 pub struct MockGlobalShortcutManager {
   context: RuntimeContext,
 }
 
-#[cfg(feature = "global-shortcut")]
+#[cfg(all(desktop, feature = "global-shortcut"))]
 impl tauri_runtime::GlobalShortcutManager for MockGlobalShortcutManager {
   fn is_registered(&self, accelerator: &str) -> Result<bool> {
     Ok(
@@ -510,13 +510,13 @@ impl<T: UserEvent> Dispatch<T> for MockDispatcher {
   }
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 #[derive(Debug, Clone)]
 pub struct MockTrayHandler {
   context: RuntimeContext,
 }
 
-#[cfg(feature = "system-tray")]
+#[cfg(all(desktop, feature = "system-tray"))]
 impl TrayHandle for MockTrayHandler {
   fn set_icon(&self, icon: Icon) -> Result<()> {
     Ok(())
@@ -545,11 +545,11 @@ impl<T: UserEvent> EventLoopProxy<T> for EventProxy {
 #[derive(Debug)]
 pub struct MockRuntime {
   pub context: RuntimeContext,
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   global_shortcut_manager: MockGlobalShortcutManager,
   #[cfg(feature = "clipboard")]
   clipboard_manager: MockClipboardManager,
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   tray_handler: MockTrayHandler,
 }
 
@@ -560,7 +560,7 @@ impl MockRuntime {
       clipboard: Default::default(),
     };
     Self {
-      #[cfg(feature = "global-shortcut")]
+      #[cfg(all(desktop, feature = "global-shortcut"))]
       global_shortcut_manager: MockGlobalShortcutManager {
         context: context.clone(),
       },
@@ -568,7 +568,7 @@ impl MockRuntime {
       clipboard_manager: MockClipboardManager {
         context: context.clone(),
       },
-      #[cfg(feature = "system-tray")]
+      #[cfg(all(desktop, feature = "system-tray"))]
       tray_handler: MockTrayHandler {
         context: context.clone(),
       },
@@ -580,11 +580,11 @@ impl MockRuntime {
 impl<T: UserEvent> Runtime<T> for MockRuntime {
   type Dispatcher = MockDispatcher;
   type Handle = MockRuntimeHandle;
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   type GlobalShortcutManager = MockGlobalShortcutManager;
   #[cfg(feature = "clipboard")]
   type ClipboardManager = MockClipboardManager;
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   type TrayHandler = MockTrayHandler;
   type EventLoopProxy = EventProxy;
 
@@ -607,7 +607,7 @@ impl<T: UserEvent> Runtime<T> for MockRuntime {
     }
   }
 
-  #[cfg(feature = "global-shortcut")]
+  #[cfg(all(desktop, feature = "global-shortcut"))]
   fn global_shortcut_manager(&self) -> Self::GlobalShortcutManager {
     self.global_shortcut_manager.clone()
   }
@@ -628,13 +628,13 @@ impl<T: UserEvent> Runtime<T> for MockRuntime {
     })
   }
 
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   fn system_tray(&self, system_tray: SystemTray) -> Result<Self::TrayHandler> {
     Ok(self.tray_handler.clone())
   }
 
-  #[cfg(feature = "system-tray")]
+  #[cfg(all(desktop, feature = "system-tray"))]
   #[cfg_attr(doc_cfg, doc(cfg(feature = "system-tray")))]
   fn on_system_tray_event<F: Fn(&SystemTrayEvent) + Send + 'static>(&mut self, f: F) -> Uuid {
     Uuid::new_v4()
@@ -644,6 +644,15 @@ impl<T: UserEvent> Runtime<T> for MockRuntime {
   #[cfg_attr(doc_cfg, doc(cfg(target_os = "macos")))]
   fn set_activation_policy(&mut self, activation_policy: tauri_runtime::ActivationPolicy) {}
 
+  #[cfg(any(
+    target_os = "macos",
+    windows,
+    target_os = "linux",
+    target_os = "dragonfly",
+    target_os = "freebsd",
+    target_os = "netbsd",
+    target_os = "openbsd"
+  ))]
   fn run_iteration<F: Fn(RunEvent<T>) + 'static>(
     &mut self,
     callback: F,

+ 28 - 22
core/tauri/src/updater/core.rs

@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: MIT
 
 use super::error::{Error, Result};
+#[cfg(desktop)]
 use crate::api::file::{ArchiveFormat, Extract, Move};
 use crate::{
   api::http::{ClientBuilder, HttpRequestBuilder},
@@ -20,6 +21,7 @@ use tauri_utils::{platform::current_exe, Env};
 use time::OffsetDateTime;
 use url::Url;
 
+#[cfg(desktop)]
 use std::io::Seek;
 use std::{
   collections::HashMap,
@@ -31,10 +33,10 @@ use std::{
   time::Duration,
 };
 
-#[cfg(not(target_os = "macos"))]
+#[cfg(any(target_os = "linux", windows))]
 use std::ffi::OsStr;
 
-#[cfg(all(feature = "updater", not(target_os = "windows")))]
+#[cfg(all(desktop, not(target_os = "windows")))]
 use crate::api::file::Compression;
 
 #[cfg(target_os = "windows")]
@@ -599,26 +601,30 @@ impl<R: Runtime> Update<R> {
     // if there is no signature, bail out.
     verify_signature(&mut archive_buffer, &self.signature, &pub_key)?;
 
-    // we copy the files depending of the operating system
-    // we run the setup, appimage re-install or overwrite the
-    // macos .app
-    #[cfg(target_os = "windows")]
-    copy_files_and_run(
-      archive_buffer,
-      &self.extract_path,
-      self.with_elevated_task,
-      self
-        .app
-        .config()
-        .tauri
-        .updater
-        .windows
-        .install_mode
-        .clone()
-        .msiexec_args(),
-    )?;
-    #[cfg(not(target_os = "windows"))]
-    copy_files_and_run(archive_buffer, &self.extract_path)?;
+    // TODO: implement updater in mobile
+    #[cfg(desktop)]
+    {
+      // we copy the files depending of the operating system
+      // we run the setup, appimage re-install or overwrite the
+      // macos .app
+      #[cfg(target_os = "windows")]
+      copy_files_and_run(
+        archive_buffer,
+        &self.extract_path,
+        self.with_elevated_task,
+        self
+          .app
+          .config()
+          .tauri
+          .updater
+          .windows
+          .install_mode
+          .clone()
+          .msiexec_args(),
+      )?;
+      #[cfg(not(target_os = "windows"))]
+      copy_files_and_run(archive_buffer, &self.extract_path)?;
+    }
 
     // We are done!
     Ok(())

+ 13 - 4
core/tauri/src/updater/mod.rs

@@ -456,10 +456,19 @@ pub use self::{core::RemoteRelease, error::Error};
 /// Alias for [`std::result::Result`] using our own [`Error`].
 pub type Result<T> = std::result::Result<T, Error>;
 
-use crate::{
-  api::dialog::blocking::ask, runtime::EventLoopProxy, AppHandle, EventLoopMessage, Manager,
-  Runtime, UpdaterEvent,
-};
+use crate::{runtime::EventLoopProxy, AppHandle, EventLoopMessage, Manager, Runtime, UpdaterEvent};
+
+#[cfg(desktop)]
+use crate::api::dialog::blocking::ask;
+
+#[cfg(mobile)]
+fn ask<R: Runtime>(
+  _parent_window: Option<&crate::Window<R>>,
+  _title: impl AsRef<str>,
+  _message: impl AsRef<str>,
+) -> bool {
+  true
+}
 
 /// Check for new updates
 pub const EVENT_CHECK_UPDATE: &str = "tauri://update";

+ 5 - 4
core/tauri/src/window.rs

@@ -560,11 +560,11 @@ impl<'de, R: Runtime> CommandArg<'de, R> for Window<R> {
 }
 
 /// The platform webview handle. Accessed with [`Window#method.with_webview`];
-#[cfg(feature = "wry")]
-#[cfg_attr(doc_cfg, doc(cfg(feature = "wry")))]
+#[cfg(all(desktop, feature = "wry"))]
+#[cfg_attr(doc_cfg, doc(cfg(all(desktop, feature = "wry"))))]
 pub struct PlatformWebview(tauri_runtime_wry::Webview);
 
-#[cfg(feature = "wry")]
+#[cfg(all(desktop, feature = "wry"))]
 impl PlatformWebview {
   /// Returns [`webkit2gtk::WebView`] handle.
   #[cfg(any(
@@ -671,7 +671,8 @@ impl Window<crate::Wry> {
   ///   });
   /// }
   /// ```
-  #[cfg_attr(doc_cfg, doc(cfg(eature = "wry")))]
+  #[cfg(desktop)]
+  #[cfg_attr(doc_cfg, doc(cfg(all(feature = "wry", desktop))))]
   pub fn with_webview<F: FnOnce(PlatformWebview) + Send + 'static>(
     &self,
     f: F,

+ 5 - 0
core/tests/app-updater/tests/update.rs

@@ -98,6 +98,11 @@ fn bundle_path(root_dir: &Path, _version: &str) -> PathBuf {
   root_dir.join(format!("target/debug/bundle/macos/app-updater.app"))
 }
 
+#[cfg(target_os = "ios")]
+fn bundle_path(root_dir: &Path, _version: &str) -> PathBuf {
+  root_dir.join(format!("target/debug/bundle/ios/app-updater.app"))
+}
+
 #[cfg(windows)]
 fn bundle_path(root_dir: &Path, version: &str) -> PathBuf {
   root_dir.join(format!(

+ 108 - 94
examples/api/src-tauri/src/main.rs

@@ -9,13 +9,19 @@
 
 mod cmd;
 
-use std::sync::atomic::{AtomicBool, Ordering};
-
 use serde::Serialize;
-use tauri::{
-  api::dialog::ask, window::WindowBuilder, CustomMenuItem, GlobalShortcutManager, Manager,
-  RunEvent, SystemTray, SystemTrayEvent, SystemTrayMenu, WindowEvent, WindowUrl,
-};
+use tauri::{window::WindowBuilder, RunEvent, WindowUrl};
+
+#[cfg(desktop)]
+mod desktop {
+  pub use std::sync::atomic::{AtomicBool, Ordering};
+  pub use tauri::{
+    api::dialog::ask, CustomMenuItem, GlobalShortcutManager, Manager, SystemTray, SystemTrayEvent,
+    SystemTrayMenu, WindowEvent,
+  };
+}
+#[cfg(desktop)]
+pub use desktop::*;
 
 #[derive(Clone, Serialize)]
 struct Reply {
@@ -23,20 +29,6 @@ struct Reply {
 }
 
 fn main() {
-  let tray_menu1 = SystemTrayMenu::new()
-    .add_item(CustomMenuItem::new("toggle", "Toggle"))
-    .add_item(CustomMenuItem::new("new", "New window"))
-    .add_item(CustomMenuItem::new("icon_1", "Tray Icon 1"))
-    .add_item(CustomMenuItem::new("icon_2", "Tray Icon 2"))
-    .add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
-    .add_item(CustomMenuItem::new("exit_app", "Quit"));
-  let tray_menu2 = SystemTrayMenu::new()
-    .add_item(CustomMenuItem::new("toggle", "Toggle"))
-    .add_item(CustomMenuItem::new("new", "New window"))
-    .add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
-    .add_item(CustomMenuItem::new("exit_app", "Quit"));
-  let is_menu1 = AtomicBool::new(true);
-
   #[allow(unused_mut)]
   let mut builder = tauri::Builder::default()
     .setup(|app| {
@@ -101,80 +93,6 @@ fn main() {
           .emit("rust-event", Some(reply))
           .expect("failed to emit");
       });
-    })
-    .system_tray(SystemTray::new().with_menu(tray_menu1.clone()))
-    .on_system_tray_event(move |app, event| match event {
-      SystemTrayEvent::LeftClick {
-        position: _,
-        size: _,
-        ..
-      } => {
-        let window = app.get_window("main").unwrap();
-        window.show().unwrap();
-        window.set_focus().unwrap();
-      }
-      SystemTrayEvent::MenuItemClick { id, .. } => {
-        let item_handle = app.tray_handle().get_item(&id);
-        match id.as_str() {
-          "exit_app" => {
-            // exit the app
-            app.exit(0);
-          }
-          "toggle" => {
-            let window = app.get_window("main").unwrap();
-            let new_title = if window.is_visible().unwrap() {
-              window.hide().unwrap();
-              "Show"
-            } else {
-              window.show().unwrap();
-              "Hide"
-            };
-            item_handle.set_title(new_title).unwrap();
-          }
-          "new" => {
-            WindowBuilder::new(app, "new", WindowUrl::App("index.html".into()))
-              .title("Tauri")
-              .build()
-              .unwrap();
-          }
-          "icon_1" => {
-            #[cfg(target_os = "macos")]
-            app.tray_handle().set_icon_as_template(true).unwrap();
-
-            app
-              .tray_handle()
-              .set_icon(tauri::Icon::Raw(
-                include_bytes!("../../../.icons/tray_icon_with_transparency.png").to_vec(),
-              ))
-              .unwrap();
-          }
-          "icon_2" => {
-            #[cfg(target_os = "macos")]
-            app.tray_handle().set_icon_as_template(true).unwrap();
-
-            app
-              .tray_handle()
-              .set_icon(tauri::Icon::Raw(
-                include_bytes!("../../../.icons/icon.ico").to_vec(),
-              ))
-              .unwrap();
-          }
-          "switch_menu" => {
-            let flag = is_menu1.load(Ordering::Relaxed);
-            app
-              .tray_handle()
-              .set_menu(if flag {
-                tray_menu2.clone()
-              } else {
-                tray_menu1.clone()
-              })
-              .unwrap();
-            is_menu1.store(!flag, Ordering::Relaxed);
-          }
-          _ => {}
-        }
-      }
-      _ => {}
     });
 
   #[cfg(target_os = "macos")]
@@ -182,6 +100,99 @@ fn main() {
     builder = builder.menu(tauri::Menu::os_default("Tauri API Validation"));
   }
 
+  #[cfg(desktop)]
+  {
+    let tray_menu1 = SystemTrayMenu::new()
+      .add_item(CustomMenuItem::new("toggle", "Toggle"))
+      .add_item(CustomMenuItem::new("new", "New window"))
+      .add_item(CustomMenuItem::new("icon_1", "Tray Icon 1"))
+      .add_item(CustomMenuItem::new("icon_2", "Tray Icon 2"))
+      .add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
+      .add_item(CustomMenuItem::new("exit_app", "Quit"));
+    let tray_menu2 = SystemTrayMenu::new()
+      .add_item(CustomMenuItem::new("toggle", "Toggle"))
+      .add_item(CustomMenuItem::new("new", "New window"))
+      .add_item(CustomMenuItem::new("switch_menu", "Switch Menu"))
+      .add_item(CustomMenuItem::new("exit_app", "Quit"));
+    let is_menu1 = AtomicBool::new(true);
+
+    builder = builder
+      .system_tray(SystemTray::new().with_menu(tray_menu1.clone()))
+      .on_system_tray_event(move |app, event| match event {
+        SystemTrayEvent::LeftClick {
+          position: _,
+          size: _,
+          ..
+        } => {
+          let window = app.get_window("main").unwrap();
+          window.show().unwrap();
+          window.set_focus().unwrap();
+        }
+        SystemTrayEvent::MenuItemClick { id, .. } => {
+          let item_handle = app.tray_handle().get_item(&id);
+          match id.as_str() {
+            "exit_app" => {
+              // exit the app
+              app.exit(0);
+            }
+            "toggle" => {
+              let window = app.get_window("main").unwrap();
+              let new_title = if window.is_visible().unwrap() {
+                window.hide().unwrap();
+                "Show"
+              } else {
+                window.show().unwrap();
+                "Hide"
+              };
+              item_handle.set_title(new_title).unwrap();
+            }
+            "new" => {
+              WindowBuilder::new(app, "new", WindowUrl::App("index.html".into()))
+                .title("Tauri")
+                .build()
+                .unwrap();
+            }
+            "icon_1" => {
+              #[cfg(target_os = "macos")]
+              app.tray_handle().set_icon_as_template(true).unwrap();
+
+              app
+                .tray_handle()
+                .set_icon(tauri::Icon::Raw(
+                  include_bytes!("../../../.icons/tray_icon_with_transparency.png").to_vec(),
+                ))
+                .unwrap();
+            }
+            "icon_2" => {
+              #[cfg(target_os = "macos")]
+              app.tray_handle().set_icon_as_template(true).unwrap();
+
+              app
+                .tray_handle()
+                .set_icon(tauri::Icon::Raw(
+                  include_bytes!("../../../.icons/icon.ico").to_vec(),
+                ))
+                .unwrap();
+            }
+            "switch_menu" => {
+              let flag = is_menu1.load(Ordering::Relaxed);
+              app
+                .tray_handle()
+                .set_menu(if flag {
+                  tray_menu2.clone()
+                } else {
+                  tray_menu1.clone()
+                })
+                .unwrap();
+              is_menu1.store(!flag, Ordering::Relaxed);
+            }
+            _ => {}
+          }
+        }
+        _ => {}
+      });
+  }
+
   #[allow(unused_mut)]
   let mut app = builder
     .invoke_handler(tauri::generate_handler![
@@ -194,8 +205,10 @@ fn main() {
   #[cfg(target_os = "macos")]
   app.set_activation_policy(tauri::ActivationPolicy::Regular);
 
+  #[allow(unused_variables)]
   app.run(|app_handle, e| match e {
     // Application is ready (triggered only once)
+    #[cfg(desktop)]
     RunEvent::Ready => {
       let app_handle = app_handle.clone();
       app_handle
@@ -209,6 +222,7 @@ fn main() {
     }
 
     // Triggered when a window is trying to close
+    #[cfg(desktop)]
     RunEvent::WindowEvent {
       label,
       event: WindowEvent::CloseRequested { api, .. },