mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-01 10:01:07 +02:00
fix(examples): parent window example freezing and crashing, closes #4064
This commit is contained in:
@@ -39,15 +39,16 @@
|
||||
})
|
||||
|
||||
var createWindowButton = document.createElement('button')
|
||||
var windowId = Math.random().toString().replace('.', '')
|
||||
var windowNumber = 1
|
||||
createWindowButton.innerHTML = 'Create child window '+windowNumber
|
||||
createWindowButton.innerHTML = 'Create child window ' + windowNumber
|
||||
createWindowButton.addEventListener('click', function () {
|
||||
runCommand('create_child_window', { id: 'child-'+windowNumber })
|
||||
runCommand('create_child_window', { id: `child-${windowId}-${windowNumber}` })
|
||||
windowNumber += 1
|
||||
createWindowButton.innerHTML = 'Create child window '+windowNumber
|
||||
createWindowButton.innerHTML = 'Create child window ' + windowNumber
|
||||
})
|
||||
container.appendChild(createWindowButton)
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
@@ -7,23 +7,18 @@
|
||||
windows_subsystem = "windows"
|
||||
)]
|
||||
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
use tauri::Manager;
|
||||
use tauri::{command, window::WindowBuilder, AppHandle, WindowUrl};
|
||||
use tauri::{command, window::WindowBuilder, Window, WindowUrl};
|
||||
|
||||
#[command]
|
||||
fn create_child_window(id: String, app: AppHandle) {
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
let main = app.get_window("main").unwrap();
|
||||
|
||||
let child = WindowBuilder::new(&app, id, WindowUrl::default())
|
||||
async fn create_child_window(id: String, window: Window) {
|
||||
let child = WindowBuilder::new(&window, id, WindowUrl::default())
|
||||
.title("Child")
|
||||
.inner_size(400.0, 300.0);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let child = child.parent_window(main.ns_window().unwrap());
|
||||
let child = child.parent_window(window.ns_window().unwrap());
|
||||
#[cfg(windows)]
|
||||
let child = child.parent_window(main.hwnd().unwrap());
|
||||
let child = child.parent_window(window.hwnd().unwrap());
|
||||
|
||||
child.build().unwrap();
|
||||
}
|
||||
@@ -43,7 +38,7 @@ fn main() {
|
||||
.inner_size(600.0, 400.0)
|
||||
.build()?;
|
||||
Ok(())
|
||||
}) // safe to unwrap: window label is valid
|
||||
})
|
||||
.run(tauri::generate_context!(
|
||||
"../../examples/parent-window/tauri.conf.json"
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user