Files
DPM/src-tauri/vendor/wry/src/custom_protocol_workaround.rs
T
Pine a143b94ac1 fix(tauri): patch wry 绕过 macOS 26 启动崩溃(NSBundle bundleWithIdentifier SIGTRAP)
- 根因:tauri 启动探测 webview 版本时调用 wry platform_webview_version()
  → NSBundle::bundleWithIdentifier(com.apple.WebKit) 在 macOS 26 (Tahoe) 上
  触发 CFBundle/CFRelease 断言崩溃(EXC_BREAKPOINT)
- 方案:vendor 本地 wry 0.55.1,该函数改为安全占位返回(仅被上层用作 is_ok() 探测,
  返回值无实际用途),[patch.crates-io] 指向本地副本
- 附带:移除 NSBundle import,消除 unused 警告
2026-08-18 01:53:34 +08:00

57 lines
2.0 KiB
Rust

//! - WebView2 supports non-standard protocols only on Windows 10+, so we have to use a workaround.
//! See <https://github.com/MicrosoftEdge/WebView2Feedback/issues/73>
//! - On Android, there's no API for registering custom protocols, so this workaround is also used.
//!
//! The process looks like this:
//!
//! 1. Use [`apply_uri_work_around`] to convert the URI we want to navigate to
//! 2. Intercept http(s) requests, test the request URI against [`is_work_around_uri`],
//! if it matches, we apply [`revert_uri_work_around`] to the URI and feed it to the custom protocol handler
/// If the URI is a work around URI for this protocol which starts with `{http_or_https}://{protocol}.`
pub fn is_work_around_uri(uri: &str, http_or_https: &str, protocol: &str) -> bool {
uri
.strip_prefix(http_or_https)
.and_then(|rest| rest.strip_prefix("://"))
.and_then(|rest| rest.strip_prefix(protocol))
.and_then(|rest| rest.strip_prefix("."))
.is_some()
}
/// Conveting `{protocol}://localhost/abc` to `{http_or_https}://{protocol}.localhost/abc`
pub fn apply_uri_work_around(uri: &str, http_or_https: &str, protocol: &str) -> String {
uri.replace(
&original_uri_prefix(protocol),
&work_around_uri_prefix(http_or_https, protocol),
)
}
/// Conveting `{http_or_https}://{protocol}.localhost/abc` back to `{protocol}://localhost/abc`
pub fn revert_uri_work_around(uri: &str, http_or_https: &str, protocol: &str) -> String {
uri.replace(
&work_around_uri_prefix(http_or_https, protocol),
&original_uri_prefix(protocol),
)
}
pub fn original_uri_prefix(protocol: &str) -> String {
format!("{protocol}://")
}
pub fn work_around_uri_prefix(http_or_https: &str, protocol: &str) -> String {
format!("{http_or_https}://{protocol}.")
}
#[cfg(test)]
mod tests {
use super::is_work_around_uri;
#[test]
fn checks_if_custom_protocol_uri() {
let scheme = "http";
let uri = "http://wry.localhost/path/to/page";
assert!(is_work_around_uri(uri, scheme, "wry"));
assert!(!is_work_around_uri(uri, scheme, "asset"));
}
}