Updating Uno sample

Updating Uno sample with latest changes.
This commit is contained in:
Kevin Bost
2024-06-24 00:50:00 -07:00
committed by Caelan Sayler
parent dba6081749
commit 02ff2fda51
7 changed files with 40 additions and 71 deletions

View File

@@ -5,44 +5,14 @@ This solution contains an Uno Desktop application that targets both Windows and
## Prerequisites ## Prerequisites
This solution will publish the application out to the Velopack Flow service. To test the full publish you will need to create a [Velopack Flow account](https://app.velopack.io). This solution will publish the application out to the Velopack Flow service. To test the full publish you will need to create a [Velopack Flow account](https://app.velopack.io).
The solution assumes that you have downloaded and installed the Velopack CLI (`vpk`) global tool. This tool can be installed by running `dotnet tool install -g vpk`. You will then need ot authenticate with the Velopack Flow servie by running `vpk login` and signing in with your Velopack Flow account. The solution assumes that you have downloaded and installed the Velopack CLI (`vpk`) global tool. This tool can be installed by running `dotnet tool install -g vpk`.
You will need to authenticate with the Velopack Flow service by running `vpk login` and signing in with your Velopack Flow account.
## The Application ## The Application
Inside of `Presentation` the `MainPage.xaml` contains the main UI for viewing the current version, checking for updates, and applying the latest update. `Presentation/MainPage.xaml` contains the main UI for viewing the current version, checking for updates, and applying the latest update.
The `MainViewModel.cs` contains the logic for checking for updates and applying them. The key piece of the setup is the initialization of the `UpdateManager` with the `VelopackFlowUpdateSource` which provides the interaction with the Velopack Flow service. The `MainViewModel.cs` contains the logic for checking for updates and applying them. The key piece of the setup is the initialization of the `UpdateManager` with the `VelopackFlowUpdateSource` which provides the interaction with the Velopack Flow service.
The `Main` methods in the `Platforms\Desktop\Program.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview). The `App.xaml.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview).
The `Main` methods in the `Platforms\MacCatalyst\Main.maccatalyst.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview).
Finally, for the WinUI platform, a little more work is needed as the `Main` method is auto-generated by default.
First, the generation of the `Main` method needs to be disabled by defining `DISABLE_XAML_GENERATED_MAIN` constant in the csproj.
```xml
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-windows10.0.19041'">
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants>
</PropertyGroup>
```
Next the `Main` method needs to be added so a new `Platforms\Windows\Program.cs` file is added with a standard content, and the [Velopack application startup hook](https://docs.velopack.io/integrating/overview):
```csharp
[STAThread]
public static void Main(string[] args)
{
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
WinRT.ComWrappersSupport.InitializeComWrappers();
Application.Start((p) =>
{
var context = new DispatcherQueueSynchronizationContext(
DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
new App();
});
}
```
### Updating the Project file ### Updating the Project file
There are two properties to set in the `csproj` file to enable the Velopack Flow integration. These are: There are two properties to set in the `csproj` file to enable the Velopack Flow integration. These are:
@@ -51,12 +21,19 @@ There are two properties to set in the `csproj` file to enable the Velopack Flow
<VelopackPackId>Velopack.UnoSample</VelopackPackId> <VelopackPackId>Velopack.UnoSample</VelopackPackId>
``` ```
`VelopackPackId` is the unique identifier for the application. This is used to identify the application in the Velopack Flow service. It must be unique among all applications. `VelopackPackId` is the unique identifier for the application. This is used to identify the application in the Velopack Flow service. It must be unique among all applications.You **MUST** change this to be your own application identifier.
`VelopackPushOnPublish` is a boolean value that determines if the application should be pushed to the Velopack Flow service when it is published. This should be set to `true` to enable the integration. `VelopackPushOnPublish` is a boolean value that determines if the application should be pushed to the Velopack Flow service when it is published. This should be set to `true` to enable the integration.
### Building installers ### Building installers
To build the local installers run the following command replacing `<Version>` with the desired version number. To build the local installers run the following command replacing `<Version>` with the desired version number.
The `-f` option is used to specify the target framework. This can be any of the desktop frameworks specified in the `csproj` file. The `-f` option is used to specify the target framework. Because each target platform should result in a different build, you likely will want to specify a different Velopack channel for each target platform. By default, it will default to your target OS. You can specify the channel by adding `-p:VelopackChannel=<Channel>` to the command.
This can be any of the desktop frameworks specified in the `csproj` file.
```bash ```bash
dotnet publish -c Release -f net8.0-desktop -p:Version=<Version> dotnet publish -c Release -f net8.0-desktop -p:VelopackChannel=<Channel> -p:Version=<Version>
```
For example:
```bash
dotnet publish -c Release -f net8.0-desktop -p:VelopackChannel=win-desktop -p:Version=1.0.5
``` ```

View File

@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.targets = Directory.Build.targets Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props Directory.Packages.props = Directory.Packages.props
global.json = global.json global.json = global.json
README.md = README.md
EndProjectSection EndProjectSection
EndProject EndProject
Global Global

View File

@@ -1,4 +1,5 @@
using Uno.Resizetizer; using Uno.Resizetizer;
using Velopack;
namespace UnoSample; namespace UnoSample;
public partial class App : Application public partial class App : Application
@@ -9,6 +10,11 @@ public partial class App : Application
/// </summary> /// </summary>
public App() public App()
{ {
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
this.InitializeComponent(); this.InitializeComponent();
} }

View File

@@ -1,5 +1,4 @@
using Uno.UI.Runtime.Skia; using Uno.UI.Runtime.Skia;
using Velopack;
namespace UnoSample; namespace UnoSample;
public class Program public class Program
@@ -7,11 +6,6 @@ public class Program
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
#if (!useDependencyInjection && useLoggingFallback) #if (!useDependencyInjection && useLoggingFallback)
App.InitializeLogging(); App.InitializeLogging();

View File

@@ -1,5 +1,4 @@
using UIKit; using UIKit;
using Velopack;
namespace UnoSample.MacCatalyst; namespace UnoSample.MacCatalyst;
public class EntryPoint public class EntryPoint
@@ -7,11 +6,6 @@ public class EntryPoint
// This is the main entry point of the application. // This is the main entry point of the application.
public static void Main(string[] args) public static void Main(string[] args)
{ {
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
// if you want to use a different Application Delegate class from "AppDelegate" // if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here. // you can specify it here.
UIApplication.Main(args, null, typeof(App)); UIApplication.Main(args, null, typeof(App));

View File

@@ -2,25 +2,22 @@ using Microsoft.UI.Dispatching;
using Velopack; using Velopack;
namespace UnoSample; namespace UnoSample;
public static class Program //public static class Program
{ //{
// https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/applifecycle?WT.mc_id=DT-MVP-5003472#single-instancing-in-main-or-wwinmain // // https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/migrate-to-windows-app-sdk/guides/applifecycle?WT.mc_id=DT-MVP-5003472#single-instancing-in-main-or-wwinmain
[STAThread] // [STAThread]
public static void Main(string[] args) // public static void Main(string[] args)
{ // {
// It's important to Run() the VelopackApp as early as possible in app startup.
VelopackApp.Build()
.WithFirstRun((v) => { /* Your first run code here */ })
.Run();
WinRT.ComWrappersSupport.InitializeComWrappers();
Application.Start((p) => // WinRT.ComWrappersSupport.InitializeComWrappers();
{
var context = new DispatcherQueueSynchronizationContext( // Application.Start((p) =>
DispatcherQueue.GetForCurrentThread()); // {
SynchronizationContext.SetSynchronizationContext(context); // var context = new DispatcherQueueSynchronizationContext(
new App(); // DispatcherQueue.GetForCurrentThread());
}); // SynchronizationContext.SetSynchronizationContext(context);
} // new App();
} // });
// }
//}

View File

@@ -54,9 +54,9 @@
<!-- <!--
Disables the auto-generated Main method so that we can add in the Velopack calls at startup. Disables the auto-generated Main method so that we can add in the Velopack calls at startup.
--> -->
<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-windows10.0.19041'"> <!--<PropertyGroup Condition="'$(TargetFramework)'=='net8.0-windows10.0.19041'">
<DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants> <DefineConstants>$(DefineConstants);DISABLE_XAML_GENERATED_MAIN</DefineConstants>
</PropertyGroup> </PropertyGroup>-->
<ItemGroup> <ItemGroup>
<PackageReference Include="Velopack" /> <PackageReference Include="Velopack" />