Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add setting child window #43

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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