Skip to content

Commit 0a957c9

Browse files
committed
Fixes issue with Windows platform relative image paths
1 parent 323333a commit 0a957c9

File tree

6 files changed

+287
-274
lines changed

6 files changed

+287
-274
lines changed

apps/pwabuilder-google-play/services/packageCreator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export class PackageCreator {
138138
const errorMessage = (error as Error)?.message || `${error}`;
139139
this.dispatchProgressEvent("Unable to generate app package due to error. Checking if error is 403 Forbidden. " + errorMessage, "warn");
140140
const is403Error =
141+
(error as any)?.status === 403 ||
142+
(error as any)?.response?.status === 403 ||
141143
errorMessage.includes('403') ||
142144
errorMessage.includes('ECONNREFUSED') ||
143145
errorMessage.includes('ENOTFOUND');

apps/pwabuilder-microsoft-store/Common/HttpClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace PWABuilder.MicrosoftStore.Common;
1111

1212
public static class HttpClientExtensions
1313
{
14-
private const string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/137.0.3296.62 PWABuilderHttpAgent"; // Note: this should include PWABuilderHttpAgent, as Cloudflare has whitelisted this UA
14+
private const string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0 PWABuilderHttpAgent";
1515

1616
public static void AddLatestEdgeUserAgent(this HttpClient http)
1717
{

apps/pwabuilder-microsoft-store/Services/ImageGenerator.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class ImageGenerator
2727
private readonly Uri imageGeneratorServiceUrl;
2828

2929
public ImageGenerator(
30-
IHttpClientFactory httpClientFactory,
30+
IHttpClientFactory httpClientFactory,
3131
IOptions<AppSettings> appSettings,
3232
ILogger<ImageGenerator> logger)
3333
{
@@ -82,9 +82,13 @@ private async Task<byte[]> GetBaseImage(WindowsImages imageOptions, WebAppManife
8282
// Better than nothing: the largest image from the manifest
8383

8484
// Go through each source and see if we can get the bytes for it.
85+
86+
var manifestUrl = !string.IsNullOrEmpty(webManifest.Url) ? new Uri(webManifest.Url) : null;
87+
var baseImageAbsoluteUri = manifestUrl != null && imageOptions.BaseImage != null ?
88+
new Uri(manifestUrl, imageOptions.BaseImage?.ToString()) : null;
8589
var baseImageSources = new[]
8690
{
87-
(source: imageOptions.BaseImage, description: "base image from package options"),
91+
(source: baseImageAbsoluteUri, description: "base image from package options"),
8892
(source: webManifest.GetIconSuitableForWindowsApps(512), description: "largest square PNG or JPG icon 512x512 or larger from web manifest"),
8993
(source: webManifest.GetIconSuitableForWindowsApps(256), description: "largest square PNG or JPG icon 256x256 or larger from web manifest"),
9094
(source: webManifest.GetIconSuitableForWindowsApps(128), description: "largest square PNG or JPG icon 128x128 or larger from web manifest"),
@@ -114,7 +118,7 @@ private async Task<byte[]> GetBaseImage(WindowsImages imageOptions, WebAppManife
114118

115119
var imageSourceDescriptions = baseImageSources
116120
.Where(s => s.source != null)
117-
.Select(s => $"{s.description}: {s.source?.ToString()}");
121+
.Select(s => $"{s.description}: {s.source?.ToString()}");
118122
throw new InvalidOperationException($"Couldn't find a suitable base image from which to generate all Windows package images. Please ensure your web app manifest has a square PNG image 512x512 or larger. Base image sources: {string.Join(", ", imageSourceDescriptions)}");
119123
}
120124

apps/pwabuilder-microsoft-store/wwwroot/index.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
<!-- Bootstrap CSS -->
99
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
1010

11-
<title>PWABuilder.Windows.Chromium tester</title>
11+
<title>PWABuilder Microsoft Store packaging service</title>
1212
</head>
1313
<body class="container">
1414
<h1 class="display-4">
15-
PWABuilder.Windows.Chromium
15+
PWABuilder Microsoft Store packaging service
1616
</h1>
17-
<h5 class="display-5"><small class="text-muted">Test the service using the JSON below</small></h5>
17+
<h5 class="display-5">
18+
<small class="text-muted">
19+
This service builds a Microsoft Store app package (.msixbundle) from your PWA. The app package can be uploaded to <a href="https://partner.microsoft.com/dashboard">Microsoft Partner Center</a> for listing in the Microsoft Store.
20+
</small>
21+
</h5>
1822
<br>
1923

2024
<div class="card w-100">

0 commit comments

Comments
 (0)