Implement autostart functionality, ZIP packaging, and related installation scripts; update documentation and tests

This commit is contained in:
2026-09-09 18:27:32 +03:00
parent 49d10a5242
commit 369c0347a7
18 changed files with 368 additions and 13 deletions
+15 -2
View File
@@ -5,7 +5,8 @@ using MusicBridge.Agent.Network;
namespace MusicBridge.Agent.Desktop;
internal sealed class DesktopHost(Func<MediaState> read, IMediaService media, PairingService pairing,
Func<string> network, Action showQr, Action exit, bool visible = true) : IDisposable
Func<string> network, Action showQr, Action exit, bool visible = true,
StartupSettings? startup = null, bool minimized = false) : IDisposable
{
private readonly object gate = new();
private readonly TaskCompletionSource ready = new(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -34,6 +35,18 @@ internal sealed class DesktopHost(Func<MediaState> read, IMediaService media, Pa
menu.Items.Add("Открыть MusicBridge", null, (_, _) => ShowWindow());
var toggle = menu.Items.Add("Play / Pause", null, async (_, _) => await view.SendAsync(new("toggle")));
menu.Items.Add("Подключить iPhone", null, (_, _) => { pairing.Open(); showQr(); });
if (startup is not null)
{
var autoStart = new ToolStripMenuItem("Запускать вместе с Windows");
try { autoStart.Checked = startup.Enabled; }
catch (Exception) { autoStart.Enabled = false; }
autoStart.Click += (_, _) =>
{
try { startup.SetEnabled(!startup.Enabled); autoStart.Checked = startup.Enabled; }
catch (Exception ex) { MessageBox.Show(view, ex.Message, "Автозапуск MusicBridge", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
};
menu.Items.Add(autoStart);
}
menu.Items.Add(new ToolStripSeparator());
menu.Items.Add("Завершить MusicBridge", null, (_, _) => { view.AllowClose = true; view.Close(); });
using var icon = new NotifyIcon { Icon = SystemIcons.Application, Text = "MusicBridge", ContextMenuStrip = menu, Visible = visible };
@@ -46,7 +59,7 @@ internal sealed class DesktopHost(Func<MediaState> read, IMediaService media, Pa
var text = state.HasSession ? $"MusicBridge — {state.Title}" : "MusicBridge — нет плеера";
icon.Text = text.Length > 63 ? text[..63] : text;
};
view.Shown += (_, _) => { timer.Start(); ready.TrySetResult(); };
view.Shown += (_, _) => { if (minimized) view.Hide(); timer.Start(); ready.TrySetResult(); };
lock (gate)
{
if (disposed) { ready.TrySetCanceled(); return; }