-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[feat][macOS] Provide a hook to capture the dock events / activate event #3084
Comments
related to tauri-apps/tao#218 |
Maybe just Once the app is hidden, I can bring the window back by clicking the dock icon, or by switching to the app with |
Also found tauri-apps/tao#517 and #4865 |
Is there any plan for working on this one? This is a pretty common feature in MacOs: clicking app icon in the dock should open an app window. |
This may not close the issue as it's not about capturing left click on dock events. So obviously this isn't the solution you've described as the one you'd like, but I think I have implemented the behaviour you've described. I've got an app which needs to stay running when the window is closed as we have some long running processes. A bit like docker desktop. On MacOS we want the app to stay in the dock, and the window to reappear if the item in the dock is left clicked. On Windows we don't want the application to be visible on the menu bar unless the window is open, as we have a system tray icon instead, so our logic differs slightly: tauri::Builder::default()
.on_window_event(|event| match event.event() {
tauri::WindowEvent::CloseRequested { api, .. } => {
#[cfg(not(target_os = "macos"))] {
event.window().hide().unwrap();
}
#[cfg(target_os = "macos")] {
tauri::AppHandle::hide(&event.window().app_handle()).unwrap();
}
api.prevent_close();
}
_ => {}
}) Excuse the 'unwrap's - It's easier to show them here for brevity, but longer term I'd suggest doing something like mapping them and handling the errors. I've found that this hiding was enough, as the other events appear to be handled by default in a satisfactory manner. I don't try to manually 'show' the window (except if prompted via our system tray) |
@MGough thanks!! for some reason, indeed if I use |
Closes https://github.com/sourcegraph/sourcegraph/issues/53756 This allows clicking the dock icon to show the main window if it is closed but the app is still running. This is a temporary solution that only works if the app has a single window. If we need to add more windows in the future, we need to wait until tauri-apps/tauri#3084 is fixed. ## Test plan 1. Open app 2. Close with red button on top-left of window 3. Click on Cody icon in dock App main window should be shown again.
Closes https://github.com/sourcegraph/sourcegraph/issues/53756 This allows clicking the dock icon to show the main window if it is closed but the app is still running. This is a temporary solution that only works if the app has a single window. If we need to add more windows in the future, we need to wait until tauri-apps/tauri#3084 is fixed. ## Test plan 1. Open app 2. Close with red button on top-left of window 3. Click on Cody icon in dock App main window should be shown again.
This basic function is not supported yet? That's unbelievable. |
Is there a way to get the NS'Application object? |
Two years have passed. Has there been any progress on this issue? |
Is your feature request related to a problem? Please describe.
I use api.prevent_close() and window.hide() to prevent the app to exit. And then I want to show the window again by left-clicking the icon on the dock, but it does not work. The question is how to capture the left-click events?
Describe the solution you'd like
Provide a hook to capture theses events, like this:
Describe alternatives you've considered
None.
Additional context
Cargo tauri info
Operating System - Mac OS, version 11.6.1 X64
Node.js environment
Node.js - 14.18.1
@tauri-apps/cli - 1.0.0-beta.10
@tauri-apps/api - 1.0.0-beta.8
Global packages
npm - 6.14.15
yarn - 1.22.17
Rust environment
rustc - 1.56.1
cargo - 1.56.0
App directory structure
/bin
/node_modules
/webpack
/public
/src-web
/src-tauri
/change-logs
/build
/.git
/src
App
tauri.rs - 1.0.0-beta.8
build-type - bundle
CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
distDir - ../build
devPath - http://localhost:9091
framework - React
bundler - Webpack
The text was updated successfully, but these errors were encountered: