-
Notifications
You must be signed in to change notification settings - Fork 10
Develop #15
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
Merged
Develop #15
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,145 @@ | ||
| 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>(); | ||
| // Singleton: owns a long-lived log pump consuming the singleton UiLogBus and must survive | ||
| // navigation (so logs aren't lost and a reused LogsView page keeps working). Disposed by | ||
| // the container at app shutdown. | ||
| services.AddSingleton<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 void OnExit(ExitEventArgs e) | ||
| { | ||
| try | ||
| { | ||
| // Relay modes are stopped in the explicit quit flow (ShellWindow) before | ||
| // Shutdown(); OnExit now only disposes and flushes synchronously so it always | ||
| // runs to completion (an async-void OnExit could return before cleanup ran). | ||
| _services?.Dispose(); | ||
| } | ||
| catch | ||
| { | ||
| // Best-effort shutdown — never block process exit. | ||
| } | ||
| finally | ||
| { | ||
| Log.CloseAndFlush(); | ||
| _singleInstanceMutex?.Dispose(); | ||
| base.OnExit(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| 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) | ||
| { | ||
| // Clamp to the -80..0 display range once, then map to a 0..100 percentage | ||
| // (-80 dBFS -> 0, 0 dBFS -> 100) so the bar and the label stay consistent. | ||
| var clampedDb = Math.Clamp(db, -80.0, 0.0); | ||
| Bar.Value = (clampedDb + 80.0) / 80.0 * 100.0; | ||
| Label.Text = $"{clampedDb,5:0.0} dBFS"; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Stale comment: no Debug sink is configured.
The comment claims the logger is fanned out "plus Debug for local diagnostics," but the
LoggerConfigurationonly wiresWriteTo.UiBus(logBus). Either drop the parenthetical or add theWriteTo.Debug()sink to match intent.📝 Option A — fix the comment
📝 Committable suggestion
🤖 Prompt for AI Agents