Skip to content

Commit 0c16f23

Browse files
Save uncommitted changes
1 parent d2f2f09 commit 0c16f23

3 files changed

Lines changed: 106 additions & 13 deletions

File tree

‎windows/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ own `CHANGELOG.md` at the repository root.
66
## [Unreleased]
77

88
### Fixed
9+
- **Settings now opens immediately while microphones load in the background** — microphone device enumeration is now asynchronous, and the microphone picker shows a loading spinner until devices are ready instead of blocking the settings window during startup.
910
- **Picker overlays now match the tray popup shell style** — capture, screen, window, and countdown picker windows now use the same context-menu presenter behavior, 8px rounded window clipping, and filled popup surface treatment as the tray popup, making corners/backgrounds visually consistent.
1011
- **Overlay windows now use a consistent popup presenter** — recording/processing and region select/indicator overlays now use the same context-menu presenter path as other picker overlays, reducing shell/chrome inconsistencies.
1112
- **winget dependency installation no longer forces user scope** — removed `Scope: user` from the

‎windows/src/TinyClips.App/SettingsViewModel.cs‎

Lines changed: 88 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System.Collections.Generic;
12
using System.Linq;
23
using System.Threading.Tasks;
34
using CommunityToolkit.Mvvm.ComponentModel;
5+
using Microsoft.UI.Dispatching;
46
using TinyClips.Core.Models;
57
using TinyClips.Core.Services;
68

@@ -25,7 +27,9 @@ public sealed partial class SettingsViewModel : ObservableObject
2527
private readonly ILaunchAtLoginService _launchAtLoginService;
2628
private readonly IAudioDeviceService _audioDevices;
2729
private readonly IClipStorageService _storage;
30+
private readonly DispatcherQueue? _dispatcherQueue;
2831
private bool _loading;
32+
private string _savedMicrophoneId = string.Empty;
2933

3034
// Persistence stays suppressed until the Settings window has finished its first
3135
// layout/binding pass. WinUI TwoWay x:Bind targets (ComboBox.SelectedIndex,
@@ -45,7 +49,9 @@ public SettingsViewModel(ICaptureSettings settings, IHotKeyService hotKeys, ILau
4549
_launchAtLoginService = launchAtLogin;
4650
_audioDevices = audioDevices;
4751
_storage = storage;
52+
_dispatcherQueue = DispatcherQueue.GetForCurrentThread();
4853
Load();
54+
_ = LoadMicrophonesAsync();
4955

5056
// Reconcile the toggle with the OS-owned launch-at-login (StartupTask) state.
5157
_ = RefreshLaunchAtLoginAsync();
@@ -138,14 +144,31 @@ public SettingsViewModel(ICaptureSettings settings, IHotKeyService hotKeys, ILau
138144
private bool _recordAudio;
139145

140146
[ObservableProperty]
147+
[NotifyPropertyChangedFor(nameof(MicrophoneSelectorEnabled))]
141148
private bool _recordMicrophone;
142149

143150
/// <summary>Microphone devices for the picker (first entry is the system default).</summary>
144151
public System.Collections.ObjectModel.ObservableCollection<AudioInputDevice> Microphones { get; } = new();
145152

153+
[ObservableProperty]
154+
[NotifyPropertyChangedFor(nameof(MicrophoneLoadingVisibility))]
155+
[NotifyPropertyChangedFor(nameof(MicrophoneSelectorVisibility))]
156+
[NotifyPropertyChangedFor(nameof(MicrophoneSelectorEnabled))]
157+
private bool _isMicrophonesLoading = true;
158+
146159
[ObservableProperty]
147160
private AudioInputDevice? _selectedMicrophone;
148161

162+
public Microsoft.UI.Xaml.Visibility MicrophoneLoadingVisibility => IsMicrophonesLoading
163+
? Microsoft.UI.Xaml.Visibility.Visible
164+
: Microsoft.UI.Xaml.Visibility.Collapsed;
165+
166+
public Microsoft.UI.Xaml.Visibility MicrophoneSelectorVisibility => IsMicrophonesLoading
167+
? Microsoft.UI.Xaml.Visibility.Collapsed
168+
: Microsoft.UI.Xaml.Visibility.Visible;
169+
170+
public bool MicrophoneSelectorEnabled => RecordMicrophone && !IsMicrophonesLoading;
171+
149172
[ObservableProperty]
150173
private double _videoRecordingTimeLimitMinutes;
151174

@@ -303,17 +326,7 @@ private void Load()
303326
RecordAudio = _settings.RecordAudio;
304327
RecordMicrophone = _settings.RecordMicrophone;
305328

306-
var savedMicId = _settings.SelectedMicrophoneId ?? string.Empty;
307-
var microphones = _audioDevices.GetMicrophones();
308-
309-
SelectedMicrophone = null;
310-
Microphones.Clear();
311-
foreach (var mic in microphones)
312-
{
313-
Microphones.Add(mic);
314-
}
315-
316-
SelectedMicrophone = Microphones.FirstOrDefault(m => m.Id == savedMicId) ?? Microphones[0];
329+
_savedMicrophoneId = _settings.SelectedMicrophoneId ?? string.Empty;
317330

318331
VideoRecordingTimeLimitMinutes = _settings.VideoRecordingTimeLimitMinutes;
319332
VideoCountdownEnabled = _settings.VideoCountdownEnabled;
@@ -343,6 +356,70 @@ private void Load()
343356
}
344357
}
345358

359+
private async Task LoadMicrophonesAsync()
360+
{
361+
IsMicrophonesLoading = true;
362+
var microphones = await Task.Run(() => _audioDevices.GetMicrophones());
363+
await ApplyMicrophonesAsync(microphones);
364+
}
365+
366+
private async Task ApplyMicrophonesAsync(IReadOnlyList<AudioInputDevice> microphones)
367+
{
368+
if (_dispatcherQueue is null || _dispatcherQueue.HasThreadAccess)
369+
{
370+
ApplyMicrophones(microphones);
371+
return;
372+
}
373+
374+
var completion = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
375+
if (!_dispatcherQueue.TryEnqueue(() =>
376+
{
377+
try
378+
{
379+
ApplyMicrophones(microphones);
380+
completion.SetResult(true);
381+
}
382+
catch (Exception ex)
383+
{
384+
completion.SetException(ex);
385+
}
386+
}))
387+
{
388+
throw new InvalidOperationException("Unable to update microphone list on the UI thread.");
389+
}
390+
391+
await completion.Task;
392+
}
393+
394+
private void ApplyMicrophones(IReadOnlyList<AudioInputDevice> microphones)
395+
{
396+
_loading = true;
397+
try
398+
{
399+
SelectedMicrophone = null;
400+
Microphones.Clear();
401+
402+
if (microphones.Count == 0)
403+
{
404+
Microphones.Add(new AudioInputDevice(string.Empty, "System default"));
405+
}
406+
else
407+
{
408+
foreach (var mic in microphones)
409+
{
410+
Microphones.Add(mic);
411+
}
412+
}
413+
414+
SelectedMicrophone = Microphones.FirstOrDefault(m => m.Id == _savedMicrophoneId) ?? Microphones[0];
415+
}
416+
finally
417+
{
418+
_loading = false;
419+
IsMicrophonesLoading = false;
420+
}
421+
}
422+
346423
partial void OnThemeIndexChanged(int value)
347424
{
348425
if (_loading || !_ready)

‎windows/src/TinyClips.App/SettingsWindow.xaml‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,16 +525,31 @@
525525
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
526526
Text="Choose which input is recorded when &quot;Record microphone&quot; is on." />
527527
</StackPanel>
528+
<StackPanel
529+
Grid.Column="1"
530+
MinWidth="220"
531+
Orientation="Horizontal"
532+
Spacing="8"
533+
VerticalAlignment="Center"
534+
Visibility="{x:Bind ViewModel.MicrophoneLoadingVisibility, Mode=OneWay}">
535+
<ProgressRing Width="20" Height="20" IsActive="True" />
536+
<TextBlock
537+
VerticalAlignment="Center"
538+
Style="{StaticResource CaptionTextBlockStyle}"
539+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
540+
Text="Loading microphones..." />
541+
</StackPanel>
528542
<ComboBox
529543
Grid.Column="1"
530544
MinWidth="220"
531545
VerticalAlignment="Center"
532546
AutomationProperties.AutomationId="MicrophoneDeviceCombo"
533547
AutomationProperties.Name="Microphone device"
534548
DisplayMemberPath="Name"
535-
IsEnabled="{x:Bind ViewModel.RecordMicrophone, Mode=OneWay}"
549+
IsEnabled="{x:Bind ViewModel.MicrophoneSelectorEnabled, Mode=OneWay}"
536550
ItemsSource="{x:Bind ViewModel.Microphones, Mode=OneWay}"
537-
SelectedItem="{x:Bind ViewModel.SelectedMicrophone, Mode=TwoWay}" />
551+
SelectedItem="{x:Bind ViewModel.SelectedMicrophone, Mode=TwoWay}"
552+
Visibility="{x:Bind ViewModel.MicrophoneSelectorVisibility, Mode=OneWay}" />
538553
</Grid>
539554
</Border>
540555

0 commit comments

Comments
 (0)