mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Refactoring proxy, part 2
This commit is contained in:
@@ -3,26 +3,27 @@ using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using Wox.Plugin;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
|
||||
namespace Wox.Infrastructure.Http
|
||||
{
|
||||
public static class Http
|
||||
{
|
||||
public static IWebProxy WebProxy(IHttpProxy proxy)
|
||||
public static HttpProxy Proxy { private get; set; }
|
||||
public static IWebProxy WebProxy()
|
||||
{
|
||||
if (proxy != null && proxy.Enabled && !string.IsNullOrEmpty(proxy.Server))
|
||||
if (Proxy != null && Proxy.Enabled && !string.IsNullOrEmpty(Proxy.Server))
|
||||
{
|
||||
if (string.IsNullOrEmpty(proxy.UserName) || string.IsNullOrEmpty(proxy.Password))
|
||||
if (string.IsNullOrEmpty(Proxy.UserName) || string.IsNullOrEmpty(Proxy.Password))
|
||||
{
|
||||
var webProxy = new WebProxy(proxy.Server, proxy.Port);
|
||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port);
|
||||
return webProxy;
|
||||
}
|
||||
else
|
||||
{
|
||||
var webProxy = new WebProxy(proxy.Server, proxy.Port)
|
||||
var webProxy = new WebProxy(Proxy.Server, Proxy.Port)
|
||||
{
|
||||
Credentials = new NetworkCredential(proxy.UserName, proxy.Password)
|
||||
Credentials = new NetworkCredential(Proxy.UserName, Proxy.Password)
|
||||
};
|
||||
return webProxy;
|
||||
}
|
||||
@@ -34,20 +35,20 @@ namespace Wox.Infrastructure.Http
|
||||
}
|
||||
|
||||
/// <exception cref="WebException">Can't download file </exception>
|
||||
public static void Download([NotNull] string url, [NotNull] string filePath, IHttpProxy proxy)
|
||||
public static void Download([NotNull] string url, [NotNull] string filePath)
|
||||
{
|
||||
var client = new WebClient { Proxy = WebProxy(proxy) };
|
||||
var client = new WebClient { Proxy = WebProxy() };
|
||||
client.DownloadFile(url, filePath);
|
||||
}
|
||||
|
||||
/// <exception cref="WebException">Can't get response from http get </exception>
|
||||
public static async Task<string> Get([NotNull] string url, IHttpProxy proxy, string encoding = "UTF-8")
|
||||
public static async Task<string> Get([NotNull] string url, string encoding = "UTF-8")
|
||||
{
|
||||
|
||||
HttpWebRequest request = WebRequest.CreateHttp(url);
|
||||
request.Method = "GET";
|
||||
request.Timeout = 10 * 1000;
|
||||
request.Proxy = WebProxy(proxy);
|
||||
request.Proxy = WebProxy();
|
||||
request.UserAgent = @"Mozilla/5.0 (Trident/7.0; rv:11.0) like Gecko";
|
||||
var response = await request.GetResponseAsync() as HttpWebResponse;
|
||||
if (response != null)
|
||||
|
||||
11
Wox.Infrastructure/UserSettings/HttpProxy.cs
Normal file
11
Wox.Infrastructure/UserSettings/HttpProxy.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class HttpProxy
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
public string Server { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
10
Wox.Infrastructure/UserSettings/PluginHotkey.cs
Normal file
10
Wox.Infrastructure/UserSettings/PluginHotkey.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class CustomPluginHotkey : BaseModel
|
||||
{
|
||||
public string Hotkey { get; set; }
|
||||
public string ActionKeyword { get; set; }
|
||||
}
|
||||
}
|
||||
51
Wox.Infrastructure/UserSettings/PluginSettings.cs
Normal file
51
Wox.Infrastructure/UserSettings/PluginSettings.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class PluginsSettings : BaseModel
|
||||
{
|
||||
public string PythonDirectory { get; set; }
|
||||
public Dictionary<string, Plugin> Plugins { get; set; } = new Dictionary<string, Plugin>();
|
||||
|
||||
public void UpdatePluginSettings(List<PluginMetadata> metadatas)
|
||||
{
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
if (Plugins.ContainsKey(metadata.ID))
|
||||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
if (settings.ActionKeywords?.Count > 0)
|
||||
{
|
||||
metadata.ActionKeywords = settings.ActionKeywords;
|
||||
metadata.ActionKeyword = settings.ActionKeywords[0];
|
||||
}
|
||||
metadata.Disabled = settings.Disabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugins[metadata.ID] = new Plugin
|
||||
{
|
||||
ID = metadata.ID,
|
||||
Name = metadata.Name,
|
||||
ActionKeywords = metadata.ActionKeywords,
|
||||
Disabled = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateActionKeyword(PluginMetadata metadata)
|
||||
{
|
||||
var settings = Plugins[metadata.ID];
|
||||
settings.ActionKeywords = metadata.ActionKeywords;
|
||||
}
|
||||
}
|
||||
public class Plugin
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<string> ActionKeywords { get; set; }
|
||||
public bool Disabled { get; set; }
|
||||
}
|
||||
}
|
||||
61
Wox.Infrastructure/UserSettings/Settings.cs
Normal file
61
Wox.Infrastructure/UserSettings/Settings.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
public class Settings : BaseModel
|
||||
{
|
||||
public string Hotkey { get; set; } = "Alt + Space";
|
||||
public string Language { get; set; } = "en";
|
||||
public string Theme { get; set; } = "Dark";
|
||||
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
|
||||
public string QueryBoxFontStyle { get; set; }
|
||||
public string QueryBoxFontWeight { get; set; }
|
||||
public string QueryBoxFontStretch { get; set; }
|
||||
public string ResultFont { get; set; } = FontFamily.GenericSansSerif.Name;
|
||||
public string ResultFontStyle { get; set; }
|
||||
public string ResultFontWeight { get; set; }
|
||||
public string ResultFontStretch { get; set; }
|
||||
|
||||
public bool AutoUpdates { get; set; } = true;
|
||||
|
||||
public double WindowLeft { get; set; }
|
||||
public double WindowTop { get; set; }
|
||||
public int MaxResultsToShow { get; set; } = 6;
|
||||
public int ActivateTimes { get; set; }
|
||||
|
||||
// Order defaults to 0 or -1, so 1 will let this property appear last
|
||||
[JsonProperty(Order = 1)]
|
||||
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();
|
||||
public ObservableCollection<CustomPluginHotkey> CustomPluginHotkeys { get; set; } = new ObservableCollection<CustomPluginHotkey>();
|
||||
|
||||
[Obsolete]
|
||||
public double Opacity { get; set; } = 1;
|
||||
|
||||
[Obsolete]
|
||||
public OpacityMode OpacityMode { get; set; } = OpacityMode.Normal;
|
||||
|
||||
public bool DontPromptUpdateMsg { get; set; }
|
||||
public bool EnableUpdateLog { get; set; }
|
||||
|
||||
public bool StartWoxOnSystemStartup { get; set; } = true;
|
||||
public bool HideOnStartup { get; set; }
|
||||
public bool LeaveCmdOpen { get; set; }
|
||||
public bool HideWhenDeactive { get; set; }
|
||||
public bool RememberLastLaunchLocation { get; set; }
|
||||
public bool IgnoreHotkeysOnFullscreen { get; set; }
|
||||
|
||||
public HttpProxy Proxy { get; set; } = new HttpProxy();
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public enum OpacityMode
|
||||
{
|
||||
Normal = 0,
|
||||
LayeredWindow = 1,
|
||||
DWM = 2
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,10 @@
|
||||
<Compile Include="Hotkey\HotkeyModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Alphabet.cs" />
|
||||
<Compile Include="UserSettings\HttpProxy.cs" />
|
||||
<Compile Include="UserSettings\PluginHotkey.cs" />
|
||||
<Compile Include="UserSettings\PluginSettings.cs" />
|
||||
<Compile Include="UserSettings\Settings.cs" />
|
||||
<Compile Include="Wox.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user