mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Merge branch 'enable_manual_reloaddata' into dev
This commit is contained in:
35
Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs
Normal file
35
Plugins/Wox.Plugin.BrowserBookmark/Commands/Bookmarks.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,21 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Wox.Infrastructure;
|
using Wox.Plugin.BrowserBookmark.Commands;
|
||||||
using Wox.Plugin.SharedCommands;
|
using Wox.Plugin.SharedCommands;
|
||||||
|
|
||||||
namespace Wox.Plugin.BrowserBookmark
|
namespace Wox.Plugin.BrowserBookmark
|
||||||
{
|
{
|
||||||
public class Main : IPlugin
|
public class Main : IPlugin, IReloadable
|
||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
|
|
||||||
// TODO: periodically refresh the Cache?
|
|
||||||
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
|
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
|
||||||
|
|
||||||
public void Init(PluginInitContext context)
|
public void Init(PluginInitContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
// Cache all bookmarks
|
cachedBookmarks = Bookmarks.LoadAllBookmarks();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Result> Query(Query query)
|
public List<Result> Query(Query query)
|
||||||
@@ -41,7 +30,7 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
if (!topResults)
|
if (!topResults)
|
||||||
{
|
{
|
||||||
// Since we mixed chrome and firefox bookmarks, we should order them again
|
// 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();
|
returnList = returnList.OrderByDescending(o => o.Score).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +49,11 @@ namespace Wox.Plugin.BrowserBookmark
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool MatchProgram(Bookmark bookmark, string queryString)
|
public void ReloadData()
|
||||||
{
|
{
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Name, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
cachedBookmarks.Clear();
|
||||||
if ( StringMatcher.FuzzySearch(queryString, bookmark.PinyinName, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
|
||||||
if (StringMatcher.FuzzySearch(queryString, bookmark.Url, new MatchOption()).IsSearchPrecisionScoreMet()) return true;
|
|
||||||
|
|
||||||
return false;
|
cachedBookmarks = Bookmarks.LoadAllBookmarks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Bookmark.cs" />
|
<Compile Include="Bookmark.cs" />
|
||||||
<Compile Include="ChromeBookmarks.cs" />
|
<Compile Include="ChromeBookmarks.cs" />
|
||||||
|
<Compile Include="Commands\Bookmarks.cs" />
|
||||||
<Compile Include="FirefoxBookmarks.cs" />
|
<Compile Include="FirefoxBookmarks.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ using Stopwatch = Wox.Infrastructure.Stopwatch;
|
|||||||
|
|
||||||
namespace Wox.Plugin.Program
|
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 readonly object IndexLock = new object();
|
||||||
private static Win32[] _win32s;
|
private static Win32[] _win32s;
|
||||||
@@ -145,5 +145,13 @@ namespace Wox.Plugin.Program
|
|||||||
}
|
}
|
||||||
return hide;
|
return hide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReloadData()
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
IndexPrograms();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +207,17 @@ namespace Wox.Plugin.Sys
|
|||||||
context.API.OpenSettingDialog();
|
context.API.OpenSettingDialog();
|
||||||
return true;
|
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;
|
return results;
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Wox.Core.Resource;
|
|
||||||
using Wox.Infrastructure;
|
using Wox.Infrastructure;
|
||||||
using Wox.Infrastructure.Exception;
|
|
||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Infrastructure.UserSettings;
|
using Wox.Infrastructure.UserSettings;
|
||||||
@@ -66,6 +64,15 @@ namespace Wox.Core.Plugin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ReloadData()
|
||||||
|
{
|
||||||
|
foreach(var plugin in AllPlugins)
|
||||||
|
{
|
||||||
|
var reloadablePlugin = plugin.Plugin as IReloadable;
|
||||||
|
reloadablePlugin?.ReloadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static PluginManager()
|
static PluginManager()
|
||||||
{
|
{
|
||||||
ValidateUserDirectory();
|
ValidateUserDirectory();
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ namespace Wox.Plugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void SaveAppAllSettings();
|
void SaveAppAllSettings();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads any Plugins that have the
|
||||||
|
/// IReloadable implemented. It refeshes
|
||||||
|
/// Plugin's in memory data with new content
|
||||||
|
/// added by user.
|
||||||
|
/// </summary>
|
||||||
|
void ReloadAllPluginData();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Show message box
|
/// Show message box
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
18
Wox.Plugin/Interfaces/IReloadable.cs
Normal file
18
Wox.Plugin/Interfaces/IReloadable.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Wox.Plugin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This interface is to indicate and allow plugins to reload their
|
||||||
|
/// in memory data cache or other mediums when user makes a new change
|
||||||
|
/// that is not immediately captured. For example, for BrowserBookmark and Program
|
||||||
|
/// plugin does not automatically detect when a user added a new bookmark or program,
|
||||||
|
/// so this interface's function is exposed to allow user manually do the reloading after
|
||||||
|
/// those new additions.
|
||||||
|
///
|
||||||
|
/// The command that allows user to manual reload is exposed via Plugin.Sys, and
|
||||||
|
/// it will call the plugins that have implemented this interface.
|
||||||
|
/// </summary>
|
||||||
|
public interface IReloadable
|
||||||
|
{
|
||||||
|
void ReloadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@
|
|||||||
<Compile Include="Features\IContextMenu.cs" />
|
<Compile Include="Features\IContextMenu.cs" />
|
||||||
<Compile Include="Features\IExclusiveQuery.cs" />
|
<Compile Include="Features\IExclusiveQuery.cs" />
|
||||||
<Compile Include="Features\IInstantQuery.cs" />
|
<Compile Include="Features\IInstantQuery.cs" />
|
||||||
|
<Compile Include="Interfaces\IReloadable.cs" />
|
||||||
<Compile Include="IPlugin.cs" />
|
<Compile Include="IPlugin.cs" />
|
||||||
<Compile Include="IPublicAPI.cs" />
|
<Compile Include="IPublicAPI.cs" />
|
||||||
<Compile Include="ISettingProvider.cs" />
|
<Compile Include="ISettingProvider.cs" />
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ namespace Wox
|
|||||||
Alphabet.Save();
|
Alphabet.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ReloadAllPluginData()
|
||||||
|
{
|
||||||
|
PluginManager.ReloadData();
|
||||||
|
}
|
||||||
|
|
||||||
[Obsolete]
|
[Obsolete]
|
||||||
public void HideApp()
|
public void HideApp()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user