multiwindow_with_tray_icon.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //! Multiwindow with tray icon example
  2. //!
  3. //! This example shows how to implement a simple multiwindow application and tray icon using dioxus.
  4. //! This works by spawning a new window when the user clicks a button. We have to build a new virtualdom which has its
  5. //! own context, root elements, etc.
  6. use dioxus::desktop::{
  7. trayicon::{default_tray_icon, init_tray_icon},
  8. Config, WindowCloseBehaviour,
  9. };
  10. use dioxus::prelude::*;
  11. fn main() {
  12. dioxus::LaunchBuilder::desktop()
  13. // We can choose the close behavior of this window to hide. See WindowCloseBehaviour for more options.
  14. .with_cfg(Config::new().with_window_close_behaviour(WindowCloseBehaviour::WindowHides))
  15. .launch(app);
  16. }
  17. fn app() -> Element {
  18. // async should not be needed, check if issue 3542 has been resolved
  19. let onclick = move |_| async {
  20. let dom = VirtualDom::new(popup);
  21. dioxus::desktop::window().new_window(dom, Default::default());
  22. };
  23. init_tray_icon(default_tray_icon(), None);
  24. rsx! {
  25. button { onclick, "New Window" }
  26. }
  27. }
  28. fn popup() -> Element {
  29. rsx! {
  30. div { "This is a popup window!" }
  31. }
  32. }