Files
archived-wry/examples/reparent.rs
Jason Tsai 0abc221ca0 refactor(macos): migrate to objc2 (#1316)
* migrate drag & drop

* refactor: migrate to `dpi` crate (#1202)

* refactor: migrate to `dpi` crate

closes #1172

* macOS

* linux

* fix doctests

* imports

* more doctests

* fix android and ios

* Update examples/winit.rs

Co-authored-by: Jason Tsai <jason@pews.dev>

* Update src/webview2/mod.rs

---------

Co-authored-by: Jason Tsai <jason@pews.dev>

* fix(windows): avoid double-free the controller (#1206)

* fix(linux): Disable deprecated applicationCache web api. (#1207)

fixes https://github.com/tauri-apps/tauri/issues/9300
ref https://github.com/WebKit/WebKit/pull/23382

* fix(wkwebview): menu shortcuts (#1208)

* fix(wkwebview): menu shortcuts

* Update wkwebview.md

* Apply Version Updates From Current Changes (#1203)

Co-authored-by: amrbashir <amrbashir@users.noreply.github.com>

* migrate to `objc2`

* fix(macos): response body being double freed

* fix(macos): eval callback NSStrgin convertion error

* chore: remove objc dependency

* refactor(macos): migrate WebViewDelegate

* refactor(macos): migrate proxy to objc2

* refactor(macos): migrate document title change observer to objc2

* refactor(macos): move drag&drop handler to delegate

* refactor(macos): move ipc_handler into WryWebViewDelegate

* refactor(macos): migrate download handler

* fix(macos): prevent unsafe async custom protocol panic

* chore: target os import

* refactor(ios): migrate to objc2

* refactor(macos): migrate WebViewUIDelegate to objc2

* refactor(macos): migrate WryWebViewParent to objc2

* refactor(macos): move custom class to individual files

* chore: fix clippy

* refector: use reference for task. use objc2::exception::catch.

* fix(dnd): use msg_send super and impl NSDraggingDestination

* chore: call msg_send super

* fix: wrap Box<dyn FnMut(..)> with RefCell

* chore(deps): update rust crate tao to 0.29 (#1343)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* refactor: use bitflags way to handle mask bit manipulation

* WIP: refactor(ios): add wkwebview for ios

* Update Cargo.toml

Co-authored-by: Mads Marquart <mads@marquart.dk>

* fix: remove `.copy()` from RcBlock

* add change file

* lint

* fmt

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de>
Co-authored-by: thewh1teagle <61390950+thewh1teagle@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: amrbashir <amrbashir@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
2024-10-11 16:11:10 -03:00

112 lines
2.8 KiB
Rust

// Copyright 2020-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
use tao::{
event::{ElementState, Event, KeyEvent, WindowEvent},
event_loop::{ControlFlow, EventLoop},
keyboard::Key,
window::WindowBuilder,
};
use wry::WebViewBuilder;
#[cfg(target_os = "macos")]
use {objc2_app_kit::NSWindow, tao::platform::macos::WindowExtMacOS, wry::WebViewExtMacOS};
#[cfg(target_os = "windows")]
use {tao::platform::windows::WindowExtWindows, wry::WebViewExtWindows};
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
use {
tao::platform::unix::WindowExtUnix,
wry::{WebViewBuilderExtUnix, WebViewExtUnix},
};
fn main() -> wry::Result<()> {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let window2 = WindowBuilder::new().build(&event_loop).unwrap();
let builder = WebViewBuilder::new().with_url("https://tauri.app");
#[cfg(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
))]
let webview = builder.build(&window)?;
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
let webview = {
use tao::platform::unix::WindowExtUnix;
let vbox = window.default_vbox().unwrap();
builder.build_gtk(vbox)?
};
let mut webview_container = window.id();
event_loop.run(move |event, _event_loop, control_flow| {
*control_flow = ControlFlow::Wait;
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
event:
KeyEvent {
logical_key: Key::Character("x"),
state: ElementState::Pressed,
..
},
..
},
..
} => {
let new_parent = if webview_container == window.id() {
&window2
} else {
&window
};
webview_container = new_parent.id();
#[cfg(target_os = "macos")]
webview
.reparent(new_parent.ns_window() as *mut NSWindow)
.unwrap();
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "ios",
target_os = "android"
)))]
webview
.reparent(new_parent.default_vbox().unwrap())
.unwrap();
#[cfg(target_os = "windows")]
webview.reparent(new_parent.hwnd()).unwrap();
}
_ => {}
}
});
}