Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace WebDemoExe
/// </summary>
public partial class MainWindow : Window
{
private string _appDomain = "webdemoexe.localhost";

CoreWebView2Environment _webViewEnvironment;
CoreWebView2Environment WebViewEnvironment
{
Expand Down Expand Up @@ -76,6 +78,7 @@ public MainWindow()

case XmlNodeType.Text:
if (currentTag.Equals("title")) dialogTitle = reader.Value;
if (currentTag.Equals("domain")) _appDomain = reader.Value;
Comment thread
mrautio marked this conversation as resolved.
if (currentTag.Equals("autostart")) autostart = XmlConvert.ToBoolean(reader.Value);
if (currentTag.Equals("propagatekeys")) _propagateKeys = XmlConvert.ToBoolean(reader.Value);
break;
Expand Down Expand Up @@ -220,9 +223,7 @@ void ReloadIfSelectedByUser(string caption, string message)

bool IsAppContentUri(Uri source)
{
// Sample virtual host name for the app's content.
// See CoreWebView2.SetVirtualHostNameToFolderMapping: https://learn.microsoft.com/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping
return source.Host == "appassets.example";
return source.Host == _appDomain;
}

if (e.ProcessFailedKind == CoreWebView2ProcessFailedKind.FrameRenderProcessExited)
Expand Down Expand Up @@ -362,7 +363,7 @@ private string GetRuntimePath(CoreWebView2 webView2)

private string GetStartPageUri(CoreWebView2 webView2)
{
string uri = "https://appassets.example/index.html";
string uri = $"https://{_appDomain}/index.html";
if (webView2 == null)
{
return uri;
Expand All @@ -381,7 +382,7 @@ void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2Init
if (e.IsSuccess)
{
// Setup host resource mapping for local files
webView.CoreWebView2.SetVirtualHostNameToFolderMapping("appassets.example", "demo", CoreWebView2HostResourceAccessKind.DenyCors);
webView.CoreWebView2.SetVirtualHostNameToFolderMapping(_appDomain, "demo", CoreWebView2HostResourceAccessKind.DenyCors);
// Set StartPage Uri
webView.Source = new Uri(GetStartPageUri(webView.CoreWebView2));

Expand Down
68 changes: 10 additions & 58 deletions WebDemoExe.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<NoWin32Manifest>true</NoWin32Manifest>
<Configurations>Debug;Release</Configurations>
<ApplicationIcon>icon.ico</ApplicationIcon>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>5</WarningLevel>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition="'$(Platform)'=='x64'">
<PlatformTarget>x64</PlatformTarget>
Expand All @@ -20,63 +26,9 @@
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Content Include="icon_.ico" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1724-prerelease" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
</ItemGroup>
<ItemGroup>
<None Update="assets\assets\lib_hdr_studiosmall.rgbe.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\assets\mitch-harris-cPZ21gvclO8-unsplash__1_.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\assets\Virgill-LJ-Box1.mp3">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\cables.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\credits.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\doc.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\index.html">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\js\anaglyph_3d1_backup.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\js\anaglyph_3d1_backup_nopath.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\js\anaglyph_3d2_backup.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\js\anaglyph_3d2_backup_nopath.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\js\patch.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\legal.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\LICENCE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\readme.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\scene.org.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3351.48" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="4.14.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" PrivateAssets="all" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="all" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## webDemoExe

[![Build](https://github.com/pandrr/WebDemoExe/actions/workflows/build.yml/badge.svg)](https://github.com/pandrr/WebDemoExe/actions/workflows/build.yml)

wrap your web demo into a windows exe format, just like a native demo.

[download](https://github.com/pandrr/WebDemoExe/releases)
Expand All @@ -19,6 +21,7 @@ wrap your web demo into a windows exe format, just like a native demo.
- edit webdemoexe.xml and change the title
- rename webdemoexe.exe to your demo name
- add `<autostart/>` into the config to not show the dialog at all and start directly, don't do this if you want to play audio without having another user interaction!
- add `<domain>yourdomain.localhost</domain>` to customize the virtual host domain (defaults to webdemoexe.localhost)

- if the url contains "webdemoexe_exit" it will exit, e.g. use window.location.hash="webdemoexe_exit"

Expand Down