Skip to content

Commit

Permalink
feat: add setting child window (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
tu6ge authored Dec 10, 2024
1 parent 15a3949 commit b9b08d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2.0.0", features = [] }

[dependencies]
tauri = { version = "2.0.0", features = ["macos-private-api", "tray-icon", "image-png"] }
tauri = { version = "2.0.0", features = ["macos-private-api", "tray-icon", "image-png", "unstable"] }
tauri-plugin-shell = "2.0.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
25 changes: 21 additions & 4 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ fn enable_tray(app: &mut tauri::App) {
image::Image,
menu::{Menu, MenuItem},
tray::TrayIconBuilder,
webview::WebviewBuilder,
};

let image = Image::from_path("icons/32x32.png").unwrap();
Expand All @@ -240,10 +241,26 @@ fn enable_tray(app: &mut tauri::App) {
.on_menu_event(|app, event| match event.id.as_ref() {
"settings" => {
println!("settings menu item was clicked");
let app_handle = app.app_handle();
if let Some(window) = app_handle.get_webview_window("settings") {
let _ = window.show();
let _ = window.set_focus();
let window = app.get_webview_window("settings");
if let Some(window) = window {
window.show().unwrap();
window.set_focus().unwrap();
} else {
let window = tauri::window::WindowBuilder::new(app, "Settings")
.build()
.unwrap();
let webview_builder = WebviewBuilder::new(
"Settings",
tauri::WebviewUrl::App("index.html".into()),
);
let webview = window
.add_child(
webview_builder,
tauri::LogicalPosition::new(0, 0),
window.inner_size().unwrap(),
)
.unwrap();

}
}
"quit" => {
Expand Down

0 comments on commit b9b08d7

Please # to comment.