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
This commit is contained in:
Jeremy Wu 2020-03-12 09:57:36 +11:00 committed by GitHub
parent 0f2ebfbe00
commit 37149d9956
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 13 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -25,8 +25,7 @@ namespace Wox.Infrastructure.UserSettings
/// <summary>
/// when false Alphabet static service will always return empty results
/// </summary>
public bool ShouldUsePinyin { get; set; } = true;
public bool ShouldUsePinyin { get; set; } = false;
internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular;

View file

@ -55,7 +55,7 @@
<CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}">
<TextBlock Text="{DynamicResource autoUpdates}" />
</CheckBox>
<CheckBox Margin="10" IsChecked="{Binding Settings.ShouldUsePinyin}">
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}">
<TextBlock Text="{DynamicResource ShouldUsePinyin}" />
</CheckBox>
<StackPanel Margin="10" Orientation="Horizontal">
@ -72,8 +72,8 @@
</StackPanel>
<StackPanel Margin="10" Orientation="Horizontal">
<TextBlock Text="{DynamicResource language}" />
<ComboBox Margin="10 0 0 0" Width="120" SelectionChanged="OnLanguageChanged"
ItemsSource="{Binding Languages}" SelectedValue="{Binding Settings.Language}"
<ComboBox Margin="10 0 0 0" Width="120"
ItemsSource="{Binding Languages}" SelectedValue="{Binding Language}"
DisplayMemberPath="Display" SelectedValuePath="LanguageCode" />
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="10">

View file

@ -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();

View file

@ -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<string> QuerySearchPrecisionStrings
{
get