Added close behaviour option for specific window (#3754)

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
KlemenandJonathan Kelley authored and GitHub committed 2025-07-01 18:59:44 -07:00
1 parent c3c7e5f705
commit 9573af115a
10 files changed
+172 -28

No files matched your search

+6 -3
View File
@@ -5,12 +5,15 @@
//! own context, root elements, etc.
use dioxus::prelude::*;
use dioxus::{desktop::Config, desktop::WindowCloseBehaviour};
use dioxus::{desktop::Config, desktop::DefaultWindowCloseBehaviour};
fn main() {
dioxus::LaunchBuilder::desktop()
// We can choose the close behavior of the last window to hide. See WindowCloseBehaviour for more options.
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::LastWindowHides))
// We can choose the close behavior of the last window to hide. See DefaultWindowCloseBehaviour for more options.
.with_cfg(
Config::new()
.with_default_window_close_behaviour(DefaultWindowCloseBehaviour::LastWindowHides),
)
.launch(app);
}
+38
View File
@@ -0,0 +1,38 @@
//! Multiwindow with tray icon example
//!
//! This example shows how to implement a simple multiwindow application and tray icon using dioxus.
//! This works by spawning a new window when the user clicks a button. We have to build a new virtualdom which has its
//! own context, root elements, etc.
use dioxus::desktop::{
trayicon::{default_tray_icon, init_tray_icon},
Config, WindowCloseBehaviour,
};
use dioxus::prelude::*;
fn main() {
dioxus::LaunchBuilder::desktop()
// We can choose the close behavior of this window to hide. See WindowCloseBehaviour for more options.
.with_cfg(Config::new().with_window_close_behaviour(WindowCloseBehaviour::WindowHides))
.launch(app);
}
fn app() -> Element {
// async should not be needed, check if issue 3542 has been resolved
let onclick = move |_| async {
let dom = VirtualDom::new(popup);
dioxus::desktop::window().new_window(dom, Default::default());
};
init_tray_icon(default_tray_icon(), None);
rsx! {
button { onclick, "New Window" }
}
}
fn popup() -> Element {
rsx! {
div { "This is a popup window!" }
}
}
+5 -2
View File
@@ -8,12 +8,15 @@
use dioxus::desktop::tao::event::Event as WryEvent;
use dioxus::desktop::tao::event::WindowEvent;
use dioxus::desktop::use_wry_event_handler;
use dioxus::desktop::{Config, WindowCloseBehaviour};
use dioxus::desktop::{Config, DefaultWindowCloseBehaviour};
use dioxus::prelude::*;
fn main() {
dioxus::LaunchBuilder::desktop()
.with_cfg(Config::new().with_close_behaviour(WindowCloseBehaviour::CloseWindow))
.with_cfg(
Config::new()
.with_default_window_close_behaviour(DefaultWindowCloseBehaviour::WindowsCloses),
)
.launch(app)
}