Browse Source

Colour the update banner by state and fix dark-mode text

The banner used one amber colour for every state. Show green when ILSpy
is up to date and amber when an update is available, driven by a new
UpdatePanelViewModel.UpdateAvailable bound to a style class on the border.

The message text also inherited the dark theme's near-white foreground,
which was unreadable on the always-light banner; pin it to a dark colour
since the banner stays light in both themes.

Assisted-by: Claude:claude-opus-4-8:Claude Code
pull/3755/head
Siegfried Pammer 1 month ago
parent
commit
d2382ccedb
  1. 67
      ILSpy.Tests/Updates/UpdatePanelViewModelTests.cs
  2. 5
      ILSpy/ViewModels/UpdatePanelViewModel.cs
  3. 20
      ILSpy/Views/UpdatePanel.axaml

67
ILSpy.Tests/Updates/UpdatePanelViewModelTests.cs

@ -0,0 +1,67 @@
// Copyright (c) 2026 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System.Collections.Generic;
using System.ComponentModel;
using Avalonia.Headless.NUnit;
using AwesomeAssertions;
using ILSpy.AppEnv;
using ILSpy.ViewModels;
using NUnit.Framework;
namespace ICSharpCode.ILSpy.Tests.Updates;
/// <summary>
/// The update banner colours itself by state: green when ILSpy is up to date, amber when an
/// update is available. <see cref="UpdatePanelViewModel.UpdateAvailable"/> is the boolean that
/// drives that (bound to a style class in the view), so pin that it tracks the download URL.
/// </summary>
[TestFixture]
public class UpdatePanelViewModelTests
{
[AvaloniaTest]
public void UpdateAvailable_tracks_the_download_url()
{
var vm = AppComposition.Current.GetExport<UpdatePanelViewModel>();
vm.UpdateAvailableDownloadUrl = null;
vm.UpdateAvailable.Should().BeFalse("no download URL means ILSpy is up to date");
vm.UpdateAvailableDownloadUrl = "https://example.invalid/ILSpy.zip";
vm.UpdateAvailable.Should().BeTrue("a download URL means an update is available");
}
[AvaloniaTest]
public void Setting_the_download_url_notifies_UpdateAvailable()
{
var vm = AppComposition.Current.GetExport<UpdatePanelViewModel>();
vm.UpdateAvailableDownloadUrl = null;
var changed = new List<string?>();
vm.PropertyChanged += (_, e) => changed.Add(e.PropertyName);
vm.UpdateAvailableDownloadUrl = "https://example.invalid/ILSpy.zip";
changed.Should().Contain(nameof(UpdatePanelViewModel.UpdateAvailable),
"the banner colour binds to UpdateAvailable, so it must raise PropertyChanged for it");
}
}

5
ILSpy/ViewModels/UpdatePanelViewModel.cs

@ -51,6 +51,7 @@ namespace ILSpy.ViewModels
[ObservableProperty] [ObservableProperty]
[NotifyPropertyChangedFor(nameof(ButtonText))] [NotifyPropertyChangedFor(nameof(ButtonText))]
[NotifyPropertyChangedFor(nameof(Message))] [NotifyPropertyChangedFor(nameof(Message))]
[NotifyPropertyChangedFor(nameof(UpdateAvailable))]
string? updateAvailableDownloadUrl; string? updateAvailableDownloadUrl;
[ObservableProperty] [ObservableProperty]
@ -64,6 +65,10 @@ namespace ILSpy.ViewModels
? "A new version of ILSpy is available." ? "A new version of ILSpy is available."
: "ILSpy is up to date."; : "ILSpy is up to date.";
/// <summary>True once a download URL is known. Drives the banner colour: amber when an
/// update is available, green when ILSpy is up to date.</summary>
public bool UpdateAvailable => UpdateAvailableDownloadUrl != null;
[RelayCommand] [RelayCommand]
void Close() => IsPanelVisible = false; void Close() => IsPanelVisible = false;

20
ILSpy/Views/UpdatePanel.axaml

@ -4,9 +4,25 @@
x:Class="ILSpy.Views.UpdatePanel" x:Class="ILSpy.Views.UpdatePanel"
x:DataType="vm:UpdatePanelViewModel" x:DataType="vm:UpdatePanelViewModel"
IsVisible="{Binding IsPanelVisible}"> IsVisible="{Binding IsPanelVisible}">
<Border Background="#FFFFE08A" BorderBrush="#FFCC8800" BorderThickness="0,0,0,1" Padding="8,4"> <UserControl.Styles>
<!-- The banner colours itself by state: green when ILSpy is up to date (default, no
class), amber when an update is available (the .updateAvailable class, toggled from
UpdatePanelViewModel.UpdateAvailable). -->
<Style Selector="Border#PanelBorder">
<Setter Property="Background" Value="#FFDFF0D8" />
<Setter Property="BorderBrush" Value="#FF4F8A10" />
</Style>
<Style Selector="Border#PanelBorder.updateAvailable">
<Setter Property="Background" Value="#FFFFE08A" />
<Setter Property="BorderBrush" Value="#FFCC8800" />
</Style>
</UserControl.Styles>
<Border Name="PanelBorder" Classes.updateAvailable="{Binding UpdateAvailable}"
BorderThickness="0,0,0,1" Padding="8,4">
<Grid ColumnDefinitions="*,Auto,Auto" ColumnSpacing="8"> <Grid ColumnDefinitions="*,Auto,Auto" ColumnSpacing="8">
<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="{Binding Message}" /> <!-- Fixed dark foreground: the banner stays a light colour in both themes, so the
dark theme's near-white default foreground would be unreadable on it. -->
<TextBlock Grid.Column="0" VerticalAlignment="Center" Foreground="Black" Text="{Binding Message}" />
<Button Grid.Column="1" Content="{Binding ButtonText}" <Button Grid.Column="1" Content="{Binding ButtonText}"
Command="{Binding DownloadOrCheckUpdateCommand}" /> Command="{Binding DownloadOrCheckUpdateCommand}" />
<Button Grid.Column="2" Content="&#x2715;" Width="24" Padding="0" <Button Grid.Column="2" Content="&#x2715;" Width="24" Padding="0"

Loading…
Cancel
Save