-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Feature request] Keep app running after all windows are closed #2287
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
Comments
I'd be interested in figuring out how to implement this and creating a PR. On first look, there seems to be an easy way to add a parameter to |
I've gone ahead and hacked something together based on my (so far fairly limited) understanding of the codebase.
I don't want to create a PR just yet because there hasn't been enough discussion to determine if this is a desired approach, but you can check out the feat/run-mode branch in my fork, or the diff with the If this approach sounds good then I'll go through it, clean it up where necessary, and create a proper PR for review. If y'all would prefer this feature to be approached in a different way, no problem, I'll just delete my branch and we can discuss how to do this properly. 😄 |
Hey well done! @lucasfernog what you think about this? |
we have something similar to stop Window from closing, check tauri/examples/api/src-tauri/src/main.rs Lines 104 to 106 in 70a1941
|
Personally I think my approach is easier on the developers who have to work with Tauri. It's directer ("set the mode of operation", instead of "check for an ExitRequested event and then callback to prevent the exit") and I think it more clearly communicates the intention of the code. Also, this is a personal preference but I always like to make "discoverable" APIs - if there's a function From a technical standpoint regarding the internal architecture I think my attempt also a little simpler because the data only flows one way (there's no need for a "prevent exit" callback). But ultimately it's not my call, of course. It depends on how opinionated y'all want to be with this and what kind of architecture you prefer for the library. |
Your approach is fine but I think we should do something similar to how we stop closing the window for two reasons:
|
That's a fair point. I had considered ease of use over consistency but both are indeed important. Which other APIs on the Rust side use cancelable events in this way? So I can check out how it's implemented for those cases and see if maybe I can implement something similar. |
Currently only Window close event |
I've created a test on my fork of what the .run(|app, event| {
if let Event::ExitRequested { api, .. } = event {
api.prevent_exit();
}
}); I also added an .on_system_tray_event(|app, event| {
app.exit(0);
}) Let me know if this approach looks good enough to start a PR (where we can then discuss the actual underlying code & implementation). |
Looks good, would love to see a PR.
that won't be necessary, you can remove it. Tao will handle this automatically in the next release. |
PR created #2293 |
…exiting (#2293) Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Is your feature request related to a problem? Please describe.
I am building an app that should "live" in the system tray. The app window can be closed and later reopened by clicking on the tray icon. However, when the last window of the app closes, Tauri exits.
Describe the solution you'd like
I would like an option to keep the app running after all windows are closed, so that I can create a new window when the user clicks on the tray icon.
Describe alternatives you've considered
Hiding the window instead of closing it will keep the app active, so this is a possible workaround. But this means that the window still exists in memory and still uses resources while that isn't necessary.
The text was updated successfully, but these errors were encountered: