tweaks to the LastWindowClose to make it more imperative

This commit is contained in:
Jonathan Kelley committed 2025-07-01 19:58:41 -07:00
1 parent 9573af115a
commit ff762cec84
11 files changed
+74 -214

No files matched your search

+2 -10
View File
@@ -5,22 +5,14 @@
//! own context, root elements, etc.
use dioxus::prelude::*;
use dioxus::{desktop::Config, desktop::DefaultWindowCloseBehaviour};
fn main() {
dioxus::LaunchBuilder::desktop()
// 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);
dioxus::launch(app);
}
fn app() -> Element {
let onclick = move |_| {
let dom = VirtualDom::new(popup);
dioxus::desktop::window().new_window(dom, Default::default());
dioxus::desktop::window().new_window(VirtualDom::new(popup), Default::default());
};
rsx! {
+18 -12
View File
@@ -3,31 +3,37 @@
//! 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.
//!
//! This is useful for apps that incorporate settings panels or persistent windows like Raycast.
use dioxus::desktop::{
trayicon::{default_tray_icon, init_tray_icon},
Config, WindowCloseBehaviour,
window, 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);
dioxus::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());
};
use_hook(|| {
// Set the close behavior for the main window
// This will hide the window instead of closing it when the user clicks the close button
window().set_close_behavior(WindowCloseBehaviour::WindowHides);
init_tray_icon(default_tray_icon(), None);
// Initialize the tray icon with a default icon and no menu
// This will provide the tray into context for the application
init_tray_icon(default_tray_icon(), None)
});
rsx! {
button { onclick, "New Window" }
button {
onclick: move |_| {
window().new_window(VirtualDom::new(popup), Default::default());
},
"New Window"
}
}
}