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] SystemTray shows the menu on LeftClick, it should be on RightClick only #317

Closed
awkj opened this issue Feb 12, 2022 · 8 comments · Fixed by #413
Closed

[bug] SystemTray shows the menu on LeftClick, it should be on RightClick only #317

awkj opened this issue Feb 12, 2022 · 8 comments · Fixed by #413

Comments

@awkj
Copy link

awkj commented Feb 12, 2022

Describe the bug

default SystemTrayEvent::LeftClick will show Tray Menu, I not found API or setting to disable the behavior.

https://tauri.studio/docs/guides/system-tray

use tauri::{CustomMenuItem, SystemTray, SystemTrayMenu};
use tauri::Manager;

fn main() {
  let tray_menu = SystemTrayMenu::new(); // insert the menu items here
  tauri::Builder::default()
    .system_tray(SystemTray::new().with_menu(tray_menu))
    .on_system_tray_event(|app, event| match event {
      SystemTrayEvent::LeftClick {
        position: _,
        size: _,
        ..
      } => {
        // the will auto pop Tray Menu
        println!("system tray received a left click");
      }
      SystemTrayEvent::RightClick {
        position: _,
        size: _,
        ..
      } => {
        println!("system tray received a right click");
      }
      SystemTrayEvent::DoubleClick {
        position: _,
        size: _,
        ..
      } => {
        println!("system tray received a double click");
      }
      SystemTrayEvent::MenuItemClick { id, .. } => {
        match id.as_str() {
          "quit" => {
            std::process::exit(0);
          }
          "hide" => {
            let window = app.get_window("main").unwrap();
            window.hide().unwrap();
          }
          _ => {}
        }
      }
      _ => {}
    })
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}

Reproduction

No response

Expected behavior

No response

Platform and versions

Operating System - Mac OS, version 12.2.1 X64

Node.js environment
  Node.js - 16.13.2
  @tauri-apps/cli - 1.0.0-rc.2
  @tauri-apps/api - 1.0.0-rc.0

Global packages
  npm - 8.1.2
  pnpm - 6.30.0
  yarn - 1.22.17

Rust environment
  rustc - 1.58.1
  cargo - 1.58.0

Rust environment
  rustup - 1.24.3
  rustc - 1.58.1
  cargo - 1.58.0
  toolchain - stable-x86_64-apple-darwin 

App directory structure
/dist
/node_modules
/src-tauri
/src

App
  tauri.rs - 1.0.0-rc.0
  build-type - bundle
  CSP - default-src 'self'
  distDir - ../dist
  devPath - http://localhost:3000/
  framework - React

Stack trace

No response

Additional context

No response

@awkj awkj added the type: bug label Feb 12, 2022
@amrbashir
Copy link
Member

amrbashir commented Feb 12, 2022

If you have a menu attached, why wouldn't you want to show it? just want to know your use-case.

IIRC, some platforms are hard coded to open a context menu when the icon is clicked (Linux and maybe macOS).

@awkj
Copy link
Author

awkj commented Feb 12, 2022

If you have a menu attached, why wouldn't you want to show it? just want to know your use-case.

IIRC, some platforms are hard coded to openn a context menu when the icon is clicked (Linux and maybeOS).

I found SystemTrayEvent::LeftClick and SystemTrayEvent::RightClick all will show tray menu.
but I wish leftClick will let my window display(from my custom function), now when I listen leftClick event, it will show tray menu and show my window at the same time, I want control default behavior of leftclick and rightclick.

@amrbashir
Copy link
Member

I see, that's a valid use-case and one that I am interested into but you should know that tray click events on Linux doesn't work (limitation of Linux itself).

I will transfer this to Tao.

@amrbashir amrbashir transferred this issue from tauri-apps/tauri Feb 12, 2022
@amrbashir amrbashir changed the title [bug] When System Tauri Left Click , default will show Tray Menu [bug] SystemTray shows the menu on LeftClick Feb 12, 2022
@amrbashir
Copy link
Member

Ideally we want right click to show the menu without the left click.

@awkj
Copy link
Author

awkj commented Feb 12, 2022

Great!

@amrbashir amrbashir changed the title [bug] SystemTray shows the menu on LeftClick [bug] SystemTray shows the menu on LeftClick, it should be on RightClick only Feb 28, 2022
@wusyong
Copy link
Member

wusyong commented Mar 1, 2022

All applications I used will trigger the try both right and left clicks.
Telegram, Wireguard, and even system IME do this behavior.

@amrbashir
Copy link
Member

It is good to follow the OS convention, but I remember @lemarier showed a demo of 1password app where LeftClick opens a window instead of a menu.

@amrbashir
Copy link
Member

Alright, I will close this since it is the OS default behavior but If more people ask for this, we will reconsider.

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

Successfully merging a pull request may close this issue.

3 participants