fix(windows): call with_webview on built window, import COREWEBVIEW2_PERMISSION_KIND type
Build Lotus Chat Desktop / build-windows (push) Successful in 27m6s
Build Lotus Chat Desktop / build-linux (push) Successful in 20m21s
Build Lotus Chat Desktop / update-manifest (push) Failing after 3s

with_webview is on WebviewWindow (the built window), not WebviewWindowBuilder.
Also import COREWEBVIEW2_PERMISSION_KIND as a type for the out-param zero-init.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-10 10:05:49 -04:00
parent 07327845b3
commit 4b71e80636
+7 -8
View File
@@ -26,21 +26,22 @@ pub fn run() {
};
let app_handle = app.handle().clone();
let builder = WebviewWindowBuilder::new(app, "main".to_string(), window_url)
let window = WebviewWindowBuilder::new(app, "main".to_string(), window_url)
.title("Cinny")
.disable_drag_drop_handler()
.on_new_window(move |url, _features| {
let _ = app_handle.opener().open_url(url.as_str(), None::<&str>);
NewWindowResponse::Deny
});
})
.build()?;
// Grant camera and microphone to WebView2 automatically.
// Windows requires an explicit PermissionRequested COM event handler;
// macOS uses Info.plist.
// Windows requires an explicit PermissionRequested COM event handler.
#[cfg(target_os = "windows")]
let builder = builder.with_webview(|webview| {
window.with_webview(|webview| {
use webview2_com::{
Microsoft::Web::WebView2::Win32::{
COREWEBVIEW2_PERMISSION_KIND,
COREWEBVIEW2_PERMISSION_KIND_CAMERA,
COREWEBVIEW2_PERMISSION_KIND_MICROPHONE,
COREWEBVIEW2_PERMISSION_STATE_ALLOW,
@@ -53,7 +54,6 @@ pub fn run() {
let handler = PermissionRequestedEventHandler::create(Box::new(
|_sender, args| {
if let Some(args) = args {
// PermissionKind uses a COM out-param pattern
let mut kind = COREWEBVIEW2_PERMISSION_KIND(0);
unsafe { args.PermissionKind(&mut kind) }?;
if kind == COREWEBVIEW2_PERMISSION_KIND_MICROPHONE
@@ -70,9 +70,8 @@ pub fn run() {
let mut token = Default::default();
let _ = unsafe { core.add_PermissionRequested(&handler, &mut token) };
}
});
})?;
builder.build()?;
Ok(())
})
.run(context)