Harden voice recording initialization (#698)
Build and Release / Read metadata (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Has been cancelled
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Has been cancelled
Build and Release / Prepare & create release (push) Has been cancelled
Build and Release / Publish release (push) Has been cancelled

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-03-16 22:36:51 +01:00
1 parent 56da27372c
commit dac0b74145
13 files changed
+242 -69

No files matched your search

@@ -0,0 +1,8 @@
namespace AIStudio.Tools;
public sealed class AudioRecordingResult
{
public string MimeType { get; init; } = string.Empty;
public bool ChangedMimeType { get; init; }
}
+1
View File
@@ -17,6 +17,7 @@ public enum Event
SHOW_SUCCESS,
TAURI_EVENT_RECEIVED,
RUST_SERVICE_UNAVAILABLE,
VOICE_RECORDING_AVAILABILITY_CHANGED,
// Update events:
USER_SEARCH_FOR_UPDATE,
@@ -15,6 +15,7 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
CONFIGURATION_CHANGED,
STARTUP_COMPLETED,
PLUGINS_RELOADED,
VOICE_RECORDING_AVAILABILITY_CHANGED,
}
private readonly SemaphoreSlim registrationSemaphore = new(1, 1);
@@ -22,20 +23,23 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
private readonly SettingsManager settingsManager;
private readonly MessageBus messageBus;
private readonly RustService rustService;
private readonly VoiceRecordingAvailabilityService voiceRecordingAvailabilityService;
public GlobalShortcutService(
ILogger<GlobalShortcutService> logger,
SettingsManager settingsManager,
MessageBus messageBus,
RustService rustService)
RustService rustService,
VoiceRecordingAvailabilityService voiceRecordingAvailabilityService)
{
this.logger = logger;
this.settingsManager = settingsManager;
this.messageBus = messageBus;
this.rustService = rustService;
this.voiceRecordingAvailabilityService = voiceRecordingAvailabilityService;
this.messageBus.RegisterComponent(this);
this.ApplyFilters([], [Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED, Event.STARTUP_COMPLETED]);
this.ApplyFilters([], [Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED, Event.STARTUP_COMPLETED, Event.VOICE_RECORDING_AVAILABILITY_CHANGED]);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -75,6 +79,13 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
await this.RegisterAllShortcuts(ShortcutSyncSource.PLUGINS_RELOADED);
break;
case Event.VOICE_RECORDING_AVAILABILITY_CHANGED:
if (!IS_STARTUP_COMPLETED)
return;
await this.RegisterAllShortcuts(ShortcutSyncSource.VOICE_RECORDING_AVAILABILITY_CHANGED);
break;
}
}
@@ -152,8 +163,9 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
private bool IsShortcutAllowed(Shortcut name) => name switch
{
// Voice recording is a preview feature:
Shortcut.VOICE_RECORDING_TOGGLE => PreviewFeatures.PRE_SPEECH_TO_TEXT_2026.IsEnabled(this.settingsManager),
Shortcut.VOICE_RECORDING_TOGGLE => PreviewFeatures.PRE_SPEECH_TO_TEXT_2026.IsEnabled(this.settingsManager)
&& this.voiceRecordingAvailabilityService.IsAvailable,
// Other shortcuts are always allowed:
_ => true,
};
@@ -0,0 +1,23 @@
namespace AIStudio.Tools.Services;
public sealed class VoiceRecordingAvailabilityService
{
private readonly Lock stateLock = new();
public bool IsAvailable { get; private set; } = true;
public string? DisableReason { get; private set; }
public bool TryDisable(string reason)
{
lock (this.stateLock)
{
if (!this.IsAvailable)
return false;
this.IsAvailable = false;
this.DisableReason = reason;
return true;
}
}
}
@@ -0,0 +1,10 @@
namespace AIStudio.Tools;
public sealed class SoundEffectsInitializationResult
{
public bool Success { get; init; }
public string[] FailedPaths { get; init; } = [];
public string? ErrorMessage { get; init; }
}