Browse Source

Fix android/ios muda cfg

Jonathan Kelley 1 năm trước cách đây
mục cha
commit
0ac8955bab

+ 1 - 1
packages/desktop/src/app.rs

@@ -1,5 +1,5 @@
 use crate::{
-    cfg::{Config, WindowCloseBehaviour},
+    config::{Config, WindowCloseBehaviour},
     desktop_context::WindowEventHandlers,
     element::DesktopElement,
     file_upload::FileDialogRequest,

+ 0 - 0
packages/desktop/src/cfg.rs → packages/desktop/src/config.rs


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

@@ -5,7 +5,7 @@
 
 mod app;
 mod assets;
-mod cfg;
+mod config;
 mod desktop_context;
 mod edits;
 mod element;
@@ -15,7 +15,6 @@ mod events;
 mod file_upload;
 mod hooks;
 mod ipc;
-mod menubar;
 mod protocol;
 mod query;
 mod shortcut;
@@ -25,9 +24,14 @@ mod webview;
 #[cfg(feature = "collect-assets")]
 mod collect_assets;
 
+// mobile shortcut is only supported on mobile platforms
 #[cfg(any(target_os = "ios", target_os = "android"))]
 mod mobile_shortcut;
 
+// menu bar is only supported on desktop platforms
+#[cfg(not(any(target_os = "android", target_os = "ios")))]
+mod menubar;
+
 // The main entrypoint for this crate
 pub use launch::*;
 mod launch;
@@ -41,7 +45,7 @@ pub use wry;
 
 // Public exports
 pub use assets::AssetRequest;
-pub use cfg::{Config, WindowCloseBehaviour};
+pub use config::{Config, WindowCloseBehaviour};
 pub use desktop_context::{
     window, DesktopContext, DesktopService, WryEventHandler, WryEventHandlerId,
 };

+ 6 - 0
packages/desktop/src/menubar.rs

@@ -1,6 +1,12 @@
 use muda::{Menu, PredefinedMenuItem, Submenu};
 use tao::window::Window;
 
+pub fn build_menu(window: &Window, default_menu_bar: bool) {
+    if default_menu_bar {
+        build_menu_bar(build_default_menu_bar(), window)
+    }
+}
+
 #[allow(unused)]
 pub fn build_menu_bar(menu: Menu, window: &Window) {
     #[cfg(target_os = "windows")]

+ 2 - 4
packages/desktop/src/webview.rs

@@ -28,10 +28,8 @@ impl WebviewInstance {
         let window = cfg.window.clone().build(&shared.target).unwrap();
 
         // TODO: allow users to specify their own menubars, again :/
-        if cfg.enable_default_menu_bar {
-            use crate::menubar::*;
-            build_menu_bar(build_default_menu_bar(), &window);
-        }
+        #[cfg(not(any(target_os = "android", target_os = "ios")))]
+        crate::menubar::build_menu(&window, cfg.enable_default_menu_bar);
 
         // We assume that if the icon is None in cfg, then the user just didnt set it
         if cfg.window.window.window_icon.is_none() {