diff --git a/Plugins/Wox.Plugin.ControlPanel/Main.cs b/Plugins/Wox.Plugin.ControlPanel/Main.cs index 4abea83392..14b870da44 100644 --- a/Plugins/Wox.Plugin.ControlPanel/Main.cs +++ b/Plugins/Wox.Plugin.ControlPanel/Main.cs @@ -35,20 +35,6 @@ namespace Wox.Plugin.ControlPanel item.Icon.ToBitmap().Save(iconFolder + item.GUID + fileType); } } - - Task.Run(() => - { - var characters = controlPanelItems.Select(i => i.LocalizedString) - .Concat(controlPanelItems.Select(i => i.InfoTip)); - - Parallel.ForEach(characters, c => - { - if (!string.IsNullOrWhiteSpace(c) && Alphabet.ContainsChinese(c)) - { - Alphabet.PinyinComination(c); - } - }); - }); } public List Query(Query query) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index f36d37e463..6fdcd1b124 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -83,19 +83,6 @@ namespace Wox.Plugin.Program }); Task.WaitAll(t1, t2); - var characters = w.Select(p => p.Name) - .Concat(w.Select(p => p.Description)) - .Concat(u.Select(p => p.DisplayName)) - .Concat(u.Select(p => p.Description)); - - Parallel.ForEach(characters, c => - { - if (!string.IsNullOrWhiteSpace(c) && Alphabet.ContainsChinese(c)) - { - Alphabet.PinyinComination(c); - } - }); - lock (IndexLock) { _win32s = w; diff --git a/Wox.Infrastructure/Alphabet.cs b/Wox.Infrastructure/Alphabet.cs index 896cda979f..8bf71321ca 100644 --- a/Wox.Infrastructure/Alphabet.cs +++ b/Wox.Infrastructure/Alphabet.cs @@ -4,17 +4,32 @@ using System.Collections.Generic; using System.Linq; using hyjiacan.util.p4n; using hyjiacan.util.p4n.format; +using Wox.Infrastructure.Logger; +using Wox.Infrastructure.Storage; namespace Wox.Infrastructure { public static class Alphabet { private static readonly HanyuPinyinOutputFormat Format = new HanyuPinyinOutputFormat(); - private static readonly ConcurrentDictionary PinyinCache = new ConcurrentDictionary(); + private static ConcurrentDictionary PinyinCache; + private static BinaryStorage> _pinyinStorage; - static Alphabet() + public static void Initialize() { Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); + + Stopwatch.Normal("|Wox.Infrastructure.Alphabet.Initialize|Preload pinyin cache", () => + { + _pinyinStorage = new BinaryStorage>("Pinyin"); + PinyinCache = _pinyinStorage.TryLoad(new ConcurrentDictionary()); + }); + Log.Info($"|Wox.Infrastructure.Alphabet.Initialize|Number of preload pinyin combination<{PinyinCache.Count}>"); + } + + public static void Save() + { + _pinyinStorage.Save(PinyinCache); } /// @@ -98,5 +113,7 @@ namespace Wox.Infrastructure ).ToArray(); return combination; } + + } } diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index f2e61bd3bf..0bbd90b917 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -53,6 +53,7 @@ namespace Wox PluginManager.InitializePlugins(API); ImageLoader.Initialize(); + Alphabet.Initialize(); Current.MainWindow = window; Current.MainWindow.Title = Infrastructure.Constant.Wox; @@ -136,6 +137,7 @@ namespace Wox PluginManager.Save(); ImageLoader.Save(); + Alphabet.Save(); _disposed = true; }