From 37149d99563e559ef1bfdbb86658fedd327f1b24 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Thu, 12 Mar 2020 09:57:36 +1100 Subject: [PATCH] Reduce Wox's drain on CPU when using Pinyin search (#162) * Remove this unneccessary dreadful logging that kills performance * Update to ShouldUsePinyin option 1. Change default start up not to use Pinyin as default language is English 2. Add prompt when switching to Chinese or Chinese_TW prompt user if they want to use Pinyin search --- Wox.Core/Resource/Internationalization.cs | 16 ++++++++++++ Wox.Infrastructure/Alphabet.cs | 2 +- Wox.Infrastructure/UserSettings/Settings.cs | 3 +-- Wox/SettingWindow.xaml | 6 ++--- Wox/SettingWindow.xaml.cs | 6 ----- Wox/ViewModel/SettingWindowViewModel.cs | 29 ++++++++++++++++++++- 6 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Wox.Core/Resource/Internationalization.cs b/Wox.Core/Resource/Internationalization.cs index 9f865cb53..53cce9174 100644 --- a/Wox.Core/Resource/Internationalization.cs +++ b/Wox.Core/Resource/Internationalization.cs @@ -99,6 +99,22 @@ namespace Wox.Core.Resource } + public bool PromptShouldUsePinyin(string languageCodeToSet) + { + var languageToSet = GetLanguageByLanguageCode(languageCodeToSet); + + if (Settings.ShouldUsePinyin) + return false; + + if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW) + return false; + + if (MessageBox.Show("Do you want to turn on search with Pinyin?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No) + return false; + + return true; + } + private void RemoveOldLanguageFiles() { var dicts = Application.Current.Resources.MergedDictionaries; diff --git a/Wox.Infrastructure/Alphabet.cs b/Wox.Infrastructure/Alphabet.cs index 487c0a4b0..4754394cb 100644 --- a/Wox.Infrastructure/Alphabet.cs +++ b/Wox.Infrastructure/Alphabet.cs @@ -162,7 +162,7 @@ namespace Wox.Infrastructure if (word.Length > 40) { - Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {word}"); + //Skip strings that are too long string for Pinyin conversion. return false; } diff --git a/Wox.Infrastructure/UserSettings/Settings.cs b/Wox.Infrastructure/UserSettings/Settings.cs index 7714768f0..94a1639d6 100644 --- a/Wox.Infrastructure/UserSettings/Settings.cs +++ b/Wox.Infrastructure/UserSettings/Settings.cs @@ -25,8 +25,7 @@ namespace Wox.Infrastructure.UserSettings /// /// when false Alphabet static service will always return empty results /// - public bool ShouldUsePinyin { get; set; } = true; - + public bool ShouldUsePinyin { get; set; } = false; internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular; diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 1eddd8ab6..7fe6d8750 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -55,7 +55,7 @@ - + @@ -72,8 +72,8 @@ - diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 52addf362..df3b363d5 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -40,12 +40,6 @@ namespace Wox #region General - void OnLanguageChanged(object sender, SelectionChangedEventArgs e) - { - var language = (Language)e.AddedItems[0]; - InternationalizationManager.Instance.ChangeLanguage(language); - } - private void OnAutoStartupChecked(object sender, RoutedEventArgs e) { SetStartup(); diff --git a/Wox/ViewModel/SettingWindowViewModel.cs b/Wox/ViewModel/SettingWindowViewModel.cs index 504e7bdfa..f9160df9f 100644 --- a/Wox/ViewModel/SettingWindowViewModel.cs +++ b/Wox/ViewModel/SettingWindowViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -77,6 +77,33 @@ namespace Wox.ViewModel } } + public string Language + { + get + { + return Settings.Language; + } + set + { + InternationalizationManager.Instance.ChangeLanguage(value); + + if (InternationalizationManager.Instance.PromptShouldUsePinyin(value)) + ShouldUsePinyin = true; + } + } + + public bool ShouldUsePinyin + { + get + { + return Settings.ShouldUsePinyin; + } + set + { + Settings.ShouldUsePinyin = value; + } + } + public List QuerySearchPrecisionStrings { get