2023-02-19 16:17:49 +03:00
|
|
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
2022-03-23 19:30:44 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-02-18 22:23:09 +03:00
|
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
2022-03-23 19:30:44 +03:00
|
|
|
|
2023-10-27 16:00:59 +03:00
|
|
|
use tauri::{
|
|
|
|
command,
|
|
|
|
window::{PageLoadEvent, WindowBuilder},
|
|
|
|
Window, WindowUrl,
|
|
|
|
};
|
2022-03-23 19:30:44 +03:00
|
|
|
|
2022-03-24 02:45:43 +03:00
|
|
|
#[command]
|
2022-05-06 02:57:32 +03:00
|
|
|
async fn create_child_window(id: String, window: Window) {
|
|
|
|
let child = WindowBuilder::new(&window, id, WindowUrl::default())
|
2022-03-24 02:45:43 +03:00
|
|
|
.title("Child")
|
|
|
|
.inner_size(400.0, 300.0);
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
2022-05-06 02:57:32 +03:00
|
|
|
let child = child.parent_window(window.ns_window().unwrap());
|
2022-03-24 02:45:43 +03:00
|
|
|
#[cfg(windows)]
|
2022-05-06 02:57:32 +03:00
|
|
|
let child = child.parent_window(window.hwnd().unwrap());
|
2022-03-24 02:45:43 +03:00
|
|
|
|
|
|
|
child.build().unwrap();
|
|
|
|
}
|
2022-03-23 19:30:44 +03:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
tauri::Builder::default()
|
2023-10-27 16:00:59 +03:00
|
|
|
.on_page_load(|window, payload| {
|
|
|
|
if payload.event() == PageLoadEvent::Finished {
|
|
|
|
let label = window.label().to_string();
|
|
|
|
window.listen("clicked".to_string(), move |_payload| {
|
|
|
|
println!("got 'clicked' event on window '{label}'");
|
|
|
|
});
|
|
|
|
}
|
2022-03-23 19:30:44 +03:00
|
|
|
})
|
2022-03-24 02:45:43 +03:00
|
|
|
.invoke_handler(tauri::generate_handler![create_child_window])
|
2022-03-31 20:50:33 +03:00
|
|
|
.setup(|app| {
|
|
|
|
WindowBuilder::new(app, "main".to_string(), WindowUrl::default())
|
|
|
|
.title("Main")
|
|
|
|
.inner_size(600.0, 400.0)
|
|
|
|
.build()?;
|
|
|
|
Ok(())
|
2022-05-06 02:57:32 +03:00
|
|
|
})
|
2022-07-04 02:26:32 +03:00
|
|
|
.run(tauri::generate_context!(
|
|
|
|
"../../examples/parent-window/tauri.conf.json"
|
|
|
|
))
|
2022-03-23 19:30:44 +03:00
|
|
|
.expect("failed to run tauri application");
|
|
|
|
}
|