diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs b/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs new file mode 100644 index 0000000000..778e0ee65b --- /dev/null +++ b/Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using System.Linq; +using Wox.Infrastructure; + +namespace Wox.Plugin.BrowserBookmark.Commands +{ + internal static class Bookmarks + { + internal static bool MatchProgram(Bookmark bookmark, string queryString) + { + if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true; + if (StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true; + if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true; + + return false; + } + + internal static List LoadAllBookmarks() + { + var allbookmarks = new List(); + + var chromeBookmarks = new ChromeBookmarks(); + var mozBookmarks = new FirefoxBookmarks(); + + //TODO: Let the user select which browser's bookmarks are displayed + // Add Firefox bookmarks + mozBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x)); + + // Add Chrome bookmarks + chromeBookmarks.GetBookmarks().ForEach(x => allbookmarks.Add(x)); + + return allbookmarks.Distinct().ToList(); + } + } +} diff --git a/Plugins/Wox.Plugin.BrowserBookmark/Main.cs b/Plugins/Wox.Plugin.BrowserBookmark/Main.cs index e18eb49530..6ff9624f3d 100644 --- a/Plugins/Wox.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Wox.Plugin.BrowserBookmark/Main.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Linq; -using Wox.Infrastructure; +using Wox.Plugin.BrowserBookmark.Commands; using Wox.Plugin.SharedCommands; namespace Wox.Plugin.BrowserBookmark @@ -8,25 +8,14 @@ namespace Wox.Plugin.BrowserBookmark public class Main : IPlugin { private PluginInitContext context; - - // TODO: periodically refresh the Cache? + private List cachedBookmarks = new List(); public void Init(PluginInitContext context) { this.context = context; - // Cache all bookmarks - var chromeBookmarks = new ChromeBookmarks(); - var mozBookmarks = new FirefoxBookmarks(); - - //TODO: Let the user select which browser's bookmarks are displayed - // Add Firefox bookmarks - cachedBookmarks.AddRange(mozBookmarks.GetBookmarks()); - // Add Chrome bookmarks - cachedBookmarks.AddRange(chromeBookmarks.GetBookmarks()); - - cachedBookmarks = cachedBookmarks.Distinct().ToList(); + cachedBookmarks = Bookmarks.LoadAllBookmarks(); } public List Query(Query query) @@ -41,7 +30,7 @@ namespace Wox.Plugin.BrowserBookmark if (!topResults) { // Since we mixed chrome and firefox bookmarks, we should order them again - returnList = cachedBookmarks.Where(o => MatchProgram(o, param)).ToList(); + returnList = cachedBookmarks.Where(o => Bookmarks.MatchProgram(o, param)).ToList(); returnList = returnList.OrderByDescending(o => o.Score).ToList(); } @@ -59,14 +48,5 @@ namespace Wox.Plugin.BrowserBookmark } }).ToList(); } - - private bool MatchProgram(Bookmark bookmark, string queryString) - { - if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true; - if ( StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true; - if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true; - - return false; - } } }