mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
[GPO][AdvPaste]Online AI models GPO (#33045)
* [Advanced Paste] AI gpo * address PR comments * XAML format * Fix showing Enable Paste with AI with module disabled * Rename variable in ViewModel for clarity * Update adml revision * Move policy registry key around * Update src/modules/AdvancedPaste/AdvancedPaste/Strings/en-us/Resources.resw Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com> --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com> Co-authored-by: Heiko <61519853+htcfreek@users.noreply.github.com>
This commit is contained in:
@@ -32,6 +32,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
private GpoRuleConfigured _enabledGpoRuleConfiguration;
|
||||
private bool _enabledStateIsGPOConfigured;
|
||||
private GpoRuleConfigured _onlineAIModelsGpoRuleConfiguration;
|
||||
private bool _onlineAIModelsDisallowedByGPO;
|
||||
private bool _isEnabled;
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
@@ -80,6 +82,15 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.AdvancedPaste;
|
||||
}
|
||||
|
||||
_onlineAIModelsGpoRuleConfiguration = GPOWrapper.GetAllowedAdvancedPasteOnlineAIModelsValue();
|
||||
if (_onlineAIModelsGpoRuleConfiguration == GpoRuleConfigured.Disabled)
|
||||
{
|
||||
_onlineAIModelsDisallowedByGPO = true;
|
||||
|
||||
// disable AI if it was enabled
|
||||
DisableAI();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEnabled
|
||||
@@ -124,13 +135,23 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
return cred is not null;
|
||||
}
|
||||
|
||||
public bool IsOpenAIEnabled => OpenAIKeyExists();
|
||||
public bool IsOpenAIEnabled => OpenAIKeyExists() && !IsOnlineAIModelsDisallowedByGPO;
|
||||
|
||||
public bool IsEnabledGpoConfigured
|
||||
{
|
||||
get => _enabledStateIsGPOConfigured;
|
||||
}
|
||||
|
||||
public bool IsOnlineAIModelsDisallowedByGPO
|
||||
{
|
||||
get => _onlineAIModelsDisallowedByGPO || _enabledGpoRuleConfiguration == GpoRuleConfigured.Disabled;
|
||||
}
|
||||
|
||||
public bool ShowOnlineAIModelsGpoConfiguredInfoBar
|
||||
{
|
||||
get => _onlineAIModelsDisallowedByGPO && _enabledGpoRuleConfiguration != GpoRuleConfigured.Disabled;
|
||||
}
|
||||
|
||||
private bool IsClipboardHistoryEnabled()
|
||||
{
|
||||
string registryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Clipboard\";
|
||||
@@ -334,18 +355,30 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
internal void DisableAI()
|
||||
{
|
||||
PasswordVault vault = new PasswordVault();
|
||||
PasswordCredential cred = vault.Retrieve("https://platform.openai.com/api-keys", "PowerToys_AdvancedPaste_OpenAIKey");
|
||||
vault.Remove(cred);
|
||||
OnPropertyChanged(nameof(IsOpenAIEnabled));
|
||||
try
|
||||
{
|
||||
PasswordVault vault = new PasswordVault();
|
||||
PasswordCredential cred = vault.Retrieve("https://platform.openai.com/api-keys", "PowerToys_AdvancedPaste_OpenAIKey");
|
||||
vault.Remove(cred);
|
||||
OnPropertyChanged(nameof(IsOpenAIEnabled));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
internal void EnableAI(string password)
|
||||
{
|
||||
PasswordVault vault = new PasswordVault();
|
||||
PasswordCredential cred = new PasswordCredential("https://platform.openai.com/api-keys", "PowerToys_AdvancedPaste_OpenAIKey", password);
|
||||
vault.Add(cred);
|
||||
OnPropertyChanged(nameof(IsOpenAIEnabled));
|
||||
try
|
||||
{
|
||||
PasswordVault vault = new PasswordVault();
|
||||
PasswordCredential cred = new PasswordCredential("https://platform.openai.com/api-keys", "PowerToys_AdvancedPaste_OpenAIKey", password);
|
||||
vault.Add(cred);
|
||||
OnPropertyChanged(nameof(IsOpenAIEnabled));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user