Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to reflect CreateCoreWebView2EnvironmentOptions to webview2? #10

Closed
keiya01 opened this issue Jul 19, 2022 · 5 comments
Closed

Comments

@keiya01
Copy link

keiya01 commented Jul 19, 2022

Thank you for creating great crates.
I have some questions.

I want to customize CreateCoreWebView2EnvironmentOptions.
And I implemented feature to create environment like the following.
This is customizing language through CreateCoreWebView2EnvironmentOptions.

CreateCoreWebView2EnvironmentCompletedHandler::wait_for_async_operation(
  Box::new(move |environmentcreatedhandler| unsafe {
    let options = {
      let options: ICoreWebView2EnvironmentOptions =
        CoreWebView2EnvironmentOptions::default().into();

      // Setting user's system language
      let lcid = Globalization::GetUserDefaultUILanguage();
      let mut lang = [0; MAX_LOCALE_NAME as usize];
      Globalization::LCIDToLocaleName(
        lcid as u32,
        &mut lang,
        Globalization::LOCALE_ALLOW_NEUTRAL_NAMES,
      );
      options
        .SetLanguage(PCWSTR(lang.as_ptr()))
        .map_err(webview2_com::Error::WindowsError)?;
      options
    };

    // remove "mini menu" - See https://github.com/tauri-apps/wry/issues/535
    let _ = options.SetAdditionalBrowserArguments("--disable-features=msWebOOUI,msPdfOOUI");
    CreateCoreWebView2EnvironmentWithOptions(
      PCWSTR::default(),
      PCWSTR::default(),
      options,
      environmentcreatedhandler,
    )
    .map_err(webview2_com::Error::WindowsError)
  }),
  Box::new(move |error_code, environment| {
    error_code?;
    tx.send(environment.ok_or_else(|| windows::core::Error::from(E_POINTER)))
      .expect("send over mpsc channel");
    Ok(())
  }),
)?;

And call environment.CreateCoreWebView2Controller then get CoreWebView2 and navigate webview2.
But My custom language is not reflected.

To resolve this problem, I think webview2 need to call EnsureCoreWebView2Async(CoreWebView2Environment, CoreWebView2ControllerOptions) or set environment to CreationProperties like written in here.
Or does webview2-com crate reflect environment implecitly?

Thank you for reading my issue.

@keiya01
Copy link
Author

keiya01 commented Jul 19, 2022

I'm sorry I may misunderstand...

@keiya01 keiya01 closed this as completed Jul 19, 2022
@wravery
Copy link
Owner

wravery commented Jul 19, 2022

The EnsureCoreWebView2Async API is part of the WinRT wrapper around the COM APIs, that's what the doc was describing. I think the sample code you showed should work with the COM APIs and the wrappers in this crate. It should be setting that option on the environment, and then all webviews created from that environment should respect it. The Language property is documented here as get_Language.

You can target the WinRT wrapper with just the windows crate, and it even gives you safe wrappers, which is nice. However, this crate exists and targets the unsafe COM wrappers with a custom winmd file because you can't use the WinRT wrapper on older versions of Windows. The COM APIs work all the way back to Win7 last time I tested them, but the WinRT APIs only work with Win11 or later releases of Win10 with support for the new runtime. That's also why WRY uses this crate, being able to target the widest range of OS versions is important for Tauri.

@keiya01
Copy link
Author

keiya01 commented Jul 20, 2022

Thank you for your reply and great description.
I see. I will research why my code is not working.

@keiya01
Copy link
Author

keiya01 commented Jul 20, 2022

@wravery
Do you know the reason why this branch is not working?
And if you know the reason, could you tell me about a wrong point...?
Thank you for your help...

@wravery
Copy link
Owner

wravery commented Aug 2, 2022

@wravery Do you know the reason why this branch is not working? And if you know the reason, could you tell me about a wrong point...? Thank you for your help...

I finally had a chance to look at the branch, but it looks like it's been deleted or merged. Were you able to get it working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants