Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Panic while firing menu event when window is minimized on macOS. #3902

Closed
sprout2000 opened this issue Apr 16, 2022 · 1 comment
Closed

Comments

@sprout2000
Copy link

Describe the bug

Selecting a menu (e.g. Open...) when a window is minimized in macOS causes the application to panic.

Reproduction

  1. Use the template with the default selected.
npx create-tauri-app
  1. src-tauri/src/main.rs:
use tauri::api::dialog;
use tauri::{CustomMenuItem, Menu, Submenu};

fn main() {
    let menu = Menu::new().add_submenu(Submenu::new(
        "File",
        Menu::new().add_item(CustomMenuItem::new("open", "Open...")),
    ));
    tauri::Builder::default()
        .menu(menu)
        .on_menu_event(|event| {
            if event.menu_item_id() == "open" {
                dialog::FileDialogBuilder::new().pick_file(|f| {
                    if let Some(fpath) = f {
                        println!("{:?}", fpath);
                    }
                })
            }
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
  1. Launch that app and minimize its window.

  2. Select Open... from the Window menu.

npx tauri dev

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:130:40
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Expected behavior

Do not fire CustomMenuItem events when the window is minimized.
Or implement window.isMinimized() so that the developer can detect the state of window minimization.

Platform and versions

_Notwithstanding the following indication, `@tauri-apps/cli@1.0.0-rc.8` and `@tauri-apps/api@1.0.0-rc.3` are actually installed._

Environment
  › OS: Mac OS 12.3.1 X64
  › Node.js: 16.14.2
  › npm: 8.7.0
  › pnpm: Not installed!
  › yarn: Not installed!
  › rustup: 1.24.3
  › rustc: 1.60.0
  › cargo: 1.60.0
  › Rust toolchain: stable-aarch64-apple-darwin 

Packages
  › @tauri-apps/cli [NPM]: 1.0.0-rc.7(outdated, latest: 1.0.0-rc.8)
  › @tauri-apps/api [NPM]: 1.0.0-rc.3(outdated, latest: 1.0.0-rc.3)
  › tauri [RUST]: 1.0.0-rc.6,
  › tauri-build [RUST]: 1.0.0-rc.5,
  › tao [RUST]: 0.7.0,
  › wry [RUST]: 0.14.0,

App
  › build-type: bundle
  › CSP: unset
  › distDir: ../dist
  › devPath: ../dist

App directory structure
  ├─ dist
  ├─ node_modules
  └─ src-tauri

Stack trace

$ RUST_BACKTRACE=1 npx tauri dev  

    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
     Running `target/debug/app`
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:130:40
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:143:14
   2: core::panicking::panic
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/panicking.rs:48:5
   3: core::option::Option<T>::unwrap
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/option.rs:752:21
   4: tauri_runtime_wry::WebviewIdStore::get
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:130:10
   5: tauri_runtime_wry::handle_event_loop
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:2410:33
   6: <tauri_runtime_wry::Wry<T> as tauri_runtime::Runtime<T>>::run::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:1953:13
   7: <tao::platform_impl::platform::app_state::EventLoopHandler<T> as tao::platform_impl::platform::app_state::EventHandler>::handle_nonuser_event::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/app_state.rs:104:9
   8: tao::platform_impl::platform::app_state::EventLoopHandler<T>::with_callback
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/app_state.rs:78:7
   9: <tao::platform_impl::platform::app_state::EventLoopHandler<T> as tao::platform_impl::platform::app_state::EventHandler>::handle_nonuser_event
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/app_state.rs:99:5
  10: tao::platform_impl::platform::app_state::Handler::handle_nonuser_event
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/app_state.rs:208:11
  11: tao::platform_impl::platform::app_state::AppState::cleared
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/app_state.rs:380:9
  12: tao::platform_impl::platform::observer::control_flow_end_handler::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/observer.rs:186:11
  13: tao::platform_impl::platform::observer::control_flow_handler::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/observer.rs:147:5
  14: std::panicking::try::do_call
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:492:40
  15: ___rust_try
  16: std::panicking::try
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panicking.rs:456:19
  17: std::panic::catch_unwind
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/std/src/panic.rs:137:14
  18: tao::platform_impl::platform::event_loop::stop_app_on_panic
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/event_loop.rs:224:9
  19: tao::platform_impl::platform::observer::control_flow_handler
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/observer.rs:145:3
  20: tao::platform_impl::platform::observer::control_flow_end_handler
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/observer.rs:181:5
  21: <unknown>
  22: <unknown>
  23: <unknown>
  24: <unknown>
  25: <unknown>
  26: <unknown>
  27: <unknown>
  28: <unknown>
  29: <unknown>
  30: <unknown>
  31: <() as objc::message::MessageArguments>::invoke
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:128:17
  32: objc::message::platform::send_unverified::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:27:9
  33: objc_exception::try::{{closure}}
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:68:31
  34: objc_exception::try_no_ret::try_objc_execute_closure
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:34:9
  35: RustObjCExceptionTryCatch
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc_exception-0.1.2/extern/exception.m:10:9
  36: objc_exception::try_no_ret
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:44:19
  37: objc_exception::try
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc_exception-0.1.2/src/lib.rs:67:9
  38: objc::exception::try
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/exception.rs:8:5
  39: objc::message::platform::send_unverified
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/apple/mod.rs:26:5
  40: objc::message::send_message
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/message/mod.rs:178:5
  41: tao::platform_impl::platform::event_loop::EventLoop<T>::run_return
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/event_loop.rs:181:16
  42: tao::platform_impl::platform::event_loop::EventLoop<T>::run
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/platform_impl/macos/event_loop.rs:148:21
  43: tao::event_loop::EventLoop<T>::run
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tao-0.7.0/src/event_loop.rs:177:5
  44: <tauri_runtime_wry::Wry<T> as tauri_runtime::Runtime<T>>::run
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-runtime-wry-0.3.5/src/lib.rs:1952:9
  45: tauri::app::App<R>::run
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-1.0.0-rc.6/src/app.rs:614:5
  46: tauri::app::Builder<R>::run
             at $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/tauri-1.0.0-rc.6/src/app.rs:1482:5
  47: app::main
             at ./src/main.rs:14:5
  48: core::ops::function::FnOnce::call_once
             at /rustc/7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Additional context

No response

@sprout2000 sprout2000 changed the title [bug] Panic when firing menu event when window is minimized on macOS. [bug] Panic while firing menu event when window is minimized on macOS. Apr 19, 2022
@lucasfernog
Copy link
Member

Thanks for the report! Fix will be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants