mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix hide item option not working in Program plugin (#4141)
This commit is contained in:
parent
1594683191
commit
bb1dfcde9b
3 changed files with 73 additions and 43 deletions
|
|
@ -334,7 +334,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
}
|
||||
}
|
||||
|
||||
public static async Task IndexWin32ProgramsAsync()
|
||||
public static async Task IndexWin32ProgramsAsync(bool resetCache)
|
||||
{
|
||||
await _win32sLock.WaitAsync();
|
||||
try
|
||||
|
|
@ -345,7 +345,10 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
_win32s.Add(win32);
|
||||
}
|
||||
ResetCache();
|
||||
if (resetCache)
|
||||
{
|
||||
ResetCache();
|
||||
}
|
||||
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
|
||||
lock (_lastIndexTimeLock)
|
||||
{
|
||||
|
|
@ -362,7 +365,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
}
|
||||
}
|
||||
|
||||
public static async Task IndexUwpProgramsAsync()
|
||||
public static async Task IndexUwpProgramsAsync(bool resetCache)
|
||||
{
|
||||
await _uwpsLock.WaitAsync();
|
||||
try
|
||||
|
|
@ -373,7 +376,10 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
_uwps.Add(uwp);
|
||||
}
|
||||
ResetCache();
|
||||
if (resetCache)
|
||||
{
|
||||
ResetCache();
|
||||
}
|
||||
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
|
||||
lock (_lastIndexTimeLock)
|
||||
{
|
||||
|
|
@ -394,12 +400,12 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
var win32Task = Task.Run(async () =>
|
||||
{
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", IndexWin32ProgramsAsync);
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", () => IndexWin32ProgramsAsync(resetCache: true));
|
||||
});
|
||||
|
||||
var uwpTask = Task.Run(async () =>
|
||||
{
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", IndexUwpProgramsAsync);
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", () => IndexUwpProgramsAsync(resetCache: true));
|
||||
});
|
||||
|
||||
await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);
|
||||
|
|
@ -407,9 +413,21 @@ namespace Flow.Launcher.Plugin.Program
|
|||
|
||||
internal static void ResetCache()
|
||||
{
|
||||
var oldCache = cache;
|
||||
cache = new MemoryCache(cacheOptions);
|
||||
oldCache.Dispose();
|
||||
var newCache = new MemoryCache(cacheOptions);
|
||||
|
||||
// Atomically swap and get the previous cache instance, avoids double-dispose/lost-assignment race
|
||||
// where each caller receives a distinct prior instance to dispose.
|
||||
var oldCache = Interlocked.Exchange(ref cache, newCache);
|
||||
|
||||
// Dispose the previous instance (if any)- each caller gets a unique prior instance from above
|
||||
try
|
||||
{
|
||||
oldCache?.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Context.API.LogException(ClassName, "Failed to dispose old program cache", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Control CreateSettingPanel()
|
||||
|
|
@ -442,12 +460,26 @@ namespace Flow.Launcher.Plugin.Program
|
|||
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
|
||||
{
|
||||
var disabled = await DisableProgramAsync(program);
|
||||
if (disabled)
|
||||
{
|
||||
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",
|
||||
|
|
@ -458,52 +490,50 @@ namespace Flow.Launcher.Plugin.Program
|
|||
return menuOptions;
|
||||
}
|
||||
|
||||
private static async Task DisableProgramAsync(IProgram programToDelete)
|
||||
private static async Task<bool> DisableProgramAsync(IProgram programToDelete)
|
||||
{
|
||||
if (_settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
|
||||
return;
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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(resetCache: false));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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(resetCache: false));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_win32sLock.Release();
|
||||
}
|
||||
|
||||
// Reindex Win32 programs
|
||||
if (reindexWin32s)
|
||||
{
|
||||
_ = Task.Run(IndexWin32ProgramsAsync);
|
||||
return;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void StartProcess(Func<ProcessStartInfo, Process> runProcess, ProcessStartInfo info)
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
|
||||
private static readonly Channel<byte> PackageChangeChannel = Channel.CreateBounded<byte>(1);
|
||||
private static PackageCatalog? catalog;
|
||||
private static PackageCatalog catalog;
|
||||
|
||||
public static async Task WatchPackageChangeAsync()
|
||||
{
|
||||
|
|
@ -317,7 +317,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
{
|
||||
await Task.Delay(3000).ConfigureAwait(false);
|
||||
PackageChangeChannel.Reader.TryRead(out _);
|
||||
await Task.Run(Main.IndexUwpProgramsAsync);
|
||||
await Main.IndexUwpProgramsAsync(resetCache: true).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -796,7 +796,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
{
|
||||
}
|
||||
|
||||
await Task.Run(Main.IndexWin32ProgramsAsync);
|
||||
await Main.IndexWin32ProgramsAsync(resetCache: true).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue