tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.82k stars 2.6k forks source link

[bug] Help Menu on MacOS is empty and there is not any response when click it which will be failed to pass apple review #9371

Open jyc5131 opened 8 months ago

jyc5131 commented 8 months ago

Describe the bug

The default help menu have empty submenu in macos desktop, it will fail to pass apple review.

Screenshot 2024-04-03 at 9 52 48 AM

also I try to call set_as_help_menu_for_nsapp, it doesn't work. if let Some(help_menu) = menu.get(tauri::menu::HELP_SUBMENU_ID) { _ = help_menu.as_submenu().unwrap().set_as_help_menu_for_nsapp(); } and I try to remove the help menu, crashed let menu = app.menu().unwrap(); menu.remove(&menu.get(tauri::menu::HELP_SUBMENU_ID).unwrap());

Reproduction

  1. create minimum tauri app and npm run tauri dev on MacOS.
  2. the desktop app will start with default title bar menu.
  3. click the Help menu, there is not any drop down menu shown and Apple review will reject it.

Expected behavior

the default help menu should have a search box under the Help menu.

Full tauri info output

[✔] Environment
    - OS: Mac OS 14.4.1 X64
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.76.0 (07dca489a 2024-02-04)
    ✔ cargo: 1.76.0 (c84b36747 2024-01-18)
    ✔ rustup: 1.26.0 (5af9b9484 2023-04-05)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 20.10.0
    - yarn: 1.22.10
    - npm: 10.2.3

[-] Packages
    - tauri [RUST]: 2.0.0-beta.11
    - tauri-build [RUST]: 2.0.0-beta.9
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.0
    - tauri-cli [RUST]: 2.0.0-beta.9
    - @tauri-apps/api [NPM]: 2.0.0-beta.5
    - @tauri-apps/cli [NPM]: 2.0.0-beta.9

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:8007/
    - framework: React

Stack trace

No response

Additional context

No response

pewsheen commented 7 months ago

The weird thing is when we set the help menu by helpMenu, it breaks the help menu.

A possible fix is to remove the logic that adds a default help menu from Tauri. I'm not sure if this will break the behavior on older macOS.

Adding a menu named "Help" without setting it helpMenu will also add the spotlight box into it

chrox commented 5 days ago

Exactly the same issue here. I think this patch should work. And you also need to setup the shell plugin in order to open a link with the default browser. Documentation is here.

diff --git a/apps/readest-app/src-tauri/src/lib.rs b/apps/readest-app/src-tauri/src/lib.rs
index bbd599b..f0a64eb 100644
--- a/apps/readest-app/src-tauri/src/lib.rs
+++ b/apps/readest-app/src-tauri/src/lib.rs
@@ -13,9 +13,13 @@ mod tauri_traffic_light_positioner_plugin;
 use tauri::TitleBarStyle;
 use tauri::{WebviewUrl, WebviewWindowBuilder};

+use tauri::menu::{SubmenuBuilder, HELP_SUBMENU_ID};
+use tauri_plugin_shell::ShellExt;
+
 #[cfg_attr(mobile, tauri::mobile_entry_point)]
 pub fn run() {
     let builder = tauri::Builder::default()
+        .plugin(tauri_plugin_shell::init())
         .plugin(tauri_plugin_http::init())
         .plugin(tauri_plugin_os::init())
         .plugin(tauri_plugin_dialog::init())
@@ -49,6 +53,29 @@ pub fn run() {

             let _ = win_builder.build().unwrap();

+            let global_menu = app.menu().unwrap();
+            if let Some(item) = global_menu.get(HELP_SUBMENU_ID) {
+                let _ = global_menu.remove(&item);
+            }
+            let _ = global_menu.append(
+                &SubmenuBuilder::new(app, "Help")
+                    .text("privacy_policy", "Privacy Policy")
+                    .separator()
+                    .text("report_issue", "Report An Issue...")
+                    .text("readest_help", "Readest Help")
+                    .build()?,
+            );
+
+            app.on_menu_event(move |app, event| {
+                if event.id() == "privacy_policy" {
+                    let _ = app.shell().open("https://readest.com/privacy-policy", None);
+                } else if event.id() == "report_issue" {
+                    let _ = app.shell().open("mailto:support@bilingify.com", None);
+                } else if event.id() == "readest_help" {
+                    let _ = app.shell().open("https://readest.com/support", None);
+                }
+            });
+
             Ok(())
         })
         .run(tauri::generate_context!())