Verified findings from a multi-dimension code audit, plus the two install-flow bugs: - Fix Opus encoder use-after-free on a codec/rate change while streaming (guard swap vs encode). - Fix "both" single-file recording dropping audio + drifting (drain both directions in lockstep). - Fix broken clip counter, UPnP teardown on exit, auto-update-restart foreground grant, and a malformed-Opus-format packet orphaning a playout session forever. - Post-install relaunch now respects start-minimised; uninstall is path-aware so it won't clear a different copy's run-at-startup. - Perf/hygiene: cache AppConfig off UI hot paths, fold per-peer EQ+gain into one pass, deterministic disposal (tray menu, timers, COM shortcut, Process handles, process meter), ring-buffer overflow guard, receiver session-lock fix, remote-control allow-list moved onto the UI thread. - Remove dead code (two IsAsioBackend, SessionPlayout.Reset, IsSameEndpoint, RemSoundUpdater IDisposable); several stale-doc fixes. Deferred (not in this release): drift-estimator tweak, peer-discovery pruning, uninstall retry-loop, encryption nonce. Wire format unchanged (interops v3.3-v5.1). Version -> 5.2. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
2.3 KiB
C#
53 lines
2.3 KiB
C#
using RemSound.Core;
|
|
|
|
namespace RemSound.App;
|
|
|
|
/// <summary>
|
|
/// Plays a short cue whenever the user switches between tabs anywhere in RemSound - the main
|
|
/// window's tab strip and every tabbed dialog (Preferences, Recording settings, ...). Fired from
|
|
/// <see cref="QuietTabControl"/> on a selection change, gated on the tab control actually containing
|
|
/// focus, so a genuine user switch (arrow keys / Ctrl+Tab) clicks but the programmatic selection
|
|
/// done while building or restoring a window stays silent.
|
|
///
|
|
/// Machine-wide cue (<see cref="AppConfig.EnableTabSwitchCue"/>), shipped as numbered variants
|
|
/// ("tab switch 1.wav", ...) and configured in Preferences exactly like the other cues. Default on.
|
|
/// </summary>
|
|
internal static class TabSwitchSoundService
|
|
{
|
|
private static CuePlayer? switchSound;
|
|
// Cached at Reload() so Play() (fires on every focused tab change) doesn't re-read + re-deserialize
|
|
// the whole config file just to fetch one bool. Reload() runs whenever cue settings change.
|
|
private static bool enableTabSwitch;
|
|
|
|
/// <summary>When true, <see cref="Play"/> is a no-op. Reserved for bulk programmatic tab changes
|
|
/// the focus gate doesn't already cover; mirrors <see cref="CheckSoundService.Suppressed"/>.</summary>
|
|
public static bool Suppressed { get; set; }
|
|
|
|
/// <summary>(Re)load the cue from the current cue configuration. Call at startup and whenever cue
|
|
/// settings change, alongside <see cref="CheckSoundService.Reload"/>.</summary>
|
|
public static void Reload()
|
|
{
|
|
var cfg = AppConfig.Load();
|
|
enableTabSwitch = cfg.EnableTabSwitchCue;
|
|
switchSound = LoadCue(MainForm.CueId.TabSwitch, "tab switch.wav", cfg);
|
|
}
|
|
|
|
public static void Play()
|
|
{
|
|
if (Suppressed) return;
|
|
if (enableTabSwitch) switchSound?.Play();
|
|
}
|
|
|
|
private static CuePlayer? LoadCue(string cueId, string defaultFile, AppConfig cfg)
|
|
{
|
|
try
|
|
{
|
|
string? path = cfg.MachineCueCustomPaths.TryGetValue(cueId, out var custom) && File.Exists(custom)
|
|
? custom
|
|
: CueSounds.ResolveDefaultPath(cueId, defaultFile, cfg);
|
|
return path is not null && File.Exists(path) ? new CuePlayer(path) : null;
|
|
}
|
|
catch { return null; }
|
|
}
|
|
}
|