Update PluginManifest if last update time is 12 hours ago

This commit is contained in:
弘韬 张 2020-12-28 23:06:47 +08:00
parent deaac1c7e4
commit 5a0358718c
3 changed files with 25 additions and 9 deletions

View file

@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Windows.Controls;
using Flow.Launcher.Infrastructure;
using System;
using System.Threading.Tasks;
namespace Flow.Launcher.Plugin.PluginsManager
{
@ -21,6 +23,8 @@ namespace Flow.Launcher.Plugin.PluginsManager
internal PluginsManager pluginManager;
internal DateTime _lastUpdateTime;
public Control CreateSettingPanel()
{
return new PluginsManagerSettings(viewModel);
@ -33,6 +37,7 @@ namespace Flow.Launcher.Plugin.PluginsManager
Settings = viewModel.Settings;
contextMenu = new ContextMenu(Context, Settings);
pluginManager = new PluginsManager(Context, Settings);
_lastUpdateTime = DateTime.Now;
}
public List<Result> LoadContextMenus(Result selectedResult)
@ -43,10 +48,19 @@ namespace Flow.Launcher.Plugin.PluginsManager
public List<Result> Query(Query query)
{
var search = query.Search.ToLower();
if (string.IsNullOrWhiteSpace(search))
return Settings.HotKeys;
if ((DateTime.Now - _lastUpdateTime).TotalSeconds > 43200) // 12 hours
{
Task.Run(async () =>
{
await pluginManager.UpdateManifest();
_lastUpdateTime = DateTime.Now;
});
}
return search switch
{
var s when s.StartsWith(Settings.HotKeyInstall) => pluginManager.RequestInstallOrUpdate(s),

View file

@ -12,19 +12,15 @@ namespace Flow.Launcher.Plugin.PluginsManager.Models
internal List<UserPlugin> UserPlugins { get; private set; }
internal PluginsManifest()
{
DownloadManifest();
Task.Run(() => DownloadManifest()).Wait();
}
private void DownloadManifest()
internal async Task DownloadManifest()
{
var json = string.Empty;
try
{
var t = Task.Run(
async () =>
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json"));
t.Wait();
json = await Http.Get("https://raw.githubusercontent.com/Flow-Launcher/Flow.Launcher.PluginsManifest/main/plugins.json");
UserPlugins = JsonConvert.DeserializeObject<List<UserPlugin>>(json);
}

View file

@ -7,13 +7,14 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace Flow.Launcher.Plugin.PluginsManager
{
internal class PluginsManager
{
private readonly PluginsManifest pluginsManifest;
private PluginsManifest pluginsManifest;
private PluginInitContext Context { get; set; }
@ -44,6 +45,11 @@ namespace Flow.Launcher.Plugin.PluginsManager
Settings = settings;
}
internal async Task UpdateManifest()
{
await pluginsManifest.DownloadManifest();
}
internal void InstallOrUpdate(UserPlugin plugin)
{
if (PluginExists(plugin.ID))