-
Notifications
You must be signed in to change notification settings - Fork 10
RR1-T102 Windows app base #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project> | ||
| <!-- | ||
| The .NET SDK does NOT emit a combined "NET10_0_WINDOWS" preprocessor symbol for the | ||
| net10.0-windows target framework — it defines NET10_0, WINDOWS, WINDOWS7_0, etc. | ||
| This codebase gates all Windows-only code (radio/audio modes, device enumeration, | ||
| the tune meter, WPF) with #if NET10_0_WINDOWS, so without this define that code | ||
| silently compiles out of every build. Define it for the windows TFM across all | ||
| projects so the Windows-only code actually compiles into the windows build (and | ||
| stays excluded from the cross-platform net10.0 / Linux / Docker build). | ||
| --> | ||
| <PropertyGroup Condition="'$(TargetFramework)' == 'net10.0-windows'"> | ||
| <DefineConstants>$(DefineConstants);NET10_0_WINDOWS</DefineConstants> | ||
| </PropertyGroup> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| <Application x:Class="Resgrid.Audio.Relay.App" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| StartupUri="MainWindow.xaml"> | ||
| <Application.Resources /> | ||
| xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"> | ||
| <Application.Resources> | ||
| <ResourceDictionary> | ||
| <ResourceDictionary.MergedDictionaries> | ||
| <ui:ThemesDictionary Theme="Dark" /> | ||
| <ui:ControlsDictionary /> | ||
| </ResourceDictionary.MergedDictionaries> | ||
| </ResourceDictionary> | ||
| </Application.Resources> | ||
| </Application> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,146 @@ | ||
| using System.Windows; | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Windows; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Resgrid.Audio.Relay.Services; | ||
| using Resgrid.Audio.Relay.ViewModels; | ||
| using Resgrid.Audio.Relay.Views; | ||
| using Resgrid.Relay.Engine; | ||
| using Resgrid.Relay.Engine.Logging; | ||
| using Serilog; | ||
| using Wpf.Ui.Appearance; | ||
|
|
||
| namespace Resgrid.Audio.Relay | ||
| { | ||
| /// <summary> | ||
| /// Application entry point. Owns the single-instance guard, the DI container, theme | ||
| /// application and the start-to-tray vs start-visible decision. The engine is composed via | ||
| /// <see cref="ServiceCollectionExtensions.AddRelayEngine"/>; logging is fanned out to a | ||
| /// <see cref="UiLogBus"/> for the Logs screen. | ||
| /// </summary> | ||
| public partial class App : Application | ||
| { | ||
| private const string SingleInstanceMutexName = "Global\\ResgridRelayDesktop"; | ||
|
|
||
| private Mutex _singleInstanceMutex; | ||
| private ServiceProvider _services; | ||
|
|
||
| /// <summary>Process-wide service provider, exposed for XAML-created view-models if needed.</summary> | ||
| public static IServiceProvider Services { get; private set; } | ||
|
|
||
| protected override void OnStartup(StartupEventArgs e) | ||
| { | ||
| base.OnStartup(e); | ||
|
|
||
| // (1) Single-instance guard — surface the existing instance instead of starting twice. | ||
| _singleInstanceMutex = new Mutex(initiallyOwned: true, SingleInstanceMutexName, out var createdNew); | ||
| if (!createdNew) | ||
| { | ||
| MessageBox.Show( | ||
| "Resgrid Relay is already running.", | ||
| "Resgrid Relay", | ||
| MessageBoxButton.OK, | ||
| MessageBoxImage.Information); | ||
| Shutdown(); | ||
| return; | ||
| } | ||
|
|
||
| // (2) Build the DI container. | ||
| _services = BuildServiceProvider(); | ||
| Services = _services; | ||
|
|
||
| // (3) Apply the WPF-UI theme. | ||
| ApplicationThemeManager.Apply(ApplicationTheme.Dark); | ||
|
Check warning on line 54 in Resgrid.Audio.Relay/App.xaml.cs
|
||
|
|
||
| // (4) Resolve the shell. Start hidden to tray when launched with --minimized. | ||
| var startMinimized = e.Args.Any(a => | ||
| string.Equals(a, "--minimized", StringComparison.OrdinalIgnoreCase) || | ||
| string.Equals(a, "/minimized", StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| var shell = _services.GetRequiredService<ShellWindow>(); | ||
| MainWindow = shell; | ||
|
|
||
| if (startMinimized) | ||
| { | ||
| // Stay hidden — the tray icon (created with the window) keeps the app alive. | ||
| shell.StartHiddenToTray(); | ||
| } | ||
| else | ||
| { | ||
| shell.Show(); | ||
| } | ||
| } | ||
|
|
||
| private static ServiceProvider BuildServiceProvider() | ||
| { | ||
| var services = new ServiceCollection(); | ||
|
|
||
| // Engine (per-mode service factory delegate). | ||
| services.AddRelayEngine(); | ||
|
|
||
| // UI log bus + a Serilog logger fanned out to it (plus Debug for local diagnostics). | ||
| var logBus = new UiLogBus(); | ||
| services.AddSingleton(logBus); | ||
|
|
||
| ILogger logger = new LoggerConfiguration() | ||
| .MinimumLevel.Information() | ||
| .WriteTo.UiBus(logBus) | ||
| .CreateLogger(); | ||
| services.AddSingleton(logger); | ||
| Log.Logger = logger; | ||
|
|
||
| // App services. | ||
| services.AddSingleton<ConfigurationService>(); | ||
| services.AddSingleton<DeviceEnumerationService>(); | ||
| services.AddSingleton<RelayController>(); | ||
|
|
||
| // View-models. | ||
| services.AddSingleton<ShellViewModel>(); | ||
| services.AddTransient<DashboardViewModel>(); | ||
| services.AddTransient<OperationsViewModel>(); | ||
| services.AddTransient<ConfigurationViewModel>(); | ||
| services.AddTransient<LogsViewModel>(); | ||
| services.AddTransient<DevicesViewModel>(); | ||
| services.AddTransient<AboutViewModel>(); | ||
|
|
||
| // Views. | ||
| services.AddTransient<DashboardView>(); | ||
| services.AddTransient<OperationsView>(); | ||
| services.AddTransient<ConfigurationView>(); | ||
| services.AddTransient<LogsView>(); | ||
| services.AddTransient<DevicesView>(); | ||
| services.AddTransient<AboutView>(); | ||
|
|
||
| // Shell window. | ||
| services.AddSingleton<ShellWindow>(); | ||
|
|
||
| return services.BuildServiceProvider(); | ||
| } | ||
|
|
||
| protected override async void OnExit(ExitEventArgs e) | ||
| { | ||
| try | ||
| { | ||
| if (_services != null) | ||
| { | ||
| var controller = _services.GetService<RelayController>(); | ||
| if (controller != null) | ||
| await controller.StopAllAsync().ConfigureAwait(true); | ||
|
|
||
| _services.Dispose(); | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| // Best-effort shutdown — never block process exit. | ||
| } | ||
| finally | ||
| { | ||
| Log.CloseAndFlush(); | ||
| _singleInstanceMutex?.Dispose(); | ||
| base.OnExit(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| <UserControl x:Class="Resgrid.Audio.Relay.Controls.LevelMeter" | ||
| xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| mc:Ignorable="d" | ||
| x:Name="Root" | ||
| d:DesignHeight="20" d:DesignWidth="200"> | ||
| <Grid> | ||
| <ProgressBar x:Name="Bar" | ||
| Minimum="0" Maximum="100" | ||
| Height="14" | ||
| Foreground="#2ECC71" | ||
| Background="#22000000" /> | ||
| <TextBlock x:Name="Label" | ||
| HorizontalAlignment="Center" | ||
| VerticalAlignment="Center" | ||
| FontSize="10" | ||
| Foreground="#DDFFFFFF" /> | ||
| </Grid> | ||
| </UserControl> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using System; | ||
| using System.Windows; | ||
| using System.Windows.Controls; | ||
|
|
||
| namespace Resgrid.Audio.Relay.Controls | ||
| { | ||
| /// <summary> | ||
| /// A simple input-level meter that maps a dBFS value (typically -80..0) onto a 0..100 | ||
| /// <see cref="ProgressBar"/> using <c>(db + 80) / 80</c>, and shows the numeric value. | ||
| /// </summary> | ||
| public partial class LevelMeter : UserControl | ||
| { | ||
| public LevelMeter() | ||
| { | ||
| InitializeComponent(); | ||
| UpdateVisual(Dbfs); | ||
| } | ||
|
|
||
| public static readonly DependencyProperty DbfsProperty = DependencyProperty.Register( | ||
| nameof(Dbfs), | ||
| typeof(double), | ||
| typeof(LevelMeter), | ||
| new FrameworkPropertyMetadata(-80.0, OnDbfsChanged)); | ||
|
|
||
| /// <summary>Current input level in dBFS. Clamped to the -80..0 display range.</summary> | ||
| public double Dbfs | ||
| { | ||
| get => (double)GetValue(DbfsProperty); | ||
| set => SetValue(DbfsProperty, value); | ||
| } | ||
|
|
||
| private static void OnDbfsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
| { | ||
| ((LevelMeter)d).UpdateVisual((double)e.NewValue); | ||
| } | ||
|
|
||
| private void UpdateVisual(double db) | ||
| { | ||
| // Map dBFS to a 0..100 percentage: -80 dBFS -> 0, 0 dBFS -> 100. | ||
| var percent = Math.Clamp((db + 80.0) / 80.0 * 100.0, 0.0, 100.0); | ||
| Bar.Value = percent; | ||
| Label.Text = $"{db,5:0.0} dBFS"; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major
🧩 Analysis chain
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 1208
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 167
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 940
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 230
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 394
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 235
🏁 Script executed:
Repository: Resgrid/Relay
Length of output: 630
Asynchronous
OnExitlogic risks skipping cleanupApplication.OnExitis not awaited by the WPF runtime. WhenApplication.Current.Shutdown()is called, it invokes this method and proceeds to terminate the process immediately upon the method's return (yielding atawait controller.StopAllAsync()). This causes thefinallyblock to be skipped, leaving Serilog logs unflushed and the single-instance mutex unreleased.Move the
StopAllAsynclogic into the explicit quit command inShellWindow.xaml.cs(calling it beforeShutdown()), and revertOnExitto be strictly synchronous with only cleanup tasks.Original Concerned Code
🤖 Prompt for AI Agents