Skip to content

Commit

Permalink
feat(Template): Make manifest.json optional
Browse files Browse the repository at this point in the history
Make manifest.json optional for WASM templates.

For Visual Studio 2022, the wizard should show an additional dialog
to ask whether the user wants a manifest.json file.

For `dotnet new unoapp` and `dotnet new unoapp-uwp-net6`, a parameter,
`--wasm-pwa-manifest` can be used.
  • Loading branch information
trungnt2910 committed Oct 18, 2022
1 parent 9b802c5 commit 572c991
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
.Replace("UseAppKit", "macos")
.Replace("UseCatalyst", "maccatalyst")
.Replace("UseServer", "hosted")
.Replace("UseWebAssemblyManifestJson", "wasm-pwa-manifest")
.Replace("$basetargetframework$", "net6.0")
;
Expand Down Expand Up @@ -410,7 +411,7 @@
<Using Namespace="System.IO" />
<Code Type="Fragment" Language="cs">
<![CDATA[
string[] filters = new[] { "*.cs", "*.xml", "*.xaml", "*.plist", "*.js", "*.config", "*.appxmanifest", "*.projitems", "*.shproj", "*.csproj", "*.sln" };
string[] filters = new[] { "*.cs", "*.xml", "*.xaml", "*.plist", "*.js", "*.json", "*.config", "*.appxmanifest", "*.projitems", "*.shproj", "*.csproj", "*.sln" };
foreach (var file in filters.SelectMany(f => Directory.EnumerateFiles(SourcePath, f, SearchOption.AllDirectories)))
{
Expand Down Expand Up @@ -463,6 +464,6 @@
</UsingTask>

<ItemGroup>
<None Include="..\..\Common\uno.png" Pack="true" PackagePath="\" Visble="false"/>
<None Include="..\..\Common\uno.png" Pack="true" PackagePath="\" Visble="false" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@
"datatype": "bool",
"description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false"
}
},
"wasm-pwa-manifest": {
"type": "parameter",
"datatype": "bool",
"description": "Enables the generation of a PWA manifest for WebAssembly",
"defaultValue": "false"
}
},
"primaryOutputs": [
{
Expand Down Expand Up @@ -215,6 +221,13 @@
"exclude": [
".vscode/**/*"
]
},
{
"condition": "(!wasm-pwa-manifest)",
"exclude": [
"UnoQuickStart.Wasm/manifest.json",
"UnoQuickStart.Wasm/Assets/AppIcon-*"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
"description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false"
},
"wasm-pwa-manifest": {
"type": "parameter",
"datatype": "bool",
"description": "Enables the generation of a PWA manifest for WebAssembly",
"defaultValue": "false"
},
"android": {
"type": "generated",
"generator": "constant",
Expand Down Expand Up @@ -292,6 +298,13 @@
"exclude": [
".vscode/**/*"
]
},
{
"condition": "(!wasm-pwa-manifest)",
"exclude": [
"UnoWinUIQuickStart.Wasm/manifest.json",
"UnoWinUIQuickStart.Wasm/Assets/AppIcon-*"
]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
<Content Include="Skia.WPF\__TemplateIcon.png" />
<Content Include="Wasm\Assets\SplashScreen.png" />
<Content Include="Wasm\LinkerConfig.xml" />
<Content Include="Wasm\manifest.json" />
<None Include="Wasm\Properties\launchSettings.json" />
<Content Include="Wasm\WasmCSS\Fonts.css" />
<Content Include="Wasm\WasmScripts\AppManifest.js" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>$basetargetframework$</TargetFramework>
<NoWarn>NU1701</NoWarn>

<WasmPWAManifestFile>manifest.json</WasmPWAManifestFile>
$if$($UseWebAssemblyManifestJson$ == True)<WasmPWAManifestFile>manifest.json</WasmPWAManifestFile>$endif$
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@

namespace UnoSolutionTemplate.Wizard.Forms
{
public partial class UnoOptions : Form
public partial class UnoOptions : UnoOptionsBaseForm
{
private IServiceProvider _serviceProvider;

public bool UseWebAssembly => checkWebAssembly.Checked;
public bool UseiOS => checkiOS.Checked;
public bool UseAndroid => checkAndroid.Checked;
Expand All @@ -35,79 +33,20 @@ public class TargetFrameworkOption
}

public UnoOptions(IServiceProvider serviceProvider)
: base(serviceProvider)
{
ThreadHelper.ThrowIfNotOnUIThread();

InitializeComponent();

_serviceProvider = serviceProvider;

if (_serviceProvider.GetService(typeof(IUIHostLocale)) is IUIHostLocale2 hostLocale)
{
UIDLGLOGFONT[] array = (UIDLGLOGFONT[])(object)new UIDLGLOGFONT[1];
if (hostLocale.GetDialogFont(array) == 0)
{
Font = FontFromUIDLGLOGFONT(array[0]);
}
}
InitializeFont();

BaseTargetFramework.Items.Add(new TargetFrameworkOption { BaseValue = "net6.0", DisplayValue = ".NET 6.0" });
BaseTargetFramework.Items.Add(new TargetFrameworkOption { BaseValue = "net7.0", DisplayValue = ".NET 7.0" });
BaseTargetFramework.SelectedIndex = 0;
}

private static Font FontFromUIDLGLOGFONT(UIDLGLOGFONT logFont)
{
var fonts = new char[logFont.lfFaceName.Length];

var num = 0;
ushort[] lfFaceName = logFont.lfFaceName;
foreach (ushort num2 in lfFaceName)
{
fonts[num++] = (char)num2;
}

var familyName = new string(fonts);
var emSize = -logFont.lfHeight;
var fontStyle = FontStyle.Regular;

if (logFont.lfItalic > 0)
{
fontStyle |= FontStyle.Italic;
}
if (logFont.lfUnderline > 0)
{
fontStyle |= FontStyle.Underline;
}
if (logFont.lfStrikeOut > 0)
{
fontStyle |= FontStyle.Strikeout;
}
if (logFont.lfWeight > 400)
{
fontStyle |= FontStyle.Bold;
}

var unit = GraphicsUnit.Pixel;
var lfCharSet = logFont.lfCharSet;

return new Font(familyName, emSize, fontStyle, unit, lfCharSet);
}

private void UnoOptions_Load(object sender, EventArgs e)
{
using Graphics graphics = CreateGraphics();
var sizeF = graphics.MeasureString(labelDescription.Text, Font);

int widthRatio = (int)(sizeF.Width / (float)labelDescription.Width);
if (widthRatio != 0)
{
int heightCeil = (int)Math.Ceiling(sizeF.Height);
SuspendLayout();
labelDescription.Height = heightCeil + widthRatio * heightCeil;
ResumeLayout(performLayout: true);
}

ResizeLabelDescription(labelDescription);
CenterToParent();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Drawing;
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;

namespace UnoSolutionTemplate.Wizard.Forms
{
public class UnoOptionsBaseForm : Form
{
private IServiceProvider _serviceProvider;

public UnoOptionsBaseForm(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

public UnoOptionsBaseForm()
{

}

protected void InitializeFont()
{
ThreadHelper.ThrowIfNotOnUIThread();

if (_serviceProvider.GetService(typeof(IUIHostLocale)) is IUIHostLocale2 hostLocale)
{
UIDLGLOGFONT[] array = (UIDLGLOGFONT[])(object)new UIDLGLOGFONT[1];
if (hostLocale.GetDialogFont(array) == 0)
{
Font = FontFromUIDLGLOGFONT(array[0]);
}
}
}

private static Font FontFromUIDLGLOGFONT(UIDLGLOGFONT logFont)
{
var fonts = new char[logFont.lfFaceName.Length];

var num = 0;
ushort[] lfFaceName = logFont.lfFaceName;
foreach (ushort num2 in lfFaceName)
{
fonts[num++] = (char)num2;
}

var familyName = new string(fonts);
var emSize = -logFont.lfHeight;
var fontStyle = FontStyle.Regular;

if (logFont.lfItalic > 0)
{
fontStyle |= FontStyle.Italic;
}
if (logFont.lfUnderline > 0)
{
fontStyle |= FontStyle.Underline;
}
if (logFont.lfStrikeOut > 0)
{
fontStyle |= FontStyle.Strikeout;
}
if (logFont.lfWeight > 400)
{
fontStyle |= FontStyle.Bold;
}

var unit = GraphicsUnit.Pixel;
var lfCharSet = logFont.lfCharSet;

return new Font(familyName, emSize, fontStyle, unit, lfCharSet);
}

protected void ResizeLabelDescription(Label labelDescription)
{
using Graphics graphics = CreateGraphics();
var sizeF = graphics.MeasureString(labelDescription.Text, Font);

int widthRatio = (int)(sizeF.Width / (float)labelDescription.Width);
if (widthRatio != 0)
{
int heightCeil = (int)Math.Ceiling(sizeF.Height);
SuspendLayout();
labelDescription.Height = heightCeil + widthRatio * heightCeil;
ResumeLayout(performLayout: true);
}
}
}
}
Loading

0 comments on commit 572c991

Please sign in to comment.