Skip to content

Commit eaa7bd3

Browse files
javiercnMackinnon Buck
authored andcommitted
Switch to use staticwebassets for webview
1 parent dd9fbd7 commit eaa7bd3

File tree

4 files changed

+67
-24
lines changed

4 files changed

+67
-24
lines changed

src/Components/WebView/Samples/PhotinoPlatform/testassets/PhotinoTestApp/PhotinoTestApp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<OutputType>Exe</OutputType>
66
<IsShippingPackage>false</IsShippingPackage>
77
<SignAssembly>false</SignAssembly>
8+
<_WebViewAssetsBasePath>..\..\..\..\..\Web.JS\dist\Release\</_WebViewAssetsBasePath>
9+
<_BlazorModulesFilePath>..\..\..\..\WebView\src\blazor.modules.json</_BlazorModulesFilePath>
810
</PropertyGroup>
911

1012
<Import Project="..\..\..\..\WebView\src\buildTransitive\Microsoft.AspNetCore.Components.WebView.props" />

src/Components/WebView/WebView/src/Microsoft.AspNetCore.Components.WebView.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
55
<Description>Build desktop applications with Blazor and a webview.</Description>
6-
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
76
<EmbeddedFilesManifestFileName>Microsoft.Extensions.FileProviders.Embedded.Manifest.xml</EmbeddedFilesManifestFileName>
87
<IsShippingPackage>true</IsShippingPackage>
98
<DefineConstants>$(DefineConstants);BLAZOR_WEBVIEW</DefineConstants>
@@ -73,9 +72,11 @@
7372

7473
<Target Name="_AddEmbeddedBlazorWebView" BeforeTargets="_CalculateEmbeddedFilesManifestInputs" DependsOnTargets="_CheckBlazorWebViewJSPath">
7574
<ItemGroup>
76-
<EmbeddedResource Include="blazor.modules.json" LogicalName="_framework/blazor.modules.json" />
77-
<EmbeddedResource Include="$(BlazorWebViewJSFile)" LogicalName="_framework/$(BlazorWebViewJSFilename)" />
78-
<EmbeddedResource Include="$(BlazorWebViewJSFile).map" LogicalName="_framework/$(BlazorWebViewJSFilename).map" Condition="Exists('$(BlazorWebViewJSFile).map')" />
75+
<!--<EmbeddedResource Include="blazor.modules.json" LogicalName="_framework/blazor.modules.json" />-->
76+
<!--<EmbeddedResource Include="$(BlazorWebViewJSFile)" LogicalName="_framework/$(BlazorWebViewJSFilename)" />
77+
<EmbeddedResource Include="$(BlazorWebViewJSFile).map" LogicalName="_framework/$(BlazorWebViewJSFilename).map" Condition="Exists('$(BlazorWebViewJSFile).map')" />-->
78+
<Content Include="$(BlazorWebViewJSFile)" Pack="true" PackagePath="staticwebassets/$(BlazorWebViewJSFilename)" />
79+
<Content Include="blazor.modules.json" Pack="true" PackagePath="staticwebassets/blazor.modules.json" />
7980
</ItemGroup>
8081
</Target>
8182

src/Components/WebView/WebView/src/StaticContentProvider.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ internal sealed class StaticContentProvider
1212
private readonly Uri _appBaseUri;
1313
private readonly string _hostPageRelativePath;
1414
private static readonly FileExtensionContentTypeProvider ContentTypeProvider = new();
15-
private static readonly ManifestEmbeddedFileProvider _manifestProvider =
16-
new ManifestEmbeddedFileProvider(typeof(StaticContentProvider).Assembly);
15+
//private static readonly ManifestEmbeddedFileProvider _manifestProvider =
16+
// new ManifestEmbeddedFileProvider(typeof(StaticContentProvider).Assembly);
1717

1818
public StaticContentProvider(IFileProvider fileProvider, Uri appBaseUri, string hostPageRelativePath)
1919
{
@@ -34,8 +34,8 @@ public bool TryGetResponseContent(string requestUri, bool allowFallbackOnHostPag
3434
// If there's no match, fall back on serving embedded framework content
3535
string contentType;
3636
var found = TryGetFromFileProvider(relativePath, out content, out contentType)
37-
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType))
38-
|| TryGetFrameworkFile(relativePath, out content, out contentType);
37+
|| (allowFallbackOnHostPage && TryGetFromFileProvider(_hostPageRelativePath, out content, out contentType));
38+
//|| TryGetFrameworkFile(relativePath, out content, out contentType);
3939

4040
if (found)
4141
{
@@ -83,22 +83,22 @@ private bool TryGetFromFileProvider(string relativePath, out Stream content, out
8383
return false;
8484
}
8585

86-
private static bool TryGetFrameworkFile(string relativePath, out Stream content, out string contentType)
87-
{
88-
// We're not trying to simulate everything a real webserver does. We don't need to
89-
// support querystring parameters, for example. It's enough to require an exact match.
90-
var file = _manifestProvider.GetFileInfo(relativePath);
91-
if (file.Exists)
92-
{
93-
content = file.CreateReadStream();
94-
contentType = GetResponseContentTypeOrDefault(relativePath);
95-
return true;
96-
}
86+
//private static bool TryGetFrameworkFile(string relativePath, out Stream content, out string contentType)
87+
//{
88+
// // We're not trying to simulate everything a real webserver does. We don't need to
89+
// // support querystring parameters, for example. It's enough to require an exact match.
90+
// var file = _manifestProvider.GetFileInfo(relativePath);
91+
// if (file.Exists)
92+
// {
93+
// content = file.CreateReadStream();
94+
// contentType = GetResponseContentTypeOrDefault(relativePath);
95+
// return true;
96+
// }
9797

98-
content = default;
99-
contentType = default;
100-
return false;
101-
}
98+
// content = default;
99+
// contentType = default;
100+
// return false;
101+
//}
102102

103103
private static string GetResponseContentTypeOrDefault(string path)
104104
=> ContentTypeProvider.TryGetContentType(path, out var matchedContentType)
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
<Project>
22
<PropertyGroup>
3-
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
3+
<JSModuleManifestRelativePath>_framework/blazor.modules.json</JSModuleManifestRelativePath>
4+
<CompressionEnabled>false</CompressionEnabled>
45
</PropertyGroup>
6+
<PropertyGroup>
7+
<ResolveStaticWebAssetsInputsDependsOn>
8+
$(ResolveStaticWebAssetsInputsDependsOn);
9+
_AddBlazorWebViewAssets;
10+
</ResolveStaticWebAssetsInputsDependsOn>
11+
</PropertyGroup>
12+
13+
<Target Name="_AddBlazorWebViewAssets" DependsOnTargets="GenerateJSModuleManifestBuildStaticWebAssets">
14+
<PropertyGroup>
15+
<_WebViewAssetsBasePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\</_WebViewAssetsBasePath>
16+
<_BlazorModulesFilePath Condition="'$(_WebViewAssetsBasePath)' == ''">$(MSBuildThisFileDirectory)..\staticwebassets\blazor.modules.json</_BlazorModulesFilePath>
17+
</PropertyGroup>
18+
<ItemGroup>
19+
<_WebViewAssetCandidates Include="$(_WebViewAssetsBasePath)blazor.webview.js">
20+
<RelativePath>_framework/blazor.webview.js</RelativePath>
21+
</_WebViewAssetCandidates>
22+
<_WebViewAssetCandidates Include="$(_BlazorModulesFilePath)" Condition="'@(_ExistingBuildJSModules)' == ''">
23+
<RelativePath>_framework/blazor.modules.json</RelativePath>
24+
</_WebViewAssetCandidates>
25+
</ItemGroup>
26+
<DefineStaticWebAssets
27+
CandidateAssets="@(_WebViewAssetCandidates)"
28+
SourceId="$(PackageId)"
29+
ContentRoot="$(_WebViewAssetsBasePath)"
30+
SourceType="Discovered"
31+
AssetKind="All"
32+
AssetMode="All"
33+
AssetRole="Primary"
34+
FingerprintCandidates="true"
35+
BasePath="/">
36+
<Output TaskParameter="Assets" ItemName="_FrameworkStaticWebAsset" />
37+
</DefineStaticWebAssets>
38+
39+
<ItemGroup>
40+
<StaticWebAsset Include="@(_FrameworkStaticWebAsset)" />
41+
</ItemGroup>
42+
</Target>
43+
544
</Project>
45+

0 commit comments

Comments
 (0)