PowerToys/Plugins/Wox.Plugin.BrowserBookmark/Main.cs

71 lines
2.1 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using Wox.Plugin.BrowserBookmark.Commands;
using Wox.Plugin.SharedCommands;
namespace Wox.Plugin.BrowserBookmark
{
public class Main : IPlugin, IReloadable, IPluginI18n
{
private PluginInitContext context;
private List<Bookmark> cachedBookmarks = new List<Bookmark>();
public void Init(PluginInitContext context)
{
this.context = context;
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
public List<Result> Query(Query query)
{
string param = query.GetAllRemainingParameter().TrimStart();
// Should top results be returned? (true if no search parameters have been passed)
var topResults = string.IsNullOrEmpty(param);
var returnList = cachedBookmarks;
if (!topResults)
{
// Since we mixed chrome and firefox bookmarks, we should order them again
returnList = cachedBookmarks.Where(o => Bookmarks.MatchProgram(o, param)).ToList();
returnList = returnList.OrderByDescending(o => o.Score).ToList();
}
return returnList.Select(c => new Result()
{
Title = c.Name,
SubTitle = c.Url,
IcoPath = @"Images\bookmark.png",
Score = 5,
Action = (e) =>
{
context.API.HideApp();
c.Url.NewBrowserWindow("");
return true;
}
}).ToList();
}
2019-10-06 09:58:36 +08:00
public void ReloadData()
{
cachedBookmarks.Clear();
cachedBookmarks = Bookmarks.LoadAllBookmarks();
}
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("wox_plugin_browserbookmark_plugin_description");
}
}
}