Try setting up installer/updater

This commit is contained in:
2024-09-26 19:37:53 -04:00
parent c4cd246fb0
commit 06ddddb852
4 changed files with 113 additions and 1 deletions

28
.github/workflows/main.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: Deploy to GitHub Releases
on:
push:
branches:
- main
jobs:
deploy-to-github-releases:
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish Application
run: dotnet publish WorldClockStatusWindow/WorldClockStatusWindow.csproj -c Release -o publish -r win-x64 --self-contained true
- name: Create Velopack Release
run: |
dotnet tool install -g vpk
vpk download github --repoUrl https://github.com/ckaczor/WorldClockStatusWindow
vpk pack -u MyUniqueIdentifier -v ${{ steps.get-version.outputs.version }} -p publish
vpk upload github --repoUrl https://github.com/ckaczor/WorldClockStatusWindow --publish --releaseName "WorldClockStatusWindow ${{ steps.get-version.outputs.version }}" --tag v${{ steps.get-version.outputs.version }}

27
Program.cs Normal file
View File

@@ -0,0 +1,27 @@
using Microsoft.Extensions.Logging;
using Serilog;
using System;
using Velopack;
namespace WorldClockStatusWindow;
internal class Program
{
[STAThread]
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration().WriteTo.File("log.txt").CreateLogger();
Log.Logger.Information("Start");
var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger);
VelopackApp.Build().Run(loggerFactory.CreateLogger("Install"));
var app = new App();
app.InitializeComponent();
app.Run();
Log.Logger.Information("End");
}
}

View File

@@ -5,8 +5,14 @@ using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Threading;
using Serilog;
using Serilog.Core;
using Velopack;
using Velopack.Sources;
using WorldClockStatusWindow.Properties;
namespace WorldClockStatusWindow;
@@ -25,9 +31,47 @@ internal class WindowSource : IWindowSource, IDisposable
_dispatcher = Dispatcher.CurrentDispatcher;
_timer = new Timer(1000);
Task.Factory.StartNew(UpdateApp).ContinueWith(_ => Start());
}
private async Task<bool> UpdateApp()
{
try
{
var updateManager = new UpdateManager(new GithubSource("https://github.com/ckaczor/WorldClockStatusWindow", null, false));
if (!updateManager.IsInstalled)
return false;
_dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Checking for update..."));
var newVersion = await updateManager.CheckForUpdatesAsync();
if (newVersion == null)
return false;
_dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Downloading update..."));
await updateManager.DownloadUpdatesAsync(newVersion);
_dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText("Installing update..."));
updateManager.ApplyUpdatesAndRestart(newVersion);
}
catch (Exception e)
{
Log.Logger.Error(e, nameof(UpdateApp));
}
return true;
}
private void Start()
{
Load();
_timer = new Timer(1000);
_timer.Elapsed += HandleTimerElapsed;
_timer.Enabled = true;
}
@@ -71,6 +115,10 @@ internal class WindowSource : IWindowSource, IDisposable
text.Append($"{timeZoneEntry.Label.PadLeft(labelLength)}: {TimeZoneInfo.ConvertTime(now, timeZone).ToString(Properties.Settings.Default.TimeFormat)}");
}
text.AppendLine();
text.AppendLine();
text.Append($"Version: {Assembly.GetEntryAssembly()!.GetName().Version!.ToString()}");
_dispatcher.InvokeAsync(() => _floatingStatusWindow.SetText(text.ToString()));
}

View File

@@ -5,6 +5,7 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<StartupObject>WorldClockStatusWindow.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<AppDesigner Include="Properties\" />
@@ -13,7 +14,12 @@
<PackageReference Include="ChrisKaczor.Wpf.Application.StartWithWindows" Version="1.0.5" />
<PackageReference Include="ChrisKaczor.Wpf.Windows.FloatingStatusWindow" Version="2.0.0.5" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="Velopack" Version="0.0.626" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
@@ -28,4 +34,7 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include=".github\workflows\main.yml" />
</ItemGroup>
</Project>