Skip to content

Commit

Permalink
Merge pull request #196 from unoplatform/pj/allow-comments-on-json-do…
Browse files Browse the repository at this point in the history
…cument

Allow comments on json document
  • Loading branch information
pictos authored Nov 14, 2023
2 parents 146ecf6 + fa289c4 commit 8c52ecf
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 28 deletions.
3 changes: 3 additions & 0 deletions doc/using-uno-resizetizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ Icon = "@mipmap/iconapp",
> [!NOTE]
> In some projects the `manifest.webmanifest` be `manifest.json`. If so, you can either adjust your project to use `manifest.webmanifest` or keep it as `manifest.json`.
> [!INFO]
> Uno.Resizetizer will support comments on your json file, but they will ignored on the final generated file.
# [**Apple**](#tab/Apple)

* For `mac-catalyst` and `iOS`, open the [`info.plist` file](https://github.com/unoplatform/uno.resizetizer/blob/main/samples/NewTemplate/Resizetizer.Extensions.Sample.Mobile/iOS/Info.plist), find the `XSAppIconAsset` key, and change its value to `Assets.xcassets/iconapp.appiconset`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
// comment test
"background_color": "#ffffff",
"description": "Resizetizer.Extensions.Sample",
"display": "standalone",
"icons": [ ],
"icons": [],
"name": "Resizetizer.Extensions.Sample",
"short_name": "Resizetizer.Extensions.Sample",
"start_url": "/index.html",
Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/CreatePartialInfoPlistTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CreatePartialInfoPlistTask_v0 : Task
public override bool Execute()
{
#if DEBUG_RESIZETIZER
System.Diagnostics.Debugger.Launch();
// System.Diagnostics.Debugger.Launch();
#endif
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/GeneratePackageAppxManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class GeneratePackageAppxManifest_v0 : Task
public override bool Execute()
{
#if DEBUG_RESIZETIZER
System.Diagnostics.Debugger.Launch();
// System.Diagnostics.Debugger.Launch();
#endif
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/GenerateSplashAndroidResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class GenerateSplashAndroidResources_v0 : Task, ILogger
public override bool Execute()
{
#if DEBUG_RESIZETIZER
System.Diagnostics.Debugger.Launch();
//System.Diagnostics.Debugger.Launch();
#endif
var splash = UnoSplashScreen[0];

Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/GenerateSplashAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class GenerateSplashAssets_v0 : Task, ILogger
public override bool Execute()
{
#if DEBUG_RESIZETIZER
System.Diagnostics.Debugger.Launch();
//System.Diagnostics.Debugger.Launch();
#endif
var splash = UnoSplashScreen[0];

Expand Down
2 changes: 1 addition & 1 deletion src/Resizetizer/src/GenerateSplashStoryboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GenerateSplashStoryboard_v0 : Task
public override bool Execute()
{
#if DEBUG_RESIZETIZER
System.Diagnostics.Debugger.Launch();
//System.Diagnostics.Debugger.Launch();
#endif
var splash = UnoSplashScreen[0];

Expand Down
10 changes: 5 additions & 5 deletions src/Resizetizer/src/GenerateWasmSplashAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public override bool Execute()
{
#if DEBUG_RESIZETIZER

if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
System.Diagnostics.Debugger.Launch();
//if (System.Diagnostics.Debugger.IsAttached)
//{
// System.Diagnostics.Debugger.Break();
//}
//System.Diagnostics.Debugger.Launch();

#endif
if (UnoSplashScreen is null || UnoSplashScreen.Length is 0 )
Expand Down
6 changes: 5 additions & 1 deletion src/Resizetizer/src/JsonHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ namespace Uno.Resizetizer;
// From https://github.com/dotnet/runtime/issues/31433#issuecomment-570475853
public static class JsonHelper
{
internal static JsonDocumentOptions jsonDocumentOptions = new()
{
CommentHandling = JsonCommentHandling.Skip
};
public static void Merge(string originalJson, string newContent, Utf8JsonWriter jsonWriter)
{
using (JsonDocument jDoc1 = JsonDocument.Parse(originalJson))
using (JsonDocument jDoc1 = JsonDocument.Parse(originalJson, jsonDocumentOptions))
using (JsonDocument jDoc2 = JsonDocument.Parse(newContent))
{
JsonElement root1 = jDoc1.RootElement;
Expand Down
10 changes: 5 additions & 5 deletions src/Resizetizer/src/ResizetizeImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public override System.Threading.Tasks.Task ExecuteAsync()
{
#if DEBUG_RESIZETIZER

if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
System.Diagnostics.Debugger.Launch();
//if (System.Diagnostics.Debugger.IsAttached)
//{
// System.Diagnostics.Debugger.Break();
//}
//System.Diagnostics.Debugger.Launch();

#endif
TargetPlatform = PlatformType;
Expand Down
26 changes: 15 additions & 11 deletions src/Resizetizer/src/WasmIconGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
using SkiaSharp;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace Uno.Resizetizer;
internal sealed class WasmIconGenerator
Expand All @@ -33,6 +27,16 @@ public WasmIconGenerator(ResizeImageInfo info, string intermediateOutputPath, IL

public string ProcessThePwaManifest()
{
#if DEBUG_RESIZETIZER

if (System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Debugger.Break();
}
System.Diagnostics.Debugger.Launch();

#endif

if (string.IsNullOrWhiteSpace(pwaManifestPath))
{
Logger.Log("There's no PWA Manifest file.");
Expand All @@ -41,7 +45,7 @@ public string ProcessThePwaManifest()

var json = File.ReadAllText(pwaManifestPath);

var jsonNodeManifest = JsonNode.Parse(json);
var jsonNodeManifest = JsonNode.Parse(json, documentOptions: JsonHelper.jsonDocumentOptions);

if (!IconPropertyIsEmpty(jsonNodeManifest))
{
Expand All @@ -51,7 +55,7 @@ public string ProcessThePwaManifest()

var appIconImagesJson = new JsonArray();
Logger.Log("Creating the icons property for the PWA manifest.");

foreach (var dpi in dpiPaths)
{
var w = dpi.Size.Value.Width.ToString("0.#", CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -86,7 +90,7 @@ public string ProcessThePwaManifest()
using var writer = new Utf8JsonWriter(fs, writeOptions);

Logger.Log("Merging the original PWA manifest with the icons property.");

JsonHelper.Merge(json, jsonIconsObject.ToJsonString(), writer);

writer.Flush();
Expand Down

0 comments on commit 8c52ecf

Please sign in to comment.