diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index bd09cd9c61a..d0347fa670c 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -85,20 +85,20 @@ public async Task InitAsync(PluginInitContext context) { _context = context; - await Task.Run(() => - { - _settings = _settingsStorage.Load(); + _settings = _settingsStorage.Load(); - Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", () => - { - _win32Storage = new BinaryStorage("Win32"); - _win32s = _win32Storage.TryLoad(new Win32[] { }); - _uwpStorage = new BinaryStorage("UWP"); - _uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); - }); - Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); - Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); + await Task.Yield(); + + Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", () => + { + _win32Storage = new BinaryStorage("Win32"); + _win32s = _win32Storage.TryLoad(new Win32[] { }); + _uwpStorage = new BinaryStorage("UWP"); + _uwps = _uwpStorage.TryLoad(new UWP.Application[] { }); }); + Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>"); + Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>"); + bool indexedWinApps = false; bool indexedUWPApps = false; @@ -121,16 +121,19 @@ await Task.Run(() => } }); - await Task.WhenAll(a, b); - - if (indexedWinApps && indexedUWPApps) - _settings.LastIndexTime = DateTime.Today; + var indexTask = Task.WhenAll(a, b).ContinueWith(t => + { + if (indexedWinApps && indexedUWPApps) + _settings.LastIndexTime = DateTime.Today; + }); + + if (!(_win32s.Any() && _uwps.Any())) + await indexTask; } public static void IndexWin32Programs() { var win32S = Win32.All(_settings); - _win32s = win32S; } @@ -138,20 +141,15 @@ public static void IndexUwpPrograms() { var windows10 = new Version(10, 0); var support = Environment.OSVersion.Version.Major >= windows10.Major; - var applications = support ? UWP.All() : new UWP.Application[] { }; - _uwps = applications; } public static async Task IndexPrograms() { var t1 = Task.Run(IndexWin32Programs); - var t2 = Task.Run(IndexUwpPrograms); - await Task.WhenAll(t1, t2).ConfigureAwait(false); - _settings.LastIndexTime = DateTime.Today; } @@ -245,4 +243,4 @@ public async Task ReloadDataAsync() await IndexPrograms(); } } -} +} \ No newline at end of file diff --git a/Plugins/Flow.Launcher.Plugin.Program/plugin.json b/Plugins/Flow.Launcher.Plugin.Program/plugin.json index 082f0d85370..48386118a89 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/plugin.json +++ b/Plugins/Flow.Launcher.Plugin.Program/plugin.json @@ -4,7 +4,7 @@ "Name": "Program", "Description": "Search programs in Flow.Launcher", "Author": "qianlifeng", - "Version": "1.4.3", + "Version": "1.4.4", "Language": "csharp", "Website": "https://github.com/Flow-Launcher/Flow.Launcher", "ExecuteFileName": "Flow.Launcher.Plugin.Program.dll",