Implement desktop tray interface with media controls and QR pairing; add related tests
This commit is contained in:
@@ -345,6 +345,49 @@ if (args.Contains("--live-read"))
|
||||
Check(next.ArtworkId == id, "real cover cache survives progress refresh");
|
||||
}
|
||||
}
|
||||
if (args.Contains("--desktop-smoke"))
|
||||
{
|
||||
var desktopMedia = new FakeMedia();
|
||||
var desktopPairing = new PairingService();
|
||||
var desktopState = new MediaState
|
||||
{
|
||||
HasSession = true, Title = "Проверка MusicBridge", Artist = "Тестовый плеер", PlaybackStatus = "Playing",
|
||||
Volume = 0.5f, Muted = false, PositionSeconds = 45, EndSeconds = 180, MaxSeekSeconds = 180,
|
||||
Capabilities = new(true, true, true, true, true, true)
|
||||
};
|
||||
var exited = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
using (var host = new MusicBridge.Agent.Desktop.DesktopHost(() => desktopState, desktopMedia, desktopPairing,
|
||||
() => "Домашняя сеть • https://192.168.1.10:8765", () => { }, () => exited.TrySetResult(), visible: false))
|
||||
{
|
||||
await host.StartAsync().WaitAsync(TimeSpan.FromSeconds(8));
|
||||
var field = typeof(MusicBridge.Agent.Desktop.DesktopHost).GetField("window", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!;
|
||||
var view = (MusicBridge.Agent.Desktop.AgentWindow)field.GetValue(host)!;
|
||||
view.Invoke(() =>
|
||||
{
|
||||
view.RefreshState();
|
||||
using var frame = new Bitmap(view.Width, view.Height);
|
||||
view.DrawToBitmap(frame, new Rectangle(0, 0, frame.Width, frame.Height));
|
||||
frame.Save(Path.Combine(AppContext.BaseDirectory, "desktop-smoke.png"));
|
||||
var toggle = (Button)view.Controls.Find("toggle", true).Single();
|
||||
Check(toggle.Enabled, "desktop enables supported commands");
|
||||
toggle.PerformClick();
|
||||
Check(desktopMedia.Commands.Last().Type == "toggle", "desktop play button reaches shared media service");
|
||||
var slider = (TrackBar)view.Controls.Find("volume", true).Single();
|
||||
slider.Value = 80;
|
||||
typeof(Control).GetMethod("OnKeyUp", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!
|
||||
.Invoke(slider, [new KeyEventArgs(Keys.Right)]);
|
||||
Check(desktopMedia.Commands.Last() is { Type: "volume", Value: 0.8 }, "desktop volume slider sends absolute volume");
|
||||
desktopState = new MediaState();
|
||||
view.RefreshState();
|
||||
Check(!toggle.Enabled && !slider.Enabled, "desktop disables unavailable player and volume controls");
|
||||
view.Close();
|
||||
Check(!view.IsDisposed && !view.Visible, "closing desktop window hides it without stopping agent");
|
||||
});
|
||||
Check(!exited.Task.IsCompleted, "tray host stays alive while window is hidden");
|
||||
}
|
||||
await exited.Task.WaitAsync(TimeSpan.FromSeconds(5));
|
||||
Check(exited.Task.IsCompleted, "disposing tray host stops its message loop");
|
||||
}
|
||||
if (args.Contains("--qr-window-smoke"))
|
||||
{
|
||||
var uiClock = new TestClock(DateTimeOffset.UtcNow);
|
||||
|
||||
Reference in New Issue
Block a user