Merge branch 'enable_manual_reloaddata' into dev

This commit is contained in:
Jeremy Wu
2019-10-06 14:16:19 +11:00
10 changed files with 105 additions and 24 deletions

View File

@@ -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<Bookmark> LoadAllBookmarks()
{
var allbookmarks = new List<Bookmark>();
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();
}
}
}

View File

@@ -1,32 +1,21 @@
using System.Collections.Generic;
using System.Linq;
using Wox.Infrastructure;
using Wox.Plugin.BrowserBookmark.Commands;
using Wox.Plugin.SharedCommands;
namespace Wox.Plugin.BrowserBookmark
{
public class Main : IPlugin
public class Main : IPlugin, IReloadable
{
private PluginInitContext context;
// TODO: periodically refresh the Cache?
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
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<Result> 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();
}
@@ -60,13 +49,11 @@ namespace Wox.Plugin.BrowserBookmark
}).ToList();
}
private bool MatchProgram(Bookmark bookmark, string queryString)
public void ReloadData()
{
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;
cachedBookmarks.Clear();
return false;
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
}
}

View File

@@ -66,6 +66,7 @@
<ItemGroup>
<Compile Include="Bookmark.cs" />
<Compile Include="ChromeBookmarks.cs" />
<Compile Include="Commands\Bookmarks.cs" />
<Compile Include="FirefoxBookmarks.cs" />
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@@ -13,7 +13,7 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
namespace Wox.Plugin.Program
{
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable
{
private static readonly object IndexLock = new object();
private static Win32[] _win32s;
@@ -145,5 +145,13 @@ namespace Wox.Plugin.Program
}
return hide;
}
public void ReloadData()
{
Task.Run(() =>
{
IndexPrograms();
});
}
}
}

View File

@@ -207,6 +207,17 @@ namespace Wox.Plugin.Sys
context.API.OpenSettingDialog();
return true;
}
},
new Result
{
Title = "Reload Plugin Data",
SubTitle = "Reloads plugin data with new content added after Wox started. Plugins need to have this feature already added.",
IcoPath = "Images\\app.png",
Action = c =>
{
context.API.ReloadAllPluginData();
return true;
}
}
});
return results;