2022-08-28 21:13:21 +03:00
|
|
|
// Copyright 2019-2022 Tauri Programme within The Commons Conservancy
|
2022-03-23 19:30:44 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
#![cfg_attr(
|
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
|
|
windows_subsystem = "windows"
|
|
|
|
)]
|
|
|
|
|
2022-05-06 02:57:32 +03:00
|
|
|
use tauri::{command, window::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()
|
|
|
|
.on_page_load(|window, _payload| {
|
|
|
|
let label = window.label().to_string();
|
|
|
|
window.listen("clicked".to_string(), move |_payload| {
|
|
|
|
println!("got 'clicked' event on window '{}'", label);
|
|
|
|
});
|
|
|
|
})
|
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");
|
|
|
|
}
|