Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/PlanViewer.App/AboutWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="PlanViewer.App.AboutWindow"
Title="About Performance Studio"
Width="450" Height="460"
Width="450" Height="500"
CanResize="False"
WindowStartupLocation="CenterOwner"
Icon="avares://PlanViewer.App/EDD.ico"
Expand Down Expand Up @@ -44,6 +44,17 @@
Text="www.erikdarling.com"
PointerPressed="DarlingDataLink_Click"
TextDecorations="Underline"/>
<StackPanel Orientation="Horizontal" Spacing="8" Margin="0,6,0,0">
<Button x:Name="CheckUpdateButton" Content="Check for Updates"
Click="CheckUpdate_Click" Padding="10,4" FontSize="12"/>
<TextBlock x:Name="UpdateStatusText" FontSize="12" VerticalAlignment="Center"
Foreground="{DynamicResource ForegroundBrush}"/>
<TextBlock x:Name="UpdateLink" FontSize="12" VerticalAlignment="Center"
Foreground="{DynamicResource AccentBrush}"
Cursor="Hand" IsVisible="False"
TextDecorations="Underline"
PointerPressed="UpdateLink_Click"/>
</StackPanel>
</StackPanel>

<!-- MCP Settings -->
Expand Down
36 changes: 36 additions & 0 deletions src/PlanViewer.App/AboutWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Avalonia.Input.Platform;
using Avalonia.Interactivity;
using PlanViewer.App.Mcp;
using PlanViewer.App.Services;

namespace PlanViewer.App;

Expand Down Expand Up @@ -72,6 +73,41 @@ private async void CopyMcpCommand_Click(object? sender, RoutedEventArgs e)
}
}

private string? _updateUrl;

private async void CheckUpdate_Click(object? sender, RoutedEventArgs e)
{
CheckUpdateButton.IsEnabled = false;
UpdateStatusText.Text = "Checking...";
UpdateLink.IsVisible = false;

var currentVersion = Assembly.GetExecutingAssembly().GetName().Version ?? new Version(0, 0, 0);
var result = await UpdateChecker.CheckAsync(currentVersion);

if (result.Error != null)
{
UpdateStatusText.Text = $"Error: {result.Error}";
}
else if (result.UpdateAvailable)
{
UpdateStatusText.Text = $"New version available:";
UpdateLink.Text = result.LatestVersion;
UpdateLink.IsVisible = true;
_updateUrl = result.ReleaseUrl;
}
else
{
UpdateStatusText.Text = $"You're up to date ({result.LatestVersion})";
}

CheckUpdateButton.IsEnabled = true;
}

private void UpdateLink_Click(object? sender, PointerPressedEventArgs e)
{
if (_updateUrl != null) OpenUrl(_updateUrl);
}

private void CloseButton_Click(object? sender, RoutedEventArgs e) => Close();

private static void OpenUrl(string url)
Expand Down
53 changes: 53 additions & 0 deletions src/PlanViewer.App/Services/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

namespace PlanViewer.App.Services;

public record UpdateCheckResult(bool UpdateAvailable, string? LatestVersion, string? ReleaseUrl, string? Error);

public static class UpdateChecker
{
private const string ReleasesApiUrl =
"https://api.github.com/repos/erikdarlingdata/PerformanceStudio/releases/latest";

private static readonly HttpClient Http = new()
{
DefaultRequestHeaders =
{
{ "User-Agent", "PerformanceStudio-UpdateCheck" },
{ "Accept", "application/vnd.github+json" }
},
Timeout = TimeSpan.FromSeconds(10)
};

public static async Task<UpdateCheckResult> CheckAsync(Version currentVersion)
{
try
{
var json = await Http.GetStringAsync(ReleasesApiUrl);
using var doc = JsonDocument.Parse(json);
var root = doc.RootElement;

var tagName = root.GetProperty("tag_name").GetString();
var htmlUrl = root.GetProperty("html_url").GetString();

if (string.IsNullOrEmpty(tagName))
return new UpdateCheckResult(false, null, null, "No release tag found");

// Strip leading 'v' from tag (e.g. "v0.9.0" -> "0.9.0")
var versionStr = tagName.StartsWith('v') ? tagName[1..] : tagName;

if (!Version.TryParse(versionStr, out var latestVersion))
return new UpdateCheckResult(false, tagName, htmlUrl, $"Could not parse version: {tagName}");

var updateAvailable = latestVersion > currentVersion;
return new UpdateCheckResult(updateAvailable, tagName, htmlUrl, null);
}
catch (Exception ex)
{
return new UpdateCheckResult(false, null, null, ex.Message);
}
}
}
Loading