Skip to content

Commit b52ef23

Browse files
committed
Merge branch 'dev' into ProgramPluginImprovement
2 parents d4b5a19 + 8010179 commit b52ef23

File tree

16 files changed

+178
-224
lines changed

16 files changed

+178
-224
lines changed

Flow.Launcher.Infrastructure/Alphabet.cs

Lines changed: 0 additions & 178 deletions
This file was deleted.

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@
5353
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
5454
<PackageReference Include="NLog.Schema" Version="4.7.0-rc1" />
5555
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.0" />
56-
<PackageReference Include="Pinyin4DotNet" Version="2016.4.23.4" />
5756
<PackageReference Include="System.Drawing.Common" Version="4.7.0" />
5857
<PackageReference Include="System.Runtime" Version="4.3.1" />
5958
<PackageReference Include="PropertyChanged.Fody" Version="2.5.13" />
59+
<PackageReference Include="ToolGood.Words.Pinyin" Version="3.0.1.4" />
6060
</ItemGroup>
6161

6262
<ItemGroup>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using JetBrains.Annotations;
7+
using Flow.Launcher.Infrastructure.Logger;
8+
using Flow.Launcher.Infrastructure.Storage;
9+
using Flow.Launcher.Infrastructure.UserSettings;
10+
using ToolGood.Words.Pinyin;
11+
using System.Threading.Tasks;
12+
13+
namespace Flow.Launcher.Infrastructure
14+
{
15+
public interface IAlphabet
16+
{
17+
string Translate(string stringToTranslate);
18+
}
19+
20+
public class PinyinAlphabet : IAlphabet
21+
{
22+
private ConcurrentDictionary<string, string> _pinyinCache = new ConcurrentDictionary<string, string>();
23+
private Settings _settings;
24+
25+
public void Initialize([NotNull] Settings settings)
26+
{
27+
_settings = settings ?? throw new ArgumentNullException(nameof(settings));
28+
}
29+
30+
31+
public string Translate(string content)
32+
{
33+
if (_settings.ShouldUsePinyin)
34+
{
35+
if (!_pinyinCache.ContainsKey(content))
36+
{
37+
if (WordsHelper.HasChinese(content))
38+
{
39+
var result = WordsHelper.GetPinyin(content, ";");
40+
result = GetFirstPinyinChar(result) + result.Replace(";", "");
41+
_pinyinCache[content] = result;
42+
return result;
43+
}
44+
else
45+
{
46+
return content;
47+
}
48+
}
49+
else
50+
{
51+
return _pinyinCache[content];
52+
}
53+
}
54+
else
55+
{
56+
return content;
57+
}
58+
}
59+
60+
private string GetFirstPinyinChar(string content)
61+
{
62+
return string.Concat(content.Split(';').Select(x => x.First()));
63+
}
64+
}
65+
}

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public partial class App : IDisposable, ISingleInstanceApp
2929
private SettingWindowViewModel _settingsVM;
3030
private readonly Updater _updater = new Updater(Flow.Launcher.Properties.Settings.Default.GithubRepo);
3131
private readonly Portable _portable = new Portable();
32-
private readonly Alphabet _alphabet = new Alphabet();
32+
private readonly PinyinAlphabet _alphabet = new PinyinAlphabet();
3333
private StringMatcher _stringMatcher;
3434

3535
[STAThread]

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public class PublicAPIInstance : IPublicAPI
2121
{
2222
private readonly SettingWindowViewModel _settingsVM;
2323
private readonly MainViewModel _mainVM;
24-
private readonly Alphabet _alphabet;
24+
private readonly PinyinAlphabet _alphabet;
2525

2626
#region Constructor
2727

28-
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, Alphabet alphabet)
28+
public PublicAPIInstance(SettingWindowViewModel settingsVM, MainViewModel mainVM, PinyinAlphabet alphabet)
2929
{
3030
_settingsVM = settingsVM;
3131
_mainVM = mainVM;
@@ -76,7 +76,6 @@ public void SaveAppAllSettings()
7676
_settingsVM.Save();
7777
PluginManager.Save();
7878
ImageLoader.Save();
79-
_alphabet.Save();
8079
}
8180

8281
public void ReloadAllPluginData()

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Bookmark.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ public string Name
1919
set
2020
{
2121
m_Name = value;
22-
PinyinName = m_Name.Unidecode();
2322
}
2423
}
25-
public string PinyinName { get; private set; }
2624
public string Url { get; set; }
2725
public string Source { get; set; }
2826
public int Score { get; set; }

Plugins/Flow.Launcher.Plugin.BrowserBookmark/Commands/Bookmarks.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ namespace Flow.Launcher.Plugin.BrowserBookmark.Commands
66
{
77
internal static class Bookmarks
88
{
9-
internal static bool MatchProgram(Bookmark bookmark, string queryString)
9+
internal static MatchResult MatchProgram(Bookmark bookmark, string queryString)
1010
{
11-
if (StringMatcher.FuzzySearch(queryString, bookmark.Name).IsSearchPrecisionScoreMet()) return true;
12-
if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName).IsSearchPrecisionScoreMet()) return true;
13-
if (StringMatcher.FuzzySearch(queryString, bookmark.Url).IsSearchPrecisionScoreMet()) return true;
11+
var match = StringMatcher.FuzzySearch(queryString, bookmark.Name);
12+
if (match.IsSearchPrecisionScoreMet())
13+
return match;
1414

15-
return false;
15+
return StringMatcher.FuzzySearch(queryString, bookmark.Url);
1616
}
1717

1818
internal static List<Bookmark> LoadAllBookmarks()
1919
{
2020
var allbookmarks = new List<Bookmark>();
21-
21+
2222
var chromeBookmarks = new ChromeBookmarks();
2323
var mozBookmarks = new FirefoxBookmarks();
2424
var edgeBookmarks = new EdgeBookmarks();

Plugins/Flow.Launcher.Plugin.BrowserBookmark/EdgeBookmarks.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public List<Bookmark> GetBookmarks()
1818
return bookmarks;
1919
}
2020

21-
private void ParseEdgeBookmarks(String path, string source)
21+
private void ParseEdgeBookmarks(string path, string source)
2222
{
2323
if (!File.Exists(path)) return;
2424

@@ -72,12 +72,13 @@ private void LoadEdgeBookmarks(string path, string name)
7272

7373
private void LoadEdgeBookmarks()
7474
{
75-
String platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
75+
string platformPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
7676
LoadEdgeBookmarks(Path.Combine(platformPath, @"Microsoft\Edge\User Data"), "Microsoft Edge");
77+
LoadEdgeBookmarks(Path.Combine(platformPath, @"Microsoft\Edge Dev\User Data"), "Microsoft Edge Dev");
7778
LoadEdgeBookmarks(Path.Combine(platformPath, @"Microsoft\Edge SxS\User Data"), "Microsoft Edge Canary");
7879
}
7980

80-
private String DecodeUnicode(String dataStr)
81+
private string DecodeUnicode(string dataStr)
8182
{
8283
Regex reg = new Regex(@"(?i)\\[uU]([0-9a-f]{4})");
8384
return reg.Replace(dataStr, m => ((char)Convert.ToInt32(m.Groups[1].Value, 16)).ToString());

0 commit comments

Comments
 (0)