This commit is contained in:
bao-qian 2016-05-09 02:41:46 +01:00
parent 6ac33b0568
commit 08571d51fa

View File

@ -66,6 +66,7 @@ namespace Wox
private async void Setting_Loaded(object sender, RoutedEventArgs ev) private async void Setting_Loaded(object sender, RoutedEventArgs ev)
{ {
#region General #region General
cbHideWhenDeactive.Checked += (o, e) => cbHideWhenDeactive.Checked += (o, e) =>
{ {
_settings.HideWhenDeactive = true; _settings.HideWhenDeactive = true;
@ -143,6 +144,7 @@ namespace Wox
#endregion #endregion
#region About #region About
string activateTimes = string.Format( string activateTimes = string.Format(
InternationalizationManager.Instance.GetTranslation("about_activate_times"), _settings.ActivateTimes); InternationalizationManager.Instance.GetTranslation("about_activate_times"), _settings.ActivateTimes);
ActivatedTimes.Text = activateTimes; ActivatedTimes.Text = activateTimes;
@ -227,7 +229,9 @@ namespace Wox
private void AddApplicationToStartup() private void AddApplicationToStartup()
{ {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) using (
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{ {
key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart"); key.SetValue("Wox", "\"" + Application.ExecutablePath + "\" --hidestart");
} }
@ -235,7 +239,9 @@ namespace Wox
private void RemoveApplicationFromStartup() private void RemoveApplicationFromStartup()
{ {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) using (
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{ {
key.DeleteValue("Wox", false); key.DeleteValue("Wox", false);
} }
@ -243,7 +249,9 @@ namespace Wox
private bool CheckApplicationIsStartupWithWindow() private bool CheckApplicationIsStartupWithWindow()
{ {
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true)) using (
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{ {
return key.GetValue("Wox") != null; return key.GetValue("Wox") != null;
} }
@ -276,6 +284,7 @@ namespace Wox
} }
} }
} }
#endregion #endregion
#region Hotkey #region Hotkey
@ -309,7 +318,8 @@ namespace Wox
} }
catch (Exception) catch (Exception)
{ {
string errorMsg = string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr); string errorMsg =
string.Format(InternationalizationManager.Instance.GetTranslation("registerHotkeyFailed"), hotkeyStr);
MessageBox.Show(errorMsg); MessageBox.Show(errorMsg);
} }
} }
@ -338,8 +348,12 @@ namespace Wox
return; return;
} }
string deleteWarning = string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"), item.Hotkey); string deleteWarning =
if (MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"), MessageBoxButton.YesNo) == MessageBoxResult.Yes) string.Format(InternationalizationManager.Instance.GetTranslation("deleteCustomHotkeyWarning"),
item.Hotkey);
if (
MessageBox.Show(deleteWarning, InternationalizationManager.Instance.GetTranslation("delete"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{ {
_settings.CustomPluginHotkeys.Remove(item); _settings.CustomPluginHotkeys.Remove(item);
lvCustomHotkey.Items.Refresh(); lvCustomHotkey.Items.Refresh();
@ -396,22 +410,26 @@ namespace Wox
{ {
cbQueryBoxFont.Text = _settings.QueryBoxFont; cbQueryBoxFont.Text = _settings.QueryBoxFont;
cbQueryBoxFontFaces.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)cbQueryBoxFont.SelectedItem).ConvertFromInvariantStringsOrNormal( cbQueryBoxFontFaces.SelectedItem =
_settings.QueryBoxFontStyle, SyntaxSugars.CallOrRescueDefault(
_settings.QueryBoxFontWeight, () => ((FontFamily)cbQueryBoxFont.SelectedItem).ConvertFromInvariantStringsOrNormal(
_settings.QueryBoxFontStretch _settings.QueryBoxFontStyle,
)); _settings.QueryBoxFontWeight,
_settings.QueryBoxFontStretch
));
} }
if (!string.IsNullOrEmpty(_settings.ResultFont) && if (!string.IsNullOrEmpty(_settings.ResultFont) &&
Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.ResultFont)) > 0) Fonts.SystemFontFamilies.Count(o => o.FamilyNames.Values.Contains(_settings.ResultFont)) > 0)
{ {
ResultFontComboBox.Text = _settings.ResultFont; ResultFontComboBox.Text = _settings.ResultFont;
ResultFontFacesComboBox.SelectedItem = SyntaxSugars.CallOrRescueDefault(() => ((FontFamily)ResultFontComboBox.SelectedItem).ConvertFromInvariantStringsOrNormal( ResultFontFacesComboBox.SelectedItem =
_settings.ResultFontStyle, SyntaxSugars.CallOrRescueDefault(
_settings.ResultFontWeight, () => ((FontFamily)ResultFontComboBox.SelectedItem).ConvertFromInvariantStringsOrNormal(
_settings.ResultFontStretch _settings.ResultFontStyle,
)); _settings.ResultFontWeight,
_settings.ResultFontStretch
));
} }
ResultListBoxPreview.AddResults(new List<Result> ResultListBoxPreview.AddResults(new List<Result>
@ -532,7 +550,8 @@ namespace Wox
if (!settingsLoaded) return; if (!settingsLoaded) return;
string resultItemFont = ResultFontComboBox.SelectedItem.ToString(); string resultItemFont = ResultFontComboBox.SelectedItem.ToString();
_settings.ResultFont = resultItemFont; _settings.ResultFont = resultItemFont;
ResultFontFacesComboBox.SelectedItem = ((FontFamily)ResultFontComboBox.SelectedItem).ChooseRegularFamilyTypeface(); ResultFontFacesComboBox.SelectedItem =
((FontFamily)ResultFontComboBox.SelectedItem).ChooseRegularFamilyTypeface();
ThemeManager.Instance.ChangeTheme(_settings.Theme); ThemeManager.Instance.ChangeTheme(_settings.Theme);
} }
@ -570,7 +589,8 @@ namespace Wox
pluginInitTime.Text = pluginInitTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime); string.Format(InternationalizationManager.Instance.GetTranslation("plugin_init_time"), pair.InitTime);
pluginQueryTime.Text = pluginQueryTime.Text =
string.Format(InternationalizationManager.Instance.GetTranslation("plugin_query_time"), pair.AvgQueryTime); string.Format(InternationalizationManager.Instance.GetTranslation("plugin_query_time"),
pair.AvgQueryTime);
if (actionKeywords.Count > 1) if (actionKeywords.Count > 1)
{ {
pluginActionKeywordsTitle.Visibility = Visibility.Collapsed; pluginActionKeywordsTitle.Visibility = Visibility.Collapsed;
@ -585,7 +605,8 @@ namespace Wox
pluginTitle.Text = pair.Metadata.Name; pluginTitle.Text = pair.Metadata.Name;
pluginTitle.Cursor = Cursors.Hand; pluginTitle.Cursor = Cursors.Hand;
pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, actionKeywords.ToArray()); pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, actionKeywords.ToArray());
pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " + pair.Metadata.Author; pluginAuthor.Text = InternationalizationManager.Instance.GetTranslation("author") + ": " +
pair.Metadata.Author;
pluginSubTitle.Text = pair.Metadata.Description; pluginSubTitle.Text = pair.Metadata.Description;
pluginId = pair.Metadata.ID; pluginId = pair.Metadata.ID;
pluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath); pluginIcon.Source = ImageLoader.Load(pair.Metadata.IcoPath);
@ -657,7 +678,9 @@ namespace Wox
ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings); ActionKeywords changeKeywordsWindow = new ActionKeywords(id, _settings);
changeKeywordsWindow.ShowDialog(); changeKeywordsWindow.ShowDialog();
PluginPair plugin = PluginManager.GetPluginForId(id); PluginPair plugin = PluginManager.GetPluginForId(id);
if (plugin != null) pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater, pair.Metadata.ActionKeywords.ToArray()); if (plugin != null)
pluginActionKeywords.Text = string.Join(Query.ActionKeywordSeperater,
pair.Metadata.ActionKeywords.ToArray());
} }
} }
} }
@ -677,7 +700,8 @@ namespace Wox
Process.Start(pair.Metadata.Website); Process.Start(pair.Metadata.Website);
} }
catch catch
{ } {
}
} }
} }
} }
@ -698,7 +722,8 @@ namespace Wox
Process.Start(pair.Metadata.PluginDirectory); Process.Start(pair.Metadata.PluginDirectory);
} }
catch catch
{ } {
}
} }
} }
} }
@ -725,6 +750,7 @@ namespace Wox
#endregion #endregion
#region Proxy #region Proxy
private void btnSaveProxy_Click(object sender, RoutedEventArgs e) private void btnSaveProxy_Click(object sender, RoutedEventArgs e)
{ {
_settings.ProxyEnabled = ToggleProxy.IsChecked ?? false; _settings.ProxyEnabled = ToggleProxy.IsChecked ?? false;
@ -827,24 +853,29 @@ namespace Wox
} }
private async void OnCheckUpdates(object sender, RoutedEventArgs e) private async void OnCheckUpdates(object sender, RoutedEventArgs e)
{
var version = await NewVersion();
if (!string.IsNullOrEmpty(version))
{
var newVersion = NumericVersion(version);
var oldVersion = NumericVersion(Infrastructure.Wox.Version);
if (newVersion > oldVersion)
{
NewVersionTips.Text = string.Format(NewVersionTips.Text, version);
NewVersionTips.Visibility = Visibility.Visible;
UpdateApp();
}
}
}
private async void UpdateApp()
{ {
try try
{ {
var version = await NewVersion(); using (var updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github, prerelease: true))
if (!string.IsNullOrEmpty(version))
{ {
var newVersion = NumericVersion(version); // todo 5/9 the return value of UpdateApp() is NULL, fucking useless!
var oldVersion = NumericVersion(Infrastructure.Wox.Version); await updater.UpdateApp();
if (newVersion > oldVersion)
{
NewVersionTips.Text = string.Format(NewVersionTips.Text, version);
NewVersionTips.Visibility = Visibility.Visible;
using (var updater = await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github, prerelease: true))
{
// todo 5/9 the return value of UpdateApp() is NULL, fucking useless!
await updater.UpdateApp();
}
}
} }
} }
catch (Exception ex) catch (Exception ex)
@ -852,7 +883,6 @@ namespace Wox
Log.Error(ex); Log.Error(ex);
} }
} }
private async Task<string> NewVersion() private async Task<string> NewVersion()
{ {
const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest"; const string githubAPI = @"https://api.github.com/repos/wox-launcher/wox/releases/latest";
@ -863,7 +893,7 @@ namespace Wox
JContainer json; JContainer json;
try try
{ {
json = (JContainer) JsonConvert.DeserializeObject(response); json = (JContainer)JsonConvert.DeserializeObject(response);
} }
catch (JsonSerializationException e) catch (JsonSerializationException e)
{ {