Using HTMLViewer on MacOS and WebView2 on Windows

Hi all,

I have an app that displays some HTML content. On MacOS, I use a DesktopHTMLViewer and all is well. On Windows, I want to avoid the huge filesize overhead of the HTMLViewer and want to use MBS WebView2 instead.

I have two windows: wnd_HTMLMac and wnd_HTMLWin, wnd_HTMLMac uses the HTMLViewer while wnd_HTMLWin uses WebView2:

Sub Pressed() Handles Pressed
  #If TargetMacOS Then
     wnd_HTMLMac.ShowModal Self
#ElseIf TargetWindows Then
     wnd_HTMLWin.ShowModal Self
#EndIf
End Sub

The problem is when I compile for Windows, the Chromium runtime files are still included because it’s the same project file as the Mac version. The majority of the code is shared between the Mac version and the Windows version.

How can I tell the Xojo compiler to only include wnd_HTMLMac on the MacOS compile and only include wnd_HTMLWin on the Windows compile? I don’t want to have to maintain two different project files because that would be a nightmare to make changes to logic that is shared between the platforms, and also to keep track of version numbers and such.

Thanks in advance.

1 Like

Latest Xojo?
I think this issue was fixed in a recent Xojo update.

Yes, 2024R2.1.

In the docs for conditional compilation it says:

You can indicate that a particular project item (excluding Windows, Web Pages and iOS Views) should only be included for certain project types.

So it seems I can not exclude these windows based on platform. Is there another way to do it?

Figured it out!

You have to change the Super of your DesktopHTMLViewer controls to the APIv1 HTMLViewer, then you can select Native as the renderer and the Chromium framework is not included in the compile on Windows. MacOS should be unaffected since it’s always using webkit/Safari anyway.

1 Like

I solved the problem by using a container which mimics much of the DesktopHTMLViewer, then creates the required controls on demand. Now I can drag it to a window and use it like I would a built-in DesktopHTMLViewer.

4 Likes

This is fantastic, thank you for sharing!