2026-01-09 14:49:44 +00:00
using AIStudio.Provider ;
using AIStudio.Settings ;
2025-01-05 14:11:15 +00:00
using AIStudio.Settings.DataModel ;
2026-06-09 18:11:32 +00:00
using AIStudio.Tools.Rust ;
2026-07-13 11:35:24 +00:00
using AIStudio.Tools.Services ;
using Microsoft.AspNetCore.Components ;
2025-01-05 14:11:15 +00:00
namespace AIStudio.Components.Settings ;
public partial class SettingsPanelApp : SettingsPanelBase
{
2026-07-13 11:35:24 +00:00
[Inject]
private UpdatePolicy UpdatePolicy { get ; init ; } = null ! ;
private UpdatePolicyMode updatePolicyMode ;
private UpdateInterval DisplayedUpdateInterval = > this . updatePolicyMode is UpdatePolicyMode . FLATPAK
? UpdateInterval . NO_CHECK
: this . SettingsManager . ConfigurationData . App . UpdateInterval ;
private UpdateInstallation DisplayedUpdateInstallation = > this . updatePolicyMode is UpdatePolicyMode . FLATPAK
? UpdateInstallation . MANUAL
: this . SettingsManager . ConfigurationData . App . UpdateInstallation ;
private string UpdateIntervalHelp = > this . updatePolicyMode switch
{
UpdatePolicyMode . ENTERPRISE_DISABLED = > T ( "Your organization has disabled update checks and installations." ) ,
UpdatePolicyMode . FLATPAK = > T ( "AI Studio cannot check for updates when running as a Flatpak. Updates are managed outside the app." ) ,
_ = > T ( "How often should we check for app updates?" )
} ;
private string UpdateInstallationHelp = > this . updatePolicyMode switch
{
UpdatePolicyMode . ENTERPRISE_DISABLED = > T ( "This setting has no effect while updates are disabled by your organization." ) ,
UpdatePolicyMode . FLATPAK = > T ( "AI Studio cannot install updates when running as a Flatpak. Use the update method provided by your Flatpak distribution." ) ,
_ = > T ( "Should updates be installed automatically or manually?" )
} ;
private bool IsUpdateIntervalLocked ( ) = > this . updatePolicyMode is UpdatePolicyMode . ENTERPRISE_DISABLED or UpdatePolicyMode . FLATPAK | |
ManagedConfiguration . TryGet ( x = > x . App , x = > x . UpdateInterval , out var meta ) & & meta . IsLocked ;
private bool IsUpdateInstallationLocked ( ) = > this . updatePolicyMode is UpdatePolicyMode . ENTERPRISE_DISABLED or UpdatePolicyMode . FLATPAK | |
ManagedConfiguration . TryGet ( x = > x . App , x = > x . UpdateInstallation , out var meta ) & & meta . IsLocked ;
protected override async Task OnInitializedAsync ( )
{
this . ApplyFilters ( [ ] , [ Event . CONFIGURATION_CHANGED ] ) ;
await base . OnInitializedAsync ( ) ;
this . updatePolicyMode = this . UpdatePolicy . CurrentMode ;
}
protected override async Task ProcessIncomingMessage < T > ( ComponentBase ? sendingComponent , Event triggeredEvent , T ? data ) where T : default
{
if ( triggeredEvent is Event . CONFIGURATION_CHANGED )
this . updatePolicyMode = this . UpdatePolicy . CurrentMode ;
await base . ProcessIncomingMessage ( sendingComponent , triggeredEvent , data ) ;
}
2026-06-09 18:11:32 +00:00
private ConfigurationShortcutData VoiceRecordingShortcut = > new ( )
{
Id = Shortcut . VOICE_RECORDING_TOGGLE ,
Value = ( ) = > this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecording ,
ValueUpdate = shortcut = > this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecording = shortcut ,
DisplayName = ( ) = > this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecordingDisplayName ,
DisplaySource = ( ) = > this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecordingDisplaySource ,
DisplayUpdate = this . UpdateShortcutVoiceRecordingDisplay ,
} ;
2026-02-07 21:59:41 +00:00
private async Task GenerateEncryptionSecret ( )
{
var secret = EnterpriseEncryption . GenerateSecret ( ) ;
await this . RustService . CopyText2Clipboard ( this . Snackbar , secret ) ;
}
2026-03-21 17:05:06 +00:00
private string GetStartPageHelpText ( )
{
var helpText = T ( "Choose which page AI Studio should open first when you start the app. Changes take effect the next time you launch AI Studio." ) ;
if ( ! ManagedConfiguration . TryGet ( x = > x . App , x = > x . StartPage , out var meta ) | | meta . ManagedMode is not ManagedConfigurationMode . EDITABLE_DEFAULT )
return helpText ;
return $"{helpText} {T(" Your organization provided a default start page , but you can still change it . ")}" ;
}
2026-02-07 21:59:41 +00:00
2026-01-09 14:49:44 +00:00
private IEnumerable < ConfigurationSelectData < string > > GetFilteredTranscriptionProviders ( )
{
yield return new ( T ( "Disable dictation and transcription" ) , string . Empty ) ;
var minimumLevel = this . SettingsManager . GetMinimumConfidenceLevel ( Tools . Components . APP_SETTINGS ) ;
foreach ( var provider in this . SettingsManager . ConfigurationData . TranscriptionProviders )
{
if ( provider . UsedLLMProvider . GetConfidence ( this . SettingsManager ) . Level > = minimumLevel )
yield return new ( provider . Name , provider . Id ) ;
}
}
2025-01-05 14:11:15 +00:00
private void UpdatePreviewFeatures ( PreviewVisibility previewVisibility )
{
this . SettingsManager . ConfigurationData . App . PreviewVisibility = previewVisibility ;
2026-02-20 11:40:38 +00:00
var filtered = previewVisibility . FilterPreviewFeatures ( this . SettingsManager . ConfigurationData . App . EnabledPreviewFeatures ) ;
filtered . UnionWith ( this . GetPluginContributedPreviewFeatures ( ) ) ;
this . SettingsManager . ConfigurationData . App . EnabledPreviewFeatures = filtered ;
}
private HashSet < PreviewFeatures > GetPluginContributedPreviewFeatures ( )
{
if ( ManagedConfiguration . TryGet ( x = > x . App , x = > x . EnabledPreviewFeatures , out var meta ) & & meta . HasPluginContribution )
return meta . PluginContribution . Where ( x = > ! x . IsReleased ( ) ) . ToHashSet ( ) ;
return [ ] ;
}
private bool IsPluginContributedPreviewFeature ( PreviewFeatures feature )
{
if ( feature . IsReleased ( ) )
return false ;
if ( ! ManagedConfiguration . TryGet ( x = > x . App , x = > x . EnabledPreviewFeatures , out var meta ) | | ! meta . HasPluginContribution )
return false ;
return meta . PluginContribution . Contains ( feature ) ;
}
private HashSet < PreviewFeatures > GetSelectedPreviewFeatures ( )
{
var enabled = this . SettingsManager . ConfigurationData . App . EnabledPreviewFeatures . Where ( x = > ! x . IsReleased ( ) ) . ToHashSet ( ) ;
enabled . UnionWith ( this . GetPluginContributedPreviewFeatures ( ) ) ;
return enabled ;
}
2026-05-31 16:46:54 +00:00
private string GetExternalHttpCustomRootCertificateAllowedHostsText ( )
{
return string . Join ( Environment . NewLine , this . SettingsManager . ConfigurationData . App . ExternalHttpCustomRootCertificateAllowedHosts . Order ( StringComparer . OrdinalIgnoreCase ) ) ;
}
private bool AreExternalHttpCustomRootCertificateDetailsDisabled ( )
{
return ! this . SettingsManager . ConfigurationData . App . ExternalHttpCustomRootCertificatesEnabled ;
}
private void UpdateExternalHttpCustomRootCertificateAllowedHosts ( string updatedText )
{
var patterns = updatedText
. Split ( [ '\r' , '\n' , ';' , ',' ] , StringSplitOptions . RemoveEmptyEntries | StringSplitOptions . TrimEntries )
. Where ( pattern = > ! string . IsNullOrWhiteSpace ( pattern ) )
. ToHashSet ( StringComparer . OrdinalIgnoreCase ) ;
this . SettingsManager . ConfigurationData . App . ExternalHttpCustomRootCertificateAllowedHosts = patterns ;
}
2026-02-20 11:40:38 +00:00
private void UpdateEnabledPreviewFeatures ( HashSet < PreviewFeatures > selectedFeatures )
{
selectedFeatures . UnionWith ( this . GetPluginContributedPreviewFeatures ( ) ) ;
this . SettingsManager . ConfigurationData . App . EnabledPreviewFeatures = selectedFeatures ;
2025-01-05 14:11:15 +00:00
}
2025-05-02 09:50:14 +00:00
2026-06-09 18:11:32 +00:00
private void UpdateShortcutVoiceRecordingDisplay ( string displayName , string displaySource )
{
this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecordingDisplayName = displayName ;
this . SettingsManager . ConfigurationData . App . ShortcutVoiceRecordingDisplaySource = displaySource ;
}
2025-05-02 09:50:14 +00:00
private async Task UpdateLangBehaviour ( LangBehavior behavior )
{
this . SettingsManager . ConfigurationData . App . LanguageBehavior = behavior ;
await this . MessageBus . SendMessage < bool > ( this , Event . PLUGINS_RELOADED ) ;
}
private async Task UpdateManuallySelectedLanguage ( Guid pluginId )
{
this . SettingsManager . ConfigurationData . App . LanguagePluginId = pluginId ;
await this . MessageBus . SendMessage < bool > ( this , Event . PLUGINS_RELOADED ) ;
}
2026-07-13 11:35:24 +00:00
}