mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-13 20:13:48 +00:00
Fixed global shortcuts on linux (#867)
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
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, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Determine run mode (push) Waiting to run
Build and Release / Read metadata (push) Blocked by required conditions
Build and Release / Sync Flatpak repo (push) Blocked by required conditions
Build and Release / Collect Flatpak artifacts (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis,updater, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg,app,updater, dmg) (push) Blocked by required conditions
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, nsis) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage,updater, appimage) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
This commit is contained in:
1 parent
45701189c8
commit
4cc9d1f9a8
15 files changed
+1139
-258
No files matched your search
@@ -45,7 +45,7 @@ public partial class SettingsPanelApp : SettingsPanelBase
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED ]);
|
||||
this.ApplyFilters([], [ Event.CONFIGURATION_CHANGED, Event.GLOBAL_SHORTCUT_CHANGED ]);
|
||||
await base.OnInitializedAsync();
|
||||
this.updatePolicyMode = this.UpdatePolicy.CurrentMode;
|
||||
}
|
||||
@@ -55,6 +55,9 @@ public partial class SettingsPanelApp : SettingsPanelBase
|
||||
if (triggeredEvent is Event.CONFIGURATION_CHANGED)
|
||||
this.updatePolicyMode = this.UpdatePolicy.CurrentMode;
|
||||
|
||||
if (triggeredEvent is Event.GLOBAL_SHORTCUT_CHANGED)
|
||||
this.StateHasChanged();
|
||||
|
||||
await base.ProcessIncomingMessage(sendingComponent, triggeredEvent, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,11 @@ public enum Event
|
||||
/// Notifies receivers that voice recording availability changed.
|
||||
/// </summary>
|
||||
VOICE_RECORDING_AVAILABILITY_CHANGED,
|
||||
|
||||
/// <summary>
|
||||
/// Notifies settings UI receivers that a portal changed the effective global shortcut label.
|
||||
/// </summary>
|
||||
GLOBAL_SHORTCUT_CHANGED,
|
||||
|
||||
// Update events:
|
||||
/// <summary>
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
public sealed record RegisterShortcutRequest(Shortcut Id, string Shortcut);
|
||||
public sealed record RegisterShortcutRequest(Shortcut Id, string Shortcut, string Description, bool Reconfigure);
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
/// <summary>
|
||||
/// Native backend used to register a global shortcut.
|
||||
/// </summary>
|
||||
public enum ShortcutBackend
|
||||
{
|
||||
NONE,
|
||||
PORTAL,
|
||||
TAURI,
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
/// <summary>
|
||||
/// Typed result of a global shortcut registration attempt.
|
||||
/// </summary>
|
||||
public sealed record ShortcutRegistrationResult(
|
||||
bool Success,
|
||||
string ErrorMessage,
|
||||
ShortcutBackend Backend,
|
||||
bool Cancelled,
|
||||
string EffectiveDisplayName)
|
||||
{
|
||||
public static ShortcutRegistrationResult Failed(string errorMessage) =>
|
||||
new(false, errorMessage, ShortcutBackend.NONE, false, string.Empty);
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
namespace AIStudio.Tools.Rust;
|
||||
|
||||
public sealed record ShortcutResponse(bool Success, string ErrorMessage);
|
||||
public sealed record ShortcutResponse(
|
||||
bool Success,
|
||||
string ErrorMessage,
|
||||
ShortcutBackend Backend,
|
||||
bool Cancelled,
|
||||
string EffectiveDisplayName);
|
||||
@@ -29,6 +29,24 @@ public readonly record struct TauriEvent(TauriEventType EventType, List<string>
|
||||
return TryParseSnakeCase(this.Payload[0], out shortcut);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a portal shortcut change and its effective display name.
|
||||
/// </summary>
|
||||
public bool TryGetShortcutChange(out Shortcut shortcut, out string effectiveDisplayName)
|
||||
{
|
||||
shortcut = default;
|
||||
effectiveDisplayName = string.Empty;
|
||||
if (this.EventType != TauriEventType.GLOBAL_SHORTCUT_CHANGED || this.Payload.Count < 2)
|
||||
return false;
|
||||
|
||||
if (!Enum.TryParse(this.Payload[0], ignoreCase: true, out shortcut)
|
||||
&& !TryParseSnakeCase(this.Payload[0], out shortcut))
|
||||
return false;
|
||||
|
||||
effectiveDisplayName = this.Payload[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to parse a snake_case string into a ShortcutName enum value.
|
||||
/// </summary>
|
||||
@@ -42,4 +60,4 @@ public readonly record struct TauriEvent(TauriEventType EventType, List<string>
|
||||
// Try to match against enum names (which are in UPPER_SNAKE_CASE):
|
||||
return Enum.TryParse(upperSnakeCase, ignoreCase: false, out shortcut);
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -17,4 +17,5 @@ public enum TauriEventType
|
||||
FILE_DROP_CANCELED,
|
||||
|
||||
GLOBAL_SHORTCUT_PRESSED,
|
||||
}
|
||||
GLOBAL_SHORTCUT_CHANGED,
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.Rust;
|
||||
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@@ -19,6 +20,8 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
}
|
||||
|
||||
private readonly SemaphoreSlim registrationSemaphore = new(1, 1);
|
||||
private readonly Dictionary<Shortcut, ShortcutState> lastSentStates = [];
|
||||
private readonly Dictionary<Shortcut, string> lastNonEmptyShortcuts = [];
|
||||
private readonly ILogger<GlobalShortcutService> logger;
|
||||
private readonly SettingsManager settingsManager;
|
||||
private readonly MessageBus messageBus;
|
||||
@@ -39,7 +42,7 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
this.voiceRecordingAvailabilityService = voiceRecordingAvailabilityService;
|
||||
|
||||
this.messageBus.RegisterComponent(this);
|
||||
this.ApplyFilters([], [Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED, Event.STARTUP_COMPLETED, Event.VOICE_RECORDING_AVAILABILITY_CHANGED]);
|
||||
this.ApplyFilters([], [Event.CONFIGURATION_CHANGED, Event.PLUGINS_RELOADED, Event.STARTUP_COMPLETED, Event.TAURI_EVENT_RECEIVED, Event.VOICE_RECORDING_AVAILABILITY_CHANGED]);
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -86,6 +89,14 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
|
||||
await this.RegisterAllShortcuts(ShortcutSyncSource.VOICE_RECORDING_AVAILABILITY_CHANGED);
|
||||
break;
|
||||
|
||||
case Event.TAURI_EVENT_RECEIVED:
|
||||
if (data is TauriEvent tauriEvent
|
||||
&& tauriEvent.TryGetShortcutChange(out var shortcutId, out var effectiveDisplayName))
|
||||
{
|
||||
await this.UpdateEffectiveDisplayName(shortcutId, effectiveDisplayName);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,6 +118,7 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
var shortcutState = await this.GetShortcutState(shortcutId, source);
|
||||
var shortcut = shortcutState.Shortcut;
|
||||
var isEnabled = shortcutState.IsEnabled;
|
||||
var requestedState = new ShortcutState(isEnabled ? shortcut : string.Empty, isEnabled, shortcutState.UsesPersistedFallback);
|
||||
this.logger.LogInformation(
|
||||
"Sync shortcut '{ShortcutId}' (source='{Source}', enabled={IsEnabled}, configured='{Shortcut}').",
|
||||
shortcutId,
|
||||
@@ -123,25 +135,53 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
shortcut);
|
||||
}
|
||||
|
||||
if (isEnabled && !string.IsNullOrWhiteSpace(shortcut))
|
||||
if (this.lastSentStates.TryGetValue(shortcutId, out var lastSentState)
|
||||
&& lastSentState.Shortcut == requestedState.Shortcut
|
||||
&& lastSentState.IsEnabled == requestedState.IsEnabled)
|
||||
{
|
||||
var success = await this.rustService.UpdateGlobalShortcut(shortcutId, shortcut);
|
||||
if (success)
|
||||
this.logger.LogInformation("Global shortcut '{ShortcutId}' ({Shortcut}) registered.", shortcutId, shortcut);
|
||||
else
|
||||
this.logger.LogWarning("Failed to register global shortcut '{ShortcutId}' ({Shortcut}).", shortcutId, shortcut);
|
||||
this.logger.LogDebug("Skipping unchanged global shortcut '{ShortcutId}'.", shortcutId);
|
||||
continue;
|
||||
}
|
||||
|
||||
var description = await this.GetShortcutDescription(shortcutId);
|
||||
var reconfigure = !string.IsNullOrWhiteSpace(requestedState.Shortcut)
|
||||
&& this.lastNonEmptyShortcuts.TryGetValue(shortcutId, out var lastNonEmptyShortcut)
|
||||
&& !string.Equals(lastNonEmptyShortcut, requestedState.Shortcut, StringComparison.Ordinal);
|
||||
|
||||
var result = await this.rustService.UpdateGlobalShortcut(shortcutId, requestedState.Shortcut, description, reconfigure);
|
||||
this.lastSentStates[shortcutId] = requestedState;
|
||||
if (!string.IsNullOrWhiteSpace(requestedState.Shortcut))
|
||||
this.lastNonEmptyShortcuts[shortcutId] = requestedState.Shortcut;
|
||||
|
||||
if (result.Success)
|
||||
{
|
||||
this.logger.LogInformation(
|
||||
"Global shortcut '{ShortcutId}' ({Shortcut}) synchronized through {Backend}.",
|
||||
shortcutId,
|
||||
requestedState.Shortcut,
|
||||
result.Backend);
|
||||
|
||||
if (result.Backend is ShortcutBackend.PORTAL)
|
||||
await this.UpdateEffectiveDisplayName(shortcutId, result.EffectiveDisplayName);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.logger.LogInformation(
|
||||
"Disabling global shortcut '{ShortcutId}' (source='{Source}', enabled={IsEnabled}, configured='{Shortcut}').",
|
||||
var userMessage = result.Cancelled
|
||||
? TB("The global shortcut change was cancelled. The previous shortcut remains active.")
|
||||
: TB("The global shortcut could not be registered. The previous shortcut remains active.");
|
||||
|
||||
this.logger.LogWarning(
|
||||
"Failed to synchronize global shortcut '{ShortcutId}' ({Shortcut}, backend={Backend}, cancelled={Cancelled}): {Error}",
|
||||
shortcutId,
|
||||
source,
|
||||
isEnabled,
|
||||
shortcut);
|
||||
requestedState.Shortcut,
|
||||
result.Backend,
|
||||
result.Cancelled,
|
||||
result.ErrorMessage);
|
||||
|
||||
// Disable the shortcut when empty or feature is disabled:
|
||||
await this.rustService.UpdateGlobalShortcut(shortcutId, string.Empty);
|
||||
if (result.Cancelled)
|
||||
await this.messageBus.SendWarning(new(Icons.Material.Filled.Keyboard, userMessage));
|
||||
else
|
||||
await this.messageBus.SendError(new(Icons.Material.Filled.Keyboard, userMessage));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +210,34 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
_ => true,
|
||||
};
|
||||
|
||||
private async Task<string> GetShortcutDescription(Shortcut shortcutId)
|
||||
{
|
||||
var language = await this.settingsManager.GetActiveLanguagePlugin();
|
||||
return shortcutId switch
|
||||
{
|
||||
Shortcut.VOICE_RECORDING_TOGGLE => I18N.I.GetText(language, "Toggle voice recording", typeof(GlobalShortcutService).Namespace, nameof(GlobalShortcutService)),
|
||||
_ => I18N.I.GetText(language, "Global shortcut", typeof(GlobalShortcutService).Namespace, nameof(GlobalShortcutService)),
|
||||
};
|
||||
}
|
||||
|
||||
private async Task UpdateEffectiveDisplayName(Shortcut shortcutId, string effectiveDisplayName)
|
||||
{
|
||||
if (shortcutId is not Shortcut.VOICE_RECORDING_TOGGLE || string.IsNullOrWhiteSpace(effectiveDisplayName))
|
||||
return;
|
||||
|
||||
var configuredShortcut = this.settingsManager.ConfigurationData.App.ShortcutVoiceRecording;
|
||||
if (this.settingsManager.ConfigurationData.App.ShortcutVoiceRecordingDisplayName == effectiveDisplayName
|
||||
&& this.settingsManager.ConfigurationData.App.ShortcutVoiceRecordingDisplaySource == configuredShortcut)
|
||||
return;
|
||||
|
||||
this.settingsManager.ConfigurationData.App.ShortcutVoiceRecordingDisplayName = effectiveDisplayName;
|
||||
this.settingsManager.ConfigurationData.App.ShortcutVoiceRecordingDisplaySource = configuredShortcut;
|
||||
await this.settingsManager.StoreSettings();
|
||||
await this.messageBus.SendMessage<bool>(null, Event.GLOBAL_SHORTCUT_CHANGED);
|
||||
}
|
||||
|
||||
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(GlobalShortcutService).Namespace, nameof(GlobalShortcutService));
|
||||
|
||||
private async Task<ShortcutState> GetShortcutState(Shortcut shortcutId, ShortcutSyncSource source)
|
||||
{
|
||||
var shortcut = this.GetShortcutValue(shortcutId);
|
||||
@@ -194,4 +262,4 @@ public sealed class GlobalShortcutService : BackgroundService, IMessageBusReceiv
|
||||
}
|
||||
|
||||
private readonly record struct ShortcutState(string Shortcut, bool IsEnabled, bool UsesPersistedFallback);
|
||||
}
|
||||
}
|
||||
@@ -10,34 +10,36 @@ public sealed partial class RustService
|
||||
/// </summary>
|
||||
/// <param name="shortcutId">The identifier for the shortcut.</param>
|
||||
/// <param name="shortcut">The shortcut string in Tauri format (e.g., "CmdOrControl+1"). Use empty string to disable.</param>
|
||||
/// <returns>True if the shortcut was registered successfully, false otherwise.</returns>
|
||||
public async Task<bool> UpdateGlobalShortcut(Shortcut shortcutId, string shortcut)
|
||||
/// <param name="description">Localized action description shown by the desktop portal.</param>
|
||||
/// <param name="reconfigure">Whether the user deliberately selected a different preferred trigger.</param>
|
||||
/// <returns>A typed result including the selected backend and effective portal label.</returns>
|
||||
public async Task<ShortcutRegistrationResult> UpdateGlobalShortcut(Shortcut shortcutId, string shortcut, string description, bool reconfigure)
|
||||
{
|
||||
try
|
||||
{
|
||||
var request = new RegisterShortcutRequest(shortcutId, shortcut);
|
||||
var request = new RegisterShortcutRequest(shortcutId, shortcut, description, reconfigure);
|
||||
var response = await this.http.PostAsJsonAsync("/shortcuts/register", request, this.jsonRustSerializerOptions);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
this.logger?.LogError("Failed to register global shortcut '{ShortcutId}' due to network error: {StatusCode}", shortcutId, response.StatusCode);
|
||||
return false;
|
||||
return ShortcutRegistrationResult.Failed(TB("The global shortcut could not be registered because the desktop service is unavailable."));
|
||||
}
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<ShortcutResponse>(this.jsonRustSerializerOptions);
|
||||
var result = await response.Content.ReadFromJsonAsync<ShortcutRegistrationResult>(this.jsonRustSerializerOptions);
|
||||
if (result is null || !result.Success)
|
||||
{
|
||||
this.logger?.LogError("Failed to register global shortcut '{ShortcutId}': {Error}", shortcutId, result?.ErrorMessage ?? "Unknown error");
|
||||
return false;
|
||||
return result ?? ShortcutRegistrationResult.Failed(TB("The desktop service returned an invalid response while registering the global shortcut."));
|
||||
}
|
||||
|
||||
this.logger?.LogInformation("Global shortcut '{ShortcutId}' registered successfully with key '{Shortcut}'.", shortcutId, shortcut);
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.logger?.LogError(ex, "Exception while registering global shortcut '{ShortcutId}'.", shortcutId);
|
||||
return false;
|
||||
return ShortcutRegistrationResult.Failed(TB("The global shortcut could not be registered because of a desktop integration error."));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
- Fixed an issue that could leave AI Studio unresponsive after waking the computer from sleep. Yes, we know this was an annoying bug, and we apologize for the inconvenience.
|
||||
- Fixed connections to internal HTTPS services and enterprise configuration servers that use organization-provided root certificates on Linux.
|
||||
- Fixed enterprise configuration plugins from Windows-created ZIP files may not load correctly on Linux when the ZIP contained plugin files inside a folder.
|
||||
- Fixed the global voice recording shortcut on Linux so it also works outside AI Studio on supported Wayland desktops.
|
||||
- Fixed voice recording and transcription on Linux.
|
||||
- Fixed copied content from AI Studio not remaining available on the clipboard on Linux.
|
||||
- Fixed being able to switch document analysis policies while an analysis or media transcription was still in progress.
|
||||
|
||||
Reference in new issue
Block a user