Skip to content

Commit

Permalink
Add updater and fix build-script to only include the files
Browse files Browse the repository at this point in the history
  • Loading branch information
haefele committed Oct 15, 2023
1 parent 674ff96 commit 2fbf30a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}"
11 changes: 10 additions & 1 deletion src/ChatPrisma/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using System.Diagnostics;
using System.Windows;
using System.Windows.Threading;
using ChatPrisma.Host;
using ChatPrisma.HostedServices;
Expand All @@ -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;

Expand Down Expand Up @@ -98,10 +102,15 @@ private IHostBuilder CreateHostBuilder(string[] args) => Microsoft.Extensions.Ho
services.AddSingleton<IChatBotService, OpenAIChatBotService>();
services.AddSingleton<IViewModelFactory, ViewModelFactory>();
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<IUpdateManager>(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<StartKeyboardHooksHostedService>();
services.AddHostedService<PrismaHostedService>();
services.AddHostedService<UpdaterHostedService>();
})
.UseNLog();
}
1 change: 1 addition & 0 deletions src/ChatPrisma/ChatPrisma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="NLog.Extensions.Hosting" Version="5.3.4" />
<PackageReference Include="FluentIcons.WPF" Version="1.1.220" />
<PackageReference Include="Onova" Version="2.6.10" />
</ItemGroup>

<ItemGroup Label="Versioning">
Expand Down
29 changes: 29 additions & 0 deletions src/ChatPrisma/HostedServices/UpdaterHostedService.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 2fbf30a

Please sign in to comment.