mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
fix reloaddata not working and refactor Init code
This commit is contained in:
parent
63e32f1097
commit
29ab9db7ce
2 changed files with 17 additions and 48 deletions
|
|
@ -55,21 +55,12 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
public static async Task ReloadData()
|
||||
{
|
||||
await Task.WhenAll(AllPlugins.Select(plugin =>
|
||||
await Task.WhenAll(AllPlugins.Select(plugin => plugin.Plugin switch
|
||||
{
|
||||
{
|
||||
switch (plugin)
|
||||
{
|
||||
case IReloadable p:
|
||||
p.ReloadData(); // Sync reload means low time consuming
|
||||
return Task.CompletedTask;
|
||||
case IAsyncReloadable p:
|
||||
return p.ReloadDataAsync();
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}));
|
||||
IReloadable p => Task.Run(p.ReloadData),
|
||||
IAsyncReloadable p => p.ReloadDataAsync(),
|
||||
_ => Task.CompletedTask,
|
||||
}).ToArray());
|
||||
}
|
||||
|
||||
static PluginManager()
|
||||
|
|
@ -106,38 +97,16 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
try
|
||||
{
|
||||
long milliseconds;
|
||||
|
||||
switch (pair.Plugin)
|
||||
var milliseconds = pair.Plugin switch
|
||||
{
|
||||
case IAsyncPlugin plugin:
|
||||
milliseconds = await Stopwatch.DebugAsync(
|
||||
$"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
|
||||
async delegate
|
||||
{
|
||||
await plugin.InitAsync(new PluginInitContext
|
||||
{
|
||||
CurrentPluginMetadata = pair.Metadata,
|
||||
API = API
|
||||
});
|
||||
});
|
||||
break;
|
||||
case IPlugin plugin:
|
||||
milliseconds = Stopwatch.Debug(
|
||||
$"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
|
||||
() =>
|
||||
{
|
||||
plugin.Init(new PluginInitContext
|
||||
{
|
||||
CurrentPluginMetadata = pair.Metadata,
|
||||
API = API
|
||||
});
|
||||
});
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
IAsyncPlugin plugin
|
||||
=> await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
|
||||
() => plugin.InitAsync(new PluginInitContext(pair.Metadata, API))),
|
||||
IPlugin plugin
|
||||
=> Stopwatch.Debug($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
|
||||
() => plugin.Init(new PluginInitContext(pair.Metadata, API))),
|
||||
_ => throw new ArgumentException(),
|
||||
};
|
||||
pair.Metadata.InitTime += milliseconds;
|
||||
Log.Info(
|
||||
$"|PluginManager.InitializePlugins|Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>");
|
||||
|
|
|
|||
|
|
@ -78,9 +78,9 @@ namespace Flow.Launcher
|
|||
ImageLoader.Save();
|
||||
}
|
||||
|
||||
public async Task ReloadAllPluginData()
|
||||
public Task ReloadAllPluginData()
|
||||
{
|
||||
await PluginManager.ReloadData();
|
||||
return PluginManager.ReloadData();
|
||||
}
|
||||
|
||||
public void ShowMsg(string title, string subTitle = "", string iconPath = "")
|
||||
|
|
@ -92,7 +92,7 @@ namespace Flow.Launcher
|
|||
{
|
||||
Application.Current.Dispatcher.Invoke(() =>
|
||||
{
|
||||
var msg = useMainWindowAsOwner ? new Msg {Owner = Application.Current.MainWindow} : new Msg();
|
||||
var msg = useMainWindowAsOwner ? new Msg { Owner = Application.Current.MainWindow } : new Msg();
|
||||
msg.Show(title, subTitle, iconPath);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue