mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Extract methods for readability
This commit is contained in:
parent
4fb2e3d14e
commit
4b6231ba8b
1 changed files with 19 additions and 14 deletions
|
|
@ -31,12 +31,27 @@ namespace Flow.Launcher.Infrastructure
|
|||
if (e.PropertyName == nameof(Settings.UseDoublePinyin) ||
|
||||
e.PropertyName == nameof(Settings.DoublePinyinSchema))
|
||||
{
|
||||
LoadDoublePinyinTable();
|
||||
_pinyinCache.Clear();
|
||||
Reload();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void Reload()
|
||||
{
|
||||
LoadDoublePinyinTable();
|
||||
_pinyinCache.Clear();
|
||||
}
|
||||
|
||||
private void CreateDoublePinyinTableFromStream(Stream jsonStream)
|
||||
{
|
||||
Dictionary<string, Dictionary<string, string>> table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(jsonStream);
|
||||
if (!table.TryGetValue(_settings.DoublePinyinSchema, out var value))
|
||||
{
|
||||
throw new InvalidOperationException("DoublePinyinSchema is invalid or double pinyin table is broken.");
|
||||
}
|
||||
currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(value);
|
||||
}
|
||||
|
||||
private void LoadDoublePinyinTable()
|
||||
{
|
||||
if (_settings.UseDoublePinyin)
|
||||
|
|
@ -45,12 +60,7 @@ namespace Flow.Launcher.Infrastructure
|
|||
try
|
||||
{
|
||||
using var fs = File.OpenRead(tablePath);
|
||||
Dictionary<string, Dictionary<string, string>> table = JsonSerializer.Deserialize<Dictionary<string, Dictionary<string, string>>>(fs);
|
||||
if (!table.TryGetValue(_settings.DoublePinyinSchema, out var value))
|
||||
{
|
||||
throw new InvalidOperationException("DoublePinyinSchema is invalid.");
|
||||
}
|
||||
currentDoublePinyinTable = new ReadOnlyDictionary<string, string>(value);
|
||||
CreateDoublePinyinTableFromStream(fs);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
|
|
@ -73,7 +83,7 @@ namespace Flow.Launcher.Infrastructure
|
|||
|
||||
public (string translation, TranslationMapping map) Translate(string content)
|
||||
{
|
||||
if (!_settings.ShouldUsePinyin)
|
||||
if (!_settings.ShouldUsePinyin || !WordsHelper.HasChinese(content))
|
||||
return (content, null);
|
||||
|
||||
return _pinyinCache.TryGetValue(content, out var value)
|
||||
|
|
@ -83,11 +93,6 @@ namespace Flow.Launcher.Infrastructure
|
|||
|
||||
private (string translation, TranslationMapping map) BuildCacheFromContent(string content)
|
||||
{
|
||||
if (!WordsHelper.HasChinese(content))
|
||||
{
|
||||
return (content, null);
|
||||
}
|
||||
|
||||
var resultList = WordsHelper.GetPinyinList(content);
|
||||
|
||||
var resultBuilder = new StringBuilder();
|
||||
|
|
|
|||
Loading…
Reference in a new issue