Tracing key presses with eight windows open and a busy feed showed the UI thread running 36 tasks of 8 ms or more in 25 seconds (up to 93 ms), nearly all of them the Available window replacing its grid rows. A key pressed meanwhile waits for the task. - OperatorActivity records the last key press. The Available, Score, Telnet, Grayline and Statistics refreshes wait until there has been no key press for 800 ms. - Bandmap no longer holds its lock while it works out spot lifetimes or spot keys, so the entry window's lookups do not wait on it. - The bandmap view stops drawing labels pushed below its edge. Tasks of 8 ms or more dropped from 36 (1,259 ms in all) to 8 (205 ms). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
117 lines
4.0 KiB
C#
117 lines
4.0 KiB
C#
using Avalonia.Media;
|
|
using Avalonia.Threading;
|
|
using Nonemm.Core;
|
|
using Nonemm.Core.Country;
|
|
using Nonemm.Session;
|
|
|
|
namespace Nonemm.App.Windows;
|
|
|
|
/// N1MM's grey line window: the world with the night drawn on it, our own
|
|
/// station on it, and the stations being called and spotted. It follows the
|
|
/// clock, redrawing every minute.
|
|
public sealed partial class GraylineWindow : RefreshableWindow
|
|
{
|
|
private static readonly IBrush HomeColour = new SolidColorBrush(Color.FromRgb(0xFF, 0xFF, 0xFF));
|
|
private static readonly IBrush CallColour = new SolidColorBrush(Color.FromRgb(0xFF, 0x6B, 0x4A));
|
|
private static readonly IBrush SpotColour = new SolidColorBrush(Color.FromRgb(0x6A, 0xC8, 0xFF));
|
|
|
|
private readonly AppSession session;
|
|
private readonly DispatcherTimer clock;
|
|
|
|
public GraylineWindow(AppSession session)
|
|
{
|
|
this.session = session;
|
|
InitializeComponent();
|
|
clock = new DispatcherTimer { Interval = TimeSpan.FromMinutes(1) };
|
|
clock.Tick += (_, _) => Refresh();
|
|
clock.Start();
|
|
Closed += (_, _) =>
|
|
{
|
|
clock.Stop();
|
|
later?.Cancel();
|
|
};
|
|
Refresh();
|
|
}
|
|
|
|
private OperatingPosition? Radio => session.Position;
|
|
|
|
private Throttled? later;
|
|
|
|
/// The map is not watched closely: a station typed or spotted shows up
|
|
/// within fifteen seconds, and the grey line moves too slowly to see.
|
|
public override void RefreshForEntry() => RefreshFromSession();
|
|
|
|
public override void RefreshFromSession()
|
|
{
|
|
later ??= new Throttled(TimeSpan.FromSeconds(15), Refresh, holdWhileTyping: true);
|
|
later.Request();
|
|
}
|
|
|
|
public override void Refresh()
|
|
{
|
|
DateTime now = DateTime.UtcNow;
|
|
IReadOnlyList<MapMarker> markers = Markers();
|
|
// the terminator moves a quarter of a degree a minute, so a redraw
|
|
// for nothing but the clock can wait
|
|
if (now - Map.Moment < TimeSpan.FromSeconds(30) && Map.Markers.SequenceEqual(markers))
|
|
{
|
|
return;
|
|
}
|
|
Map.Moment = now;
|
|
Map.Markers = markers;
|
|
Map.InvalidateVisual();
|
|
}
|
|
|
|
private IReadOnlyList<MapMarker> Markers()
|
|
{
|
|
List<MapMarker> markers = [];
|
|
if (GridSquare.TryParse(session.Settings.Station.GridSquare, out GridSquare home))
|
|
{
|
|
markers.Add(new MapMarker(
|
|
session.Settings.Station.Callsign,
|
|
home.Latitude,
|
|
home.Longitude,
|
|
HomeColour));
|
|
}
|
|
foreach (Station station in Stations())
|
|
{
|
|
markers.Add(new MapMarker(station.Call, station.Latitude, station.Longitude, station.Colour));
|
|
}
|
|
return markers;
|
|
}
|
|
|
|
/// The station being called, and every station spotted on the band we are
|
|
/// on. Both are placed by the country file, which holds a position for each
|
|
/// country: it is the middle of the country rather than the station itself,
|
|
/// which is as much as a callsign says.
|
|
private IReadOnlyList<Station> Stations()
|
|
{
|
|
List<Station> found = [];
|
|
if (Radio is { } position && Where(position.Entry.Call) is { } called)
|
|
{
|
|
found.Add(new Station(
|
|
position.Entry.Call.Trim().ToUpperInvariant(),
|
|
called.Latitude,
|
|
called.Longitude,
|
|
CallColour));
|
|
}
|
|
if (Radio is { } here && Bands.ForFrequency(here.Frequency) is { } band)
|
|
{
|
|
foreach (Spotting.Spot spot in session.Bandmap.On(band).Where(s => s.IsStation))
|
|
{
|
|
string call = spot.Call.Text;
|
|
if (found.All(s => s.Call != call) && Where(call) is { } place)
|
|
{
|
|
found.Add(new Station(call, place.Latitude, place.Longitude, SpotColour));
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
private CountryLookup? Where(string call) =>
|
|
call.Trim().Length == 0 ? null : session.Countries?.Find(call.Trim());
|
|
|
|
private sealed record Station(string Call, double Latitude, double Longitude, IBrush Colour);
|
|
}
|