From 4d1388fb5f59a05a0d2284c0744f3132bfcbf806 Mon Sep 17 00:00:00 2001 From: Steve Bilogan Date: Wed, 26 Mar 2025 07:29:19 -0700 Subject: [PATCH] chore: update uno sample app with latest (#584) * chore: update uno sample app with latest * Cleaning up UnoSample to use SampleHelper Updated the top level Directory.Build.targets to support samples with solutions and nested directories. Added build scripts. * Adding Uno sample to GHA * Remove framework bootstrap * Fixing mainExe name on non-windows --------- Co-authored-by: Kevin Bost --- .github/workflows/build.yml | 2 +- samples/CSharpUno/.editorconfig | 35 ++- samples/CSharpUno/.gitignore | 2 + samples/CSharpUno/.run/Readme.md | 3 + samples/CSharpUno/.run/UnoSample.run.xml | 32 +++ samples/CSharpUno/.vscode/launch.json | 11 +- samples/CSharpUno/.vscode/settings.json | 3 + samples/CSharpUno/.vscode/tasks.json | 4 +- samples/CSharpUno/.vsconfig | 6 - samples/CSharpUno/Directory.Build.props | 8 - samples/CSharpUno/Directory.Build.targets | 3 +- samples/CSharpUno/Directory.Packages.props | 8 +- samples/CSharpUno/README.md | 39 ---- samples/CSharpUno/UnoSample.sln | 21 +- samples/CSharpUno/UnoSample/App.xaml | 37 ++-- samples/CSharpUno/UnoSample/App.xaml.cs | 205 ++++++++++-------- .../UnoSample/Assets/Images/back.svg | 3 - samples/CSharpUno/UnoSample/GlobalUsings.cs | 12 - samples/CSharpUno/UnoSample/MainPage.xaml | 24 ++ samples/CSharpUno/UnoSample/MainPage.xaml.cs | 15 ++ samples/CSharpUno/UnoSample/MainViewModel.cs | 65 ++++++ .../CSharpUno/UnoSample/Models/AppConfig.cs | 6 - samples/CSharpUno/UnoSample/Models/Entity.cs | 3 - .../UnoSample/Models/WeatherForecast.cs | 15 -- .../CSharpUno/UnoSample/Package.appxmanifest | 20 +- .../UnoSample/Platforms/Desktop/Program.cs | 28 ++- .../Platforms/MacCatalyst/Entitlements.plist | 6 - .../Platforms/MacCatalyst/Info.plist | 26 --- .../Platforms/MacCatalyst/Main.maccatalyst.cs | 13 -- .../LaunchImages.launchimage/Contents.json | 58 ----- .../UnoSample/Platforms/Windows/Program.cs | 23 -- .../UnoSample/Presentation/MainPage.xaml | 39 ---- .../UnoSample/Presentation/MainPage.xaml.cs | 13 -- .../UnoSample/Presentation/MainViewModel.cs | 72 ------ .../UnoSample/Presentation/Shell.xaml | 36 --- .../UnoSample/Presentation/Shell.xaml.cs | 10 - .../UnoSample/Presentation/ShellViewModel.cs | 18 -- .../PublishProfiles/win-arm64.pubxml | 6 +- .../Properties/PublishProfiles/win-x64.pubxml | 6 +- .../Properties/PublishProfiles/win-x86.pubxml | 3 +- .../Serialization/WeatherForecastContext.cs | 23 -- .../Services/Caching/IWeatherCache.cs | 6 - .../Services/Caching/WeatherCache.cs | 76 ------- .../Services/Endpoints/DebugHandler.cs | 44 ---- .../Services/Endpoints/IApiClient.cs | 9 - .../UnoSample/Strings/es/Resources.resw | 123 ----------- .../UnoSample/Strings/fr/Resources.resw | 123 ----------- .../UnoSample/Strings/pt-BR/Resources.resw | 123 ----------- .../Styles/ColorPaletteOverride.json | 76 ------- .../Styles/ColorPaletteOverride.xaml | 65 ------ samples/CSharpUno/UnoSample/UnoSample.csproj | 40 +--- .../UnoSample/appsettings.development.json | 9 - samples/CSharpUno/UnoSample/appsettings.json | 16 -- samples/CSharpUno/build.bat | 18 ++ samples/CSharpUno/build.sh | 21 ++ samples/CSharpUno/global.json | 3 + samples/Directory.Build.targets | 4 +- samples/SampleHelper.cs | 6 +- 58 files changed, 389 insertions(+), 1335 deletions(-) create mode 100644 samples/CSharpUno/.run/Readme.md create mode 100644 samples/CSharpUno/.run/UnoSample.run.xml delete mode 100644 samples/CSharpUno/README.md delete mode 100644 samples/CSharpUno/UnoSample/Assets/Images/back.svg create mode 100644 samples/CSharpUno/UnoSample/MainPage.xaml create mode 100644 samples/CSharpUno/UnoSample/MainPage.xaml.cs create mode 100644 samples/CSharpUno/UnoSample/MainViewModel.cs delete mode 100644 samples/CSharpUno/UnoSample/Models/AppConfig.cs delete mode 100644 samples/CSharpUno/UnoSample/Models/Entity.cs delete mode 100644 samples/CSharpUno/UnoSample/Models/WeatherForecast.cs delete mode 100644 samples/CSharpUno/UnoSample/Platforms/MacCatalyst/Entitlements.plist delete mode 100644 samples/CSharpUno/UnoSample/Platforms/MacCatalyst/Info.plist delete mode 100644 samples/CSharpUno/UnoSample/Platforms/MacCatalyst/Main.maccatalyst.cs delete mode 100644 samples/CSharpUno/UnoSample/Platforms/MacCatalyst/Media.xcassets/LaunchImages.launchimage/Contents.json delete mode 100644 samples/CSharpUno/UnoSample/Platforms/Windows/Program.cs delete mode 100644 samples/CSharpUno/UnoSample/Presentation/MainPage.xaml delete mode 100644 samples/CSharpUno/UnoSample/Presentation/MainPage.xaml.cs delete mode 100644 samples/CSharpUno/UnoSample/Presentation/MainViewModel.cs delete mode 100644 samples/CSharpUno/UnoSample/Presentation/Shell.xaml delete mode 100644 samples/CSharpUno/UnoSample/Presentation/Shell.xaml.cs delete mode 100644 samples/CSharpUno/UnoSample/Presentation/ShellViewModel.cs rename samples/CSharpUno/UnoSample/{Platforms/Windows => }/Properties/PublishProfiles/win-arm64.pubxml (74%) rename samples/CSharpUno/UnoSample/{Platforms/Windows => }/Properties/PublishProfiles/win-x64.pubxml (74%) rename samples/CSharpUno/UnoSample/{Platforms/Windows => }/Properties/PublishProfiles/win-x86.pubxml (84%) delete mode 100644 samples/CSharpUno/UnoSample/Serialization/WeatherForecastContext.cs delete mode 100644 samples/CSharpUno/UnoSample/Services/Caching/IWeatherCache.cs delete mode 100644 samples/CSharpUno/UnoSample/Services/Caching/WeatherCache.cs delete mode 100644 samples/CSharpUno/UnoSample/Services/Endpoints/DebugHandler.cs delete mode 100644 samples/CSharpUno/UnoSample/Services/Endpoints/IApiClient.cs delete mode 100644 samples/CSharpUno/UnoSample/Strings/es/Resources.resw delete mode 100644 samples/CSharpUno/UnoSample/Strings/fr/Resources.resw delete mode 100644 samples/CSharpUno/UnoSample/Strings/pt-BR/Resources.resw delete mode 100644 samples/CSharpUno/UnoSample/Styles/ColorPaletteOverride.json delete mode 100644 samples/CSharpUno/UnoSample/Styles/ColorPaletteOverride.xaml delete mode 100644 samples/CSharpUno/UnoSample/appsettings.development.json delete mode 100644 samples/CSharpUno/UnoSample/appsettings.json create mode 100644 samples/CSharpUno/build.bat create mode 100644 samples/CSharpUno/build.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1943372b..bee9d004 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -393,7 +393,7 @@ jobs: strategy: fail-fast: false matrix: - sample: [CPlusPlusWidgets, CPlusPlusWin32, CSharpAvalonia, CSharpWpf, NodeJSElectron, RustIced] + sample: [CPlusPlusWidgets, CPlusPlusWin32, CSharpAvalonia, CSharpUno, CSharpWpf, NodeJSElectron, RustIced] os: [windows-latest, ubuntu-latest, macos-latest] exclude: - os: ubuntu-latest diff --git a/samples/CSharpUno/.editorconfig b/samples/CSharpUno/.editorconfig index b947be64..6376a9f8 100644 --- a/samples/CSharpUno/.editorconfig +++ b/samples/CSharpUno/.editorconfig @@ -9,11 +9,27 @@ root = true ########################################## [*] -indent_style = space +indent_style = tab end_of_line = crlf trim_trailing_whitespace = true insert_final_newline = true charset = utf-8 +dotnet_style_coalesce_expression = true:suggestion +dotnet_style_null_propagation = true:suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +dotnet_style_prefer_auto_properties = true:silent +dotnet_style_object_initializer = true:suggestion +dotnet_style_collection_initializer = true:suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:silent +dotnet_style_prefer_conditional_expression_over_return = true:silent +dotnet_style_explicit_tuple_names = true:suggestion +dotnet_style_prefer_inferred_tuple_names = true:suggestion +dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion +dotnet_style_operator_placement_when_wrapping = beginning_of_line +tab_width = 4 +indent_size = 4 +dotnet_style_prefer_compound_assignment = true:suggestion ########################################## # File Extension Settings @@ -31,40 +47,40 @@ indent_style = tab indent_size = 2 [*.{csproj,proj,projitems,shproj}] -indent_size = 2 +indent_size = 4 [*.{json,slnf}] indent_size = 2 end_of_line = lf [*.{props,targets}] -indent_size = 2 +indent_size = 4 [*.xaml] -indent_size = 2 +indent_size = 4 charset = utf-8-bom [*.xml] -indent_size = 2 +indent_size = 4 end_of_line = lf [*.plist] -indent_size = 2 +indent_size = 4 indent_style = tab end_of_line = lf [*.manifest] -indent_size = 2 +indent_size = 4 [*.appxmanifest] -indent_size = 2 +indent_size = 4 [*.{json,css,webmanifest}] indent_size = 2 end_of_line = lf [web.config] -indent_size = 2 +indent_size = 4 end_of_line = lf [*.sh] @@ -165,3 +181,4 @@ csharp_style_expression_bodied_indexers = true:silent csharp_style_expression_bodied_accessors = true:silent csharp_style_expression_bodied_lambdas = true:silent csharp_style_expression_bodied_local_functions = false:silent +csharp_prefer_system_threading_lock = true:suggestion diff --git a/samples/CSharpUno/.gitignore b/samples/CSharpUno/.gitignore index ef88c205..c9a4f514 100644 --- a/samples/CSharpUno/.gitignore +++ b/samples/CSharpUno/.gitignore @@ -82,6 +82,8 @@ StyleCopReport.xml *.pgc *.pgd *.rsp +# but not Directory.Build.rsp, as it configures directory-level build defaults +!Directory.Build.rsp *.sbr *.tlb *.tli diff --git a/samples/CSharpUno/.run/Readme.md b/samples/CSharpUno/.run/Readme.md new file mode 100644 index 00000000..6e72638a --- /dev/null +++ b/samples/CSharpUno/.run/Readme.md @@ -0,0 +1,3 @@ +# About the `.run` folder + +This folder is present to add support for the [Rider IDE](https://aka.platform.uno/rider-getstarted). You can remove this folder safely if you're not using Rider. diff --git a/samples/CSharpUno/.run/UnoSample.run.xml b/samples/CSharpUno/.run/UnoSample.run.xml new file mode 100644 index 00000000..6bae33f6 --- /dev/null +++ b/samples/CSharpUno/.run/UnoSample.run.xml @@ -0,0 +1,32 @@ + + + + + + diff --git a/samples/CSharpUno/.vscode/launch.json b/samples/CSharpUno/.vscode/launch.json index 87a59c21..fd154cad 100644 --- a/samples/CSharpUno/.vscode/launch.json +++ b/samples/CSharpUno/.vscode/launch.json @@ -4,23 +4,16 @@ // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md "version": "0.2.0", "configurations": [ - { - "name": "Uno Platform Mobile", - "type": "Uno", - "request": "launch", - // any Uno* task will do, this is simply to satisfy vscode requirement when a launch.json is present - "preLaunchTask": "Uno: android | Debug | android-x64" - }, { // Use IntelliSense to find out which attributes exist for C# debugging // Use hover for the description of the existing attributes // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": "Uno Platform Desktop (Debug)", + "name": "Uno Platform Desktop Debug", "type": "coreclr", "request": "launch", "preLaunchTask": "build-desktop", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/UnoSample/bin/Debug/net8.0-desktop/UnoSample.dll", + "program": "${workspaceFolder}/UnoSample/bin/Debug/net9.0-desktop/UnoSample.dll", "args": [], "launchSettingsProfile": "UnoSample (Desktop)", "env": { diff --git a/samples/CSharpUno/.vscode/settings.json b/samples/CSharpUno/.vscode/settings.json index 23133fc7..3405922d 100644 --- a/samples/CSharpUno/.vscode/settings.json +++ b/samples/CSharpUno/.vscode/settings.json @@ -3,5 +3,8 @@ "explorer.fileNesting.expand": false, "explorer.fileNesting.patterns": { "*.xaml": "$(capture).xaml.cs" + }, + "files.associations": { + "global.json": "jsonc" } } diff --git a/samples/CSharpUno/.vscode/tasks.json b/samples/CSharpUno/.vscode/tasks.json index ff3537ca..8e8935dc 100644 --- a/samples/CSharpUno/.vscode/tasks.json +++ b/samples/CSharpUno/.vscode/tasks.json @@ -9,7 +9,7 @@ "build", "${workspaceFolder}/UnoSample/UnoSample.csproj", "/property:GenerateFullPaths=true", - "/property:TargetFramework=net8.0-desktop", + "/property:TargetFramework=net9.0-desktop", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" @@ -22,7 +22,7 @@ "publish", "${workspaceFolder}/UnoSample/UnoSample.csproj", "/property:GenerateFullPaths=true", - "/property:TargetFramework=net8.0-desktop", + "/property:TargetFramework=net9.0-desktop", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" diff --git a/samples/CSharpUno/.vsconfig b/samples/CSharpUno/.vsconfig index 6cd65ee4..73997027 100644 --- a/samples/CSharpUno/.vsconfig +++ b/samples/CSharpUno/.vsconfig @@ -7,16 +7,10 @@ "Microsoft.NetCore.Component.DevelopmentTools", "Microsoft.Net.ComponentGroup.DevelopmentPrerequisites", "Microsoft.VisualStudio.Component.TextTemplating", - "Microsoft.VisualStudio.Component.Windows10SDK.19041", "Microsoft.VisualStudio.ComponentGroup.MSIX.Packaging", "Microsoft.VisualStudio.Component.ManagedDesktop.Prerequisites", "Microsoft.VisualStudio.Component.Debugger.JustInTime", "Microsoft.VisualStudio.Workload.ManagedDesktop", - "Microsoft.Component.NetFX.Native", - "Microsoft.VisualStudio.Component.Graphics", - "Microsoft.VisualStudio.Component.Merq", - "Microsoft.VisualStudio.Component.MonoDebugger", - "Microsoft.VisualStudio.ComponentGroup.Maui.All", "Microsoft.VisualStudio.Workload.NetCrossPlat", "Microsoft.VisualStudio.Workload.NetCoreTools" ] diff --git a/samples/CSharpUno/Directory.Build.props b/samples/CSharpUno/Directory.Build.props index c23d7362..8daf5692 100644 --- a/samples/CSharpUno/Directory.Build.props +++ b/samples/CSharpUno/Directory.Build.props @@ -12,12 +12,4 @@ --> $(NoWarn);NU1507;NETSDK1201;PRI257 - - - - 4.1.23 - 6.0.24 - 5.0.13 - 5.2.14 - diff --git a/samples/CSharpUno/Directory.Build.targets b/samples/CSharpUno/Directory.Build.targets index f75adf7e..14437118 100644 --- a/samples/CSharpUno/Directory.Build.targets +++ b/samples/CSharpUno/Directory.Build.targets @@ -1,2 +1,3 @@ - + + diff --git a/samples/CSharpUno/Directory.Packages.props b/samples/CSharpUno/Directory.Packages.props index 2dca56b2..e920b828 100644 --- a/samples/CSharpUno/Directory.Packages.props +++ b/samples/CSharpUno/Directory.Packages.props @@ -3,13 +3,9 @@ To update the version of Uno, you should instead update the Sdk version in the global.json file. See https://aka.platform.uno/using-uno-sdk for more information. + See https://aka.platform.uno/using-uno-sdk#implicit-packages for more information regarding the Implicit Packages. --> - - - - - - \ No newline at end of file + diff --git a/samples/CSharpUno/README.md b/samples/CSharpUno/README.md deleted file mode 100644 index 2dc09858..00000000 --- a/samples/CSharpUno/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# Uno with Velopack - -This solution contains an Uno Desktop application that targets both Windows and macOS. Because Velopack does not currently support mobile or web platforms, those are not included. - -## 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). - -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 -`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 `App.xaml.cs` has been updated to contain the [Velopack application startup hook](https://docs.velopack.io/integrating/overview). - -### Updating the Project file -There are two properties to set in the `csproj` file to enable the Velopack Flow integration. These are: -```xml -true -Velopack.UnoSample -``` - -`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. - -### Building installers -To build the local installers run the following command replacing `` with the desired version number. -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=` to the command. - -This can be any of the desktop frameworks specified in the `csproj` file. -```bash -dotnet publish -c Release -f net8.0-desktop -p:VelopackChannel= -p:Version= -``` - -For example: -```bash -dotnet publish -c Release -f net8.0-desktop -p:VelopackChannel=win-desktop -p:Version=1.0.5 -``` diff --git a/samples/CSharpUno/UnoSample.sln b/samples/CSharpUno/UnoSample.sln index 787f438b..c1d6a7fd 100644 --- a/samples/CSharpUno/UnoSample.sln +++ b/samples/CSharpUno/UnoSample.sln @@ -1,17 +1,18 @@ + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.11.34929.205 +VisualStudioVersion = 17.13.35913.81 d17.13 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnoSample", "UnoSample\UnoSample.csproj", "{F9ACED52-AE70-46F6-8C7C-2EF629084661}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnoSample", "UnoSample\UnoSample.csproj", "{6BF41A07-4B32-447E-96AB-5437C3564AFD}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29980CC9-DC41-4944-966D-F088C84D1C7B}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig .gitignore = .gitignore Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets Directory.Packages.props = Directory.Packages.props global.json = global.json - README.md = README.md EndProjectSection EndProject Global @@ -20,15 +21,17 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {F9ACED52-AE70-46F6-8C7C-2EF629084661}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F9ACED52-AE70-46F6-8C7C-2EF629084661}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F9ACED52-AE70-46F6-8C7C-2EF629084661}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F9ACED52-AE70-46F6-8C7C-2EF629084661}.Release|Any CPU.Build.0 = Release|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Release|Any CPU.Build.0 = Release|Any CPU + {6BF41A07-4B32-447E-96AB-5437C3564AFD}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {2FA3FC94-E895-443E-AAA8-9A7F956F9E92} + SolutionGuid = {800ACAFE-BC3B-4646-9989-C59A522D41E4} EndGlobalSection EndGlobal diff --git a/samples/CSharpUno/UnoSample/App.xaml b/samples/CSharpUno/UnoSample/App.xaml index d4a63169..b05f9cc9 100644 --- a/samples/CSharpUno/UnoSample/App.xaml +++ b/samples/CSharpUno/UnoSample/App.xaml @@ -1,28 +1,17 @@ - + - - - - - - - - - - - - + + + + + + - + + + + diff --git a/samples/CSharpUno/UnoSample/App.xaml.cs b/samples/CSharpUno/UnoSample/App.xaml.cs index 26a1a4ae..82f62561 100644 --- a/samples/CSharpUno/UnoSample/App.xaml.cs +++ b/samples/CSharpUno/UnoSample/App.xaml.cs @@ -4,113 +4,130 @@ using Velopack; namespace UnoSample; public partial class App : Application { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - // It's important to Run() the VelopackApp as early as possible in app startup. + /// + /// Initializes the singleton application object. This is the first line of authored code + /// executed, and as such is the logical equivalent of main() or WinMain(). + /// + 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(); + } - protected Window? MainWindow { get; private set; } - protected IHost? Host { get; private set; } + protected Window? MainWindow { get; private set; } - protected async override void OnLaunched(LaunchActivatedEventArgs args) - { - var builder = this.CreateBuilder(args) - // Add navigation support for toolkit controls such as TabBar and NavigationView - .UseToolkitNavigation() - .Configure(host => host + protected override void OnLaunched(LaunchActivatedEventArgs args) + { + MainWindow = new Window(); #if DEBUG - // Switch to Development environment when running in DEBUG - .UseEnvironment(Environments.Development) + MainWindow.UseStudio(); #endif - .UseLogging(configure: (context, logBuilder) => - { - // Configure log levels for different categories of logging - logBuilder - .SetMinimumLevel( - context.HostingEnvironment.IsDevelopment() ? - LogLevel.Information : - LogLevel.Warning) - // Default filters for core Uno Platform namespaces - .CoreLogLevel(LogLevel.Warning); - // Uno Platform namespace filter groups - // Uncomment individual methods to see more detailed logging - //// Generic Xaml events - //logBuilder.XamlLogLevel(LogLevel.Debug); - //// Layout specific messages - //logBuilder.XamlLayoutLogLevel(LogLevel.Debug); - //// Storage messages - //logBuilder.StorageLogLevel(LogLevel.Debug); - //// Binding related messages - //logBuilder.XamlBindingLogLevel(LogLevel.Debug); - //// Binder memory references tracking - //logBuilder.BinderMemoryReferenceLogLevel(LogLevel.Debug); - //// DevServer and HotReload related - //logBuilder.HotReloadCoreLogLevel(LogLevel.Information); - //// Debug JS interop - //logBuilder.WebAssemblyLogLevel(LogLevel.Debug); + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (MainWindow.Content is not Frame rootFrame) + { + // Create a Frame to act as the navigation context and navigate to the first page + rootFrame = new Frame(); - }, enableUnoLogging: true) - .UseConfiguration(configure: configBuilder => - configBuilder - .EmbeddedSource() - .Section() - ) - // Enable localization (see appsettings.json for supported languages) - .UseLocalization() - // Register Json serializers (ISerializer and ISerializer) - .UseSerialization((context, services) => services - .AddContentSerializer(context) - .AddJsonTypeInfo(WeatherForecastContext.Default.IImmutableListWeatherForecast)) - .UseHttp((context, services) => services - // Register HttpClient + // Place the frame in the current Window + MainWindow.Content = rootFrame; + + rootFrame.NavigationFailed += OnNavigationFailed; + } + + if (rootFrame.Content == null) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame.Navigate(typeof(MainPage), args.Arguments); + } + + MainWindow.SetWindowIcon(); + // Ensure the current window is active + MainWindow.Activate(); + } + + /// + /// Invoked when Navigation to a certain page fails + /// + /// The Frame which failed navigation + /// Details about the navigation failure + void OnNavigationFailed(object sender, NavigationFailedEventArgs e) + { + throw new InvalidOperationException($"Failed to load {e.SourcePageType.FullName}: {e.Exception}"); + } + + /// + /// Configures global Uno Platform logging + /// + public static void InitializeLogging() + { #if DEBUG - // DelegatingHandler will be automatically injected into Refit Client - .AddTransient() + // Logging is disabled by default for release builds, as it incurs a significant + // initialization cost from Microsoft.Extensions.Logging setup. If startup performance + // is a concern for your application, keep this disabled. If you're running on the web or + // desktop targets, you can use URL or command line parameters to enable it. + // + // For more performance documentation: https://platform.uno/docs/articles/Uno-UI-Performance.html + + var factory = LoggerFactory.Create(builder => + { +#if __WASM__ + builder.AddProvider(new global::Uno.Extensions.Logging.WebAssembly.WebAssemblyConsoleLoggerProvider()); +#elif __IOS__ || __MACCATALYST__ + builder.AddProvider(new global::Uno.Extensions.Logging.OSLogLoggerProvider()); +#else + builder.AddConsole(); #endif - .AddSingleton() - .AddRefitClient(context)) - .ConfigureServices((context, services) => - { - // TODO: Register your services - //services.AddSingleton(); - }) - .UseNavigation(RegisterRoutes) - ); - MainWindow = builder.Window; -#if DEBUG - MainWindow.EnableHotReload(); + // Exclude logs below this level + builder.SetMinimumLevel(LogLevel.Information); + + // Default filters for Uno Platform namespaces + builder.AddFilter("Uno", LogLevel.Warning); + builder.AddFilter("Windows", LogLevel.Warning); + builder.AddFilter("Microsoft", LogLevel.Warning); + + // Generic Xaml events + // builder.AddFilter("Microsoft.UI.Xaml", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.VisualStateGroup", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.StateTriggerBase", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.UIElement", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.FrameworkElement", LogLevel.Trace ); + + // Layouter specific messages + // builder.AddFilter("Microsoft.UI.Xaml.Controls", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.Controls.Layouter", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.Controls.Panel", LogLevel.Debug ); + + // builder.AddFilter("Windows.Storage", LogLevel.Debug ); + + // Binding related messages + // builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug ); + // builder.AddFilter("Microsoft.UI.Xaml.Data", LogLevel.Debug ); + + // Binder memory references tracking + // builder.AddFilter("Uno.UI.DataBinding.BinderReferenceHolder", LogLevel.Debug ); + + // DevServer and HotReload related + // builder.AddFilter("Uno.UI.RemoteControl", LogLevel.Information); + + // Debug JS interop + // builder.AddFilter("Uno.Foundation.WebAssemblyRuntime", LogLevel.Debug ); + }); + + global::Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = factory; + +#if HAS_UNO + global::Uno.UI.Adapter.Microsoft.Extensions.Logging.LoggingAdapter.Initialize(); #endif - MainWindow.SetWindowIcon(); - - Host = await builder.NavigateAsync(); - } - - private static void RegisterRoutes(IViewRegistry views, IRouteRegistry routes) - { - views.Register( - new ViewMap(ViewModel: typeof(ShellViewModel)), - new ViewMap() - ); - - routes.Register( - new RouteMap("", View: views.FindByViewModel(), - Nested: - [ - new ("Main", View: views.FindByViewModel()) - ] - ) - ); - } +#endif + } } diff --git a/samples/CSharpUno/UnoSample/Assets/Images/back.svg b/samples/CSharpUno/UnoSample/Assets/Images/back.svg deleted file mode 100644 index bcd7851b..00000000 --- a/samples/CSharpUno/UnoSample/Assets/Images/back.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/samples/CSharpUno/UnoSample/GlobalUsings.cs b/samples/CSharpUno/UnoSample/GlobalUsings.cs index c93bf566..06613b25 100644 --- a/samples/CSharpUno/UnoSample/GlobalUsings.cs +++ b/samples/CSharpUno/UnoSample/GlobalUsings.cs @@ -1,15 +1,3 @@ -global using System.Collections.Immutable; global using CommunityToolkit.Mvvm.ComponentModel; global using CommunityToolkit.Mvvm.Input; -global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Hosting; -global using Microsoft.Extensions.Localization; global using Microsoft.Extensions.Logging; -global using Microsoft.Extensions.Options; -global using UnoSample.DataContracts; -global using UnoSample.DataContracts.Serialization; -global using UnoSample.Models; -global using UnoSample.Presentation; -global using UnoSample.Services.Caching; -global using UnoSample.Services.Endpoints; -global using ApplicationExecutionState = Windows.ApplicationModel.Activation.ApplicationExecutionState; diff --git a/samples/CSharpUno/UnoSample/MainPage.xaml b/samples/CSharpUno/UnoSample/MainPage.xaml new file mode 100644 index 00000000..9167117a --- /dev/null +++ b/samples/CSharpUno/UnoSample/MainPage.xaml @@ -0,0 +1,24 @@ + + + + + + +