Skip to content

Commit 37149d9

Browse files
authored
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
1 parent 0f2ebfb commit 37149d9

File tree

6 files changed

+49
-13
lines changed

6 files changed

+49
-13
lines changed

Wox.Core/Resource/Internationalization.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ public void ChangeLanguage(Language language)
9999

100100
}
101101

102+
public bool PromptShouldUsePinyin(string languageCodeToSet)
103+
{
104+
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);
105+
106+
if (Settings.ShouldUsePinyin)
107+
return false;
108+
109+
if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW)
110+
return false;
111+
112+
if (MessageBox.Show("Do you want to turn on search with Pinyin?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
113+
return false;
114+
115+
return true;
116+
}
117+
102118
private void RemoveOldLanguageFiles()
103119
{
104120
var dicts = Application.Current.Resources.MergedDictionaries;

Wox.Infrastructure/Alphabet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public bool ContainsChinese(string word)
162162

163163
if (word.Length > 40)
164164
{
165-
Log.Debug($"|Wox.Infrastructure.StringMatcher.ScoreForPinyin|skip too long string: {word}");
165+
//Skip strings that are too long string for Pinyin conversion.
166166
return false;
167167
}
168168

Wox.Infrastructure/UserSettings/Settings.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class Settings : BaseModel
2525
/// <summary>
2626
/// when false Alphabet static service will always return empty results
2727
/// </summary>
28-
public bool ShouldUsePinyin { get; set; } = true;
29-
28+
public bool ShouldUsePinyin { get; set; } = false;
3029

3130
internal StringMatcher.SearchPrecisionScore QuerySearchPrecision { get; private set; } = StringMatcher.SearchPrecisionScore.Regular;
3231

Wox/SettingWindow.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<CheckBox Margin="10" IsChecked="{Binding Settings.AutoUpdates}">
5656
<TextBlock Text="{DynamicResource autoUpdates}" />
5757
</CheckBox>
58-
<CheckBox Margin="10" IsChecked="{Binding Settings.ShouldUsePinyin}">
58+
<CheckBox Margin="10" IsChecked="{Binding ShouldUsePinyin}">
5959
<TextBlock Text="{DynamicResource ShouldUsePinyin}" />
6060
</CheckBox>
6161
<StackPanel Margin="10" Orientation="Horizontal">
@@ -72,8 +72,8 @@
7272
</StackPanel>
7373
<StackPanel Margin="10" Orientation="Horizontal">
7474
<TextBlock Text="{DynamicResource language}" />
75-
<ComboBox Margin="10 0 0 0" Width="120" SelectionChanged="OnLanguageChanged"
76-
ItemsSource="{Binding Languages}" SelectedValue="{Binding Settings.Language}"
75+
<ComboBox Margin="10 0 0 0" Width="120"
76+
ItemsSource="{Binding Languages}" SelectedValue="{Binding Language}"
7777
DisplayMemberPath="Display" SelectedValuePath="LanguageCode" />
7878
</StackPanel>
7979
<StackPanel Orientation="Horizontal" Margin="10">

Wox/SettingWindow.xaml.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4040

4141
#region General
4242

43-
void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
44-
{
45-
var language = (Language)e.AddedItems[0];
46-
InternationalizationManager.Instance.ChangeLanguage(language);
47-
}
48-
4943
private void OnAutoStartupChecked(object sender, RoutedEventArgs e)
5044
{
5145
SetStartup();

Wox/ViewModel/SettingWindowViewModel.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
@@ -77,6 +77,33 @@ public List<LastQueryMode> LastQueryModes
7777
}
7878
}
7979

80+
public string Language
81+
{
82+
get
83+
{
84+
return Settings.Language;
85+
}
86+
set
87+
{
88+
InternationalizationManager.Instance.ChangeLanguage(value);
89+
90+
if (InternationalizationManager.Instance.PromptShouldUsePinyin(value))
91+
ShouldUsePinyin = true;
92+
}
93+
}
94+
95+
public bool ShouldUsePinyin
96+
{
97+
get
98+
{
99+
return Settings.ShouldUsePinyin;
100+
}
101+
set
102+
{
103+
Settings.ShouldUsePinyin = value;
104+
}
105+
}
106+
80107
public List<string> QuerySearchPrecisionStrings
81108
{
82109
get

0 commit comments

Comments
 (0)