diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs index 456085fcaf2..707534ad41e 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs @@ -442,12 +442,23 @@ public List LoadContextMenus(Result selectedResult) Title = Context.API.GetTranslation("flowlauncher_plugin_program_disable_program"), Action = c => { - _ = DisableProgramAsync(program); - Context.API.ShowMsg( - Context.API.GetTranslation("flowlauncher_plugin_program_disable_dlgtitle_success"), - Context.API.GetTranslation( - "flowlauncher_plugin_program_disable_dlgtitle_success_message")); - Context.API.ReQuery(); + _ = Task.Run(async () => + { + try + { + await DisableProgramAsync(program); + ResetCache(); + Context.API.ShowMsg( + Context.API.GetTranslation("flowlauncher_plugin_program_disable_dlgtitle_success"), + Context.API.GetTranslation( + "flowlauncher_plugin_program_disable_dlgtitle_success_message")); + Context.API.ReQuery(); + } + catch (Exception e) + { + Context.API.LogException(ClassName, "Failed to disable program", e); + } + }); return false; }, IcoPath = "Images/disable.png", @@ -464,46 +475,40 @@ private static async Task DisableProgramAsync(IProgram programToDelete) return; await _uwpsLock.WaitAsync(); - var reindexUwps = true; try { - reindexUwps = _uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); - var program = _uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); - program.Enabled = false; - _settings.DisabledProgramSources.Add(new ProgramSource(program)); + var program = _uwps.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); + if (program != null) + { + program.Enabled = false; + _settings.DisabledProgramSources.Add(new ProgramSource(program)); + // Reindex UWP programs + _ = Task.Run(IndexUwpProgramsAsync); + return; + } } finally { _uwpsLock.Release(); } - // Reindex UWP programs - if (reindexUwps) - { - _ = Task.Run(IndexUwpProgramsAsync); - return; - } - await _win32sLock.WaitAsync(); - var reindexWin32s = true; try { - reindexWin32s = _win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); - var program = _win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); - program.Enabled = false; - _settings.DisabledProgramSources.Add(new ProgramSource(program)); + var program = _win32s.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier); + if (program != null) + { + program.Enabled = false; + _settings.DisabledProgramSources.Add(new ProgramSource(program)); + // Reindex Win32 programs + _ = Task.Run(IndexWin32ProgramsAsync); + return; + } } finally { _win32sLock.Release(); } - - // Reindex Win32 programs - if (reindexWin32s) - { - _ = Task.Run(IndexWin32ProgramsAsync); - return; - } } public static void StartProcess(Func runProcess, ProcessStartInfo info)