diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 30562cc..99416a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,7 +34,7 @@ jobs: $outputPath = & dotnet publish "./src/ChatPrisma/" --getProperty:PublishDir cd $outputPath ren "ChatPrisma.exe" "Chat Prisma.exe" - Compress-Archive -Path $outputPath -DestinationPath "$outputPath/Chat Prisma.zip" + Compress-Archive -Path "$outputPath*" -DestinationPath "$outputPath/Chat Prisma.zip" echo "output_path=$outputPath" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - name: Upload Artifacts @@ -46,7 +46,7 @@ jobs: - name: Create Release if: github.ref == 'refs/heads/main' - uses: ncipollo/release-action@v1 + uses: ncipollo/release-action@v1.13.0 with: artifacts: "${{ env.output_path }}/Chat Prisma.zip" tag: "v${{ env.GitBuildVersionSimple }}" diff --git a/src/ChatPrisma/App.xaml.cs b/src/ChatPrisma/App.xaml.cs index 6149946..5964b44 100644 --- a/src/ChatPrisma/App.xaml.cs +++ b/src/ChatPrisma/App.xaml.cs @@ -1,4 +1,5 @@ -using System.Windows; +using System.Diagnostics; +using System.Windows; using System.Windows.Threading; using ChatPrisma.Host; using ChatPrisma.HostedServices; @@ -13,6 +14,9 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using NLog.Extensions.Hosting; +using Onova; +using Onova.Models; +using Onova.Services; namespace ChatPrisma; @@ -98,10 +102,15 @@ private IHostBuilder CreateHostBuilder(string[] args) => Microsoft.Extensions.Ho services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(new UpdateManager( + new AssemblyMetadata("Chat Prisma", Version.Parse(ThisAssembly.AssemblyFileVersion), Environment.ProcessPath!), + new GithubPackageResolver("haefele", "ChatPrisma", "Chat.Prisma.zip"), + new ZipPackageExtractor())); // Hosted Services services.AddHostedService(); services.AddHostedService(); + services.AddHostedService(); }) .UseNLog(); } diff --git a/src/ChatPrisma/ChatPrisma.csproj b/src/ChatPrisma/ChatPrisma.csproj index 9e37736..7cc86cd 100644 --- a/src/ChatPrisma/ChatPrisma.csproj +++ b/src/ChatPrisma/ChatPrisma.csproj @@ -19,6 +19,7 @@ + diff --git a/src/ChatPrisma/HostedServices/UpdaterHostedService.cs b/src/ChatPrisma/HostedServices/UpdaterHostedService.cs new file mode 100644 index 0000000..679a228 --- /dev/null +++ b/src/ChatPrisma/HostedServices/UpdaterHostedService.cs @@ -0,0 +1,29 @@ +using System.Windows; +using Microsoft.Extensions.Hosting; +using Onova; + +namespace ChatPrisma.HostedServices; + +public class UpdaterHostedService(IUpdateManager updateManager, Application app) : IHostedService +{ + public async Task StartAsync(CancellationToken cancellationToken) + { + var result = await updateManager.CheckForUpdatesAsync(cancellationToken); + if (result is { CanUpdate: true, LastVersion: not null }) + { + await updateManager.PrepareUpdateAsync(result.LastVersion, cancellationToken: cancellationToken); + + var updateResult = MessageBox.Show("Update available!, Wanna update now?", "Title", MessageBoxButton.YesNo); + if (updateResult == MessageBoxResult.Yes) + { + updateManager.LaunchUpdater(result.LastVersion); + app.Shutdown(); + } + } + } + + public Task StopAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } +}