-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathmultiwindow_with_tray_icon.rs
38 lines (32 loc) · 1.14 KB
/
multiwindow_with_tray_icon.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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!" }
}
}