mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Use variable instead of global static method
1. introduce variable 2. part of #389 3. refactoring program suffix in program plugin 4. 全局变量一时爽,代码重构火葬场
This commit is contained in:
@@ -72,12 +72,14 @@ namespace Wox.Core.Plugin
|
||||
AllPlugins = (new CSharpPluginLoader().LoadPlugin(metadatas)).
|
||||
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas));
|
||||
|
||||
//load plugin i18n languages
|
||||
ResourceMerger.UpdatePluginLanguages();
|
||||
|
||||
}
|
||||
|
||||
public static void InitializePlugins(IPublicAPI api)
|
||||
{
|
||||
//load plugin i18n languages
|
||||
ResourceMerger.UpdatePluginLanguages();
|
||||
|
||||
API = api;
|
||||
foreach (PluginPair pluginPair in AllPlugins)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
public class Internationalization : Resource
|
||||
{
|
||||
public UserSettingStorage Settings { get; set; }
|
||||
|
||||
public Internationalization()
|
||||
{
|
||||
DirectoryName = "Languages";
|
||||
@@ -64,8 +66,8 @@ namespace Wox.Core.Resource
|
||||
}
|
||||
}
|
||||
|
||||
UserSettingStorage.Instance.Language = language.LanguageCode;
|
||||
UserSettingStorage.Instance.Save();
|
||||
Settings.Language = language.LanguageCode;
|
||||
Settings.Save();
|
||||
ResourceMerger.UpdateResource(this);
|
||||
}
|
||||
|
||||
@@ -137,7 +139,7 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
if (!Directory.Exists(folder)) return string.Empty;
|
||||
|
||||
string path = Path.Combine(folder, UserSettingStorage.Instance.Language + ".xaml");
|
||||
string path = Path.Combine(folder, Settings.Language + ".xaml");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
return path;
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace Wox.Core.Resource
|
||||
public class Theme : Resource
|
||||
{
|
||||
private static List<string> themeDirectories = new List<string>();
|
||||
public UserSettingStorage Settings { get; set; }
|
||||
|
||||
public Theme()
|
||||
{
|
||||
@@ -53,8 +54,8 @@ namespace Wox.Core.Resource
|
||||
}
|
||||
}
|
||||
|
||||
UserSettingStorage.Instance.Theme = themeName;
|
||||
UserSettingStorage.Instance.Save();
|
||||
Settings.Theme = themeName;
|
||||
Settings.Save();
|
||||
ResourceMerger.UpdateResource(this);
|
||||
|
||||
// Exception of FindResource can't be cathed if global exception handle is set
|
||||
@@ -69,16 +70,16 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
var dict = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri(GetThemePath(UserSettingStorage.Instance.Theme), UriKind.Absolute)
|
||||
Source = new Uri(GetThemePath(Settings.Theme), UriKind.Absolute)
|
||||
};
|
||||
|
||||
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
||||
if (queryBoxStyle != null)
|
||||
{
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight)));
|
||||
queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch)));
|
||||
}
|
||||
|
||||
Style resultItemStyle = dict["ItemTitleStyle"] as Style;
|
||||
@@ -87,10 +88,10 @@ namespace Wox.Core.Resource
|
||||
Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style;
|
||||
if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null)
|
||||
{
|
||||
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultFont));
|
||||
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultFontStyle));
|
||||
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultFontWeight));
|
||||
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultFontStretch));
|
||||
Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont));
|
||||
Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultFontStyle));
|
||||
Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultFontWeight));
|
||||
Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch));
|
||||
|
||||
Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
|
||||
Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
private static Theme instance;
|
||||
private static object syncObject = new object();
|
||||
|
||||
public static Theme Theme
|
||||
public static Theme Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Wox.Core.Updater
|
||||
private const string UpdateFeedURL = "http://upgrade.getwox.com/update.xml";
|
||||
//private const string UpdateFeedURL = "http://127.0.0.1:8888/update.xml";
|
||||
private static SemanticVersion currentVersion;
|
||||
private UserSettingStorage _settings;
|
||||
|
||||
public event EventHandler PrepareUpdateReady;
|
||||
public event EventHandler UpdateError;
|
||||
@@ -43,6 +44,7 @@ namespace Wox.Core.Updater
|
||||
private UpdaterManager()
|
||||
{
|
||||
UpdateManager.Instance.UpdateSource = GetUpdateSource();
|
||||
_settings = UserSettingStorage.Instance;
|
||||
}
|
||||
|
||||
public SemanticVersion CurrentVersion
|
||||
@@ -87,7 +89,7 @@ namespace Wox.Core.Updater
|
||||
try
|
||||
{
|
||||
NewRelease = JsonConvert.DeserializeObject<Release>(json);
|
||||
if (IsNewerThanCurrent(NewRelease) && !UserSettingStorage.Instance.DontPromptUpdateMsg)
|
||||
if (IsNewerThanCurrent(NewRelease) && !_settings.DontPromptUpdateMsg)
|
||||
{
|
||||
StartUpdate();
|
||||
}
|
||||
@@ -146,7 +148,7 @@ namespace Wox.Core.Updater
|
||||
// get out of the way so the console window isn't obstructed
|
||||
try
|
||||
{
|
||||
UpdateManager.Instance.ApplyUpdates(true, UserSettingStorage.Instance.EnableUpdateLog, false);
|
||||
UpdateManager.Instance.ApplyUpdates(true, _settings.EnableUpdateLog, false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -5,39 +5,13 @@ namespace Wox.Core.UserSettings
|
||||
public class HttpProxy : IHttpProxy
|
||||
{
|
||||
private static readonly HttpProxy instance = new HttpProxy();
|
||||
public UserSettingStorage Settings { get; set; }
|
||||
public static HttpProxy Instance => instance;
|
||||
|
||||
private HttpProxy()
|
||||
{
|
||||
}
|
||||
|
||||
public static HttpProxy Instance
|
||||
{
|
||||
get { return instance; }
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return UserSettingStorage.Instance.ProxyEnabled; }
|
||||
}
|
||||
|
||||
public string Server
|
||||
{
|
||||
get { return UserSettingStorage.Instance.ProxyServer; }
|
||||
}
|
||||
|
||||
public int Port
|
||||
{
|
||||
get { return UserSettingStorage.Instance.ProxyPort; }
|
||||
}
|
||||
|
||||
public string UserName
|
||||
{
|
||||
get { return UserSettingStorage.Instance.ProxyUserName; }
|
||||
}
|
||||
|
||||
public string Password
|
||||
{
|
||||
get { return UserSettingStorage.Instance.ProxyPassword; }
|
||||
}
|
||||
public bool Enabled => Settings.ProxyEnabled;
|
||||
public string Server => Settings.ProxyServer;
|
||||
public int Port => Settings.ProxyPort;
|
||||
public string UserName => Settings.ProxyUserName;
|
||||
public string Password => Settings.ProxyPassword;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user