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

Menu shortcut does not work on macOS since wry 0.22 #749

Closed
1 of 2 tasks
rhysd opened this issue Nov 8, 2022 · 7 comments · Fixed by tauri-apps/tao#620
Closed
1 of 2 tasks

Menu shortcut does not work on macOS since wry 0.22 #749

rhysd opened this issue Nov 8, 2022 · 7 comments · Fixed by tauri-apps/tao#620
Labels
platform: macOS status: needs triage This issue or pull request needs to be investigated type: bug

Comments

@rhysd
Copy link
Contributor

rhysd commented Nov 8, 2022

Describe the bug

Key shotcut of menu item does not work on macOS since 0.22.0.

Steps To Reproduce
Steps to reproduce the behavior:

  1. Save the following code and run
  2. Application window launches
  3. Enter Cmd+Q
  4. Nothing happens and nothing is output to terminal console
fn main() -> wry::Result<()> {
  use wry::{
    application::{
      accelerator::Accelerator,
      event::{Event, StartCause, WindowEvent},
      event_loop::{ControlFlow, EventLoop},
      keyboard::{KeyCode, ModifiersState},
      menu::{MenuBar, MenuItemAttributes},
      window::WindowBuilder,
    },
    webview::WebViewBuilder,
  };

  let mut menu = MenuBar::new();
  let mut file_menu = MenuBar::new();
  file_menu.add_item(
    MenuItemAttributes::new("Quit").with_accelerators(&Accelerator::new(
      Some(ModifiersState::SUPER),
      KeyCode::KeyQ,
    )),
  );
  menu.add_submenu("File", true, file_menu);

  let event_loop = EventLoop::new();
  let window = WindowBuilder::new()
    .with_title("Hello World")
    .with_menu(menu)
    .build(&event_loop)?;
  let _webview = WebViewBuilder::new(window)?
    .with_url("https://example.com")?
    .build()?;

  event_loop.run(move |event, _, control_flow| {
    *control_flow = ControlFlow::Wait;

    match event {
      Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
      Event::WindowEvent {
        event: WindowEvent::CloseRequested,
        ..
      } => *control_flow = ControlFlow::Exit,
      Event::MenuEvent { menu_id, .. } => {
        println!("Menu clicked! {:?}", menu_id);
        *control_flow = ControlFlow::Exit;
      }
      _ => (),
    }
  });
}

Expected behavior
'Menu clicked!' is output to terminal console and application quits successfully

Screenshots
N/A

Platform and Versions (please complete the following information):
OS: macOS 11
Rustc: rustc v1.65.0

Would you assign yourself to resolve this bug?

  • Yes
  • No

Additional context

This seems a regression of v0.22.0. I confirmed it worked with v0.21.1.

Selecting 'Quit' from menu item works as intended.

@amrbashir amrbashir added platform: macOS status: needs triage This issue or pull request needs to be investigated type: bug labels Nov 8, 2022
@rhysd
Copy link
Contributor Author

rhysd commented Nov 8, 2022

I bisected this repository.

#745 seems related to this issue.

CC: @wusyong

@wusyong
Copy link
Member

wusyong commented Nov 8, 2022

Looks like this is a regression after we don't replace TaoView.
I further test tao's menu accelerator is fine.
If we remove TaoView's keyUp and keyDown methods, example in wry can work again somehow.
We'll need some helps looking into why adding subview will cause keyinput being blocked in menu accelerator.

@wusyong
Copy link
Member

wusyong commented Nov 8, 2022

Okay I found the cause is doCommandBySelector in TaoView.
Although it does nothing in tao, winit uses it for some text blocking.
But again this method is deprecated. We can remove this in tao and open an issue in winit to think what's the better way to do this I think.

rhysd added a commit to rhysd/Shiba that referenced this issue Nov 8, 2022
@lucasfernog
Copy link
Member

@wusyong can we patch this asap

@lucasfernog
Copy link
Member

Fixed in tao v0.15.3.

@rhysd
Copy link
Contributor Author

rhysd commented Nov 9, 2022

I confirmed that this issue was fixed after cargo update. Thank you for the quick fix.

@tw93
Copy link

tw93 commented Nov 25, 2022

when i run npm run tauri build -- --target universal-apple-darwin, the bug still exists.
but when i run npm run tauri build -- --target x86_64-apple-darwin and m1 is ok
and npm run dev is ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: macOS status: needs triage This issue or pull request needs to be investigated type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants