mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-25 13:37:22 +01:00
Compare commits
2 Commits
shawn/fixA
...
leilzh/fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2e80f7659 | ||
|
|
e37a328624 |
@@ -312,13 +312,39 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
void read_settings(PowerToysSettings::PowerToyValues& settings)
|
||||
void read_settings(PowerToysSettings::PowerToyValues& settings)
|
||||
{
|
||||
const auto settingsObject = settings.get_raw_json();
|
||||
|
||||
// Migrate Paste As Plain text shortcut
|
||||
Hotkey old_paste_as_plain_hotkey;
|
||||
bool old_data_migrated = migrate_data_and_remove_data_file(old_paste_as_plain_hotkey);
|
||||
|
||||
if (settingsObject.GetView().Size())
|
||||
{
|
||||
const auto propertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES);
|
||||
|
||||
m_is_advanced_ai_enabled = has_advanced_ai_provider(propertiesObject);
|
||||
|
||||
if (propertiesObject.HasKey(JSON_KEY_IS_AI_ENABLED))
|
||||
{
|
||||
m_is_ai_enabled = propertiesObject.GetNamedObject(JSON_KEY_IS_AI_ENABLED).GetNamedBoolean(JSON_KEY_VALUE, false);
|
||||
}
|
||||
else if (propertiesObject.HasKey(JSON_KEY_IS_OPEN_AI_ENABLED))
|
||||
{
|
||||
m_is_ai_enabled = propertiesObject.GetNamedObject(JSON_KEY_IS_OPEN_AI_ENABLED).GetNamedBoolean(JSON_KEY_VALUE, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_is_ai_enabled = false;
|
||||
}
|
||||
|
||||
if (propertiesObject.HasKey(JSON_KEY_SHOW_CUSTOM_PREVIEW))
|
||||
{
|
||||
m_preview_custom_format_output = propertiesObject.GetNamedObject(JSON_KEY_SHOW_CUSTOM_PREVIEW).GetNamedBoolean(JSON_KEY_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
if (old_data_migrated)
|
||||
{
|
||||
m_paste_as_plain_hotkey = old_paste_as_plain_hotkey;
|
||||
@@ -405,31 +431,6 @@ private:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (settingsObject.GetView().Size())
|
||||
{
|
||||
const auto propertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES);
|
||||
|
||||
m_is_advanced_ai_enabled = has_advanced_ai_provider(propertiesObject);
|
||||
|
||||
if (propertiesObject.HasKey(JSON_KEY_IS_AI_ENABLED))
|
||||
{
|
||||
m_is_ai_enabled = propertiesObject.GetNamedObject(JSON_KEY_IS_AI_ENABLED).GetNamedBoolean(JSON_KEY_VALUE, false);
|
||||
}
|
||||
else if (propertiesObject.HasKey(JSON_KEY_IS_OPEN_AI_ENABLED))
|
||||
{
|
||||
m_is_ai_enabled = propertiesObject.GetNamedObject(JSON_KEY_IS_OPEN_AI_ENABLED).GetNamedBoolean(JSON_KEY_VALUE, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_is_ai_enabled = false;
|
||||
}
|
||||
|
||||
if (propertiesObject.HasKey(JSON_KEY_SHOW_CUSTOM_PREVIEW))
|
||||
{
|
||||
m_preview_custom_format_output = propertiesObject.GetNamedObject(JSON_KEY_SHOW_CUSTOM_PREVIEW).GetNamedBoolean(JSON_KEY_VALUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the settings file.
|
||||
|
||||
@@ -314,10 +314,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
string selectedType = draft.ServiceType ?? string.Empty;
|
||||
AIServiceType serviceKind = draft.ServiceTypeKind;
|
||||
|
||||
bool requiresEndpoint = serviceKind is AIServiceType.AzureOpenAI
|
||||
or AIServiceType.AzureAIInference
|
||||
or AIServiceType.Mistral
|
||||
or AIServiceType.Ollama;
|
||||
bool requiresEndpoint = RequiresEndpointForService(serviceKind);
|
||||
bool requiresDeployment = serviceKind == AIServiceType.AzureOpenAI;
|
||||
bool requiresApiVersion = serviceKind == AIServiceType.AzureOpenAI;
|
||||
bool requiresModelPath = serviceKind == AIServiceType.Onnx;
|
||||
@@ -788,12 +785,17 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
string serviceType = draft.ServiceType ?? "OpenAI";
|
||||
string apiKey = PasteAIApiKeyPasswordBox.Password;
|
||||
string trimmedApiKey = apiKey?.Trim() ?? string.Empty;
|
||||
var serviceKind = draft.ServiceTypeKind;
|
||||
bool requiresEndpoint = RequiresEndpointForService(serviceKind);
|
||||
string endpoint = (draft.EndpointUrl ?? string.Empty).Trim();
|
||||
if (endpoint == string.Empty)
|
||||
|
||||
// Never persist placeholder text or stale values for services that don't use an endpoint.
|
||||
if (!requiresEndpoint)
|
||||
{
|
||||
endpoint = GetEndpointPlaceholder(draft.ServiceTypeKind);
|
||||
endpoint = string.Empty;
|
||||
}
|
||||
|
||||
// For endpoint-based services, keep empty if the user didn't provide a value.
|
||||
if (RequiresApiKeyForService(serviceType) && string.IsNullOrWhiteSpace(trimmedApiKey))
|
||||
{
|
||||
args.Cancel = true;
|
||||
@@ -833,6 +835,14 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
};
|
||||
}
|
||||
|
||||
private static bool RequiresEndpointForService(AIServiceType serviceKind)
|
||||
{
|
||||
return serviceKind is AIServiceType.AzureOpenAI
|
||||
or AIServiceType.AzureAIInference
|
||||
or AIServiceType.Mistral
|
||||
or AIServiceType.Ollama;
|
||||
}
|
||||
|
||||
private static string GetEndpointPlaceholder(AIServiceType serviceKind)
|
||||
{
|
||||
return serviceKind switch
|
||||
@@ -841,7 +851,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
AIServiceType.AzureAIInference => "https://{resource-name}.cognitiveservices.azure.com/",
|
||||
AIServiceType.Mistral => "https://api.mistral.ai/v1/",
|
||||
AIServiceType.Ollama => "http://localhost:11434/",
|
||||
_ => "https://your-resource.openai.azure.com/",
|
||||
_ => string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user