Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 40 additions & 21 deletions Plugins/Flow.Launcher.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

internal static PluginInitContext Context { get; private set; }

private static readonly List<Result> emptyResults = new();
private static readonly List<Result> emptyResults = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮


private static readonly MemoryCacheOptions cacheOptions = new() { SizeLimit = 1560 };
private static MemoryCache cache = new(cacheOptions);
Expand All @@ -40,10 +40,10 @@
{
"uninst.exe",
"unins000.exe",
"uninst000.exe",

Check warning on line 43 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`uninst` is not a recognized word. (unrecognized-spelling)
"uninstall.exe"
};
private static readonly string[] commonUninstallerPrefixs =

Check warning on line 46 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)
{
"uninstall",//en
"卸载",//zh-cn
Expand All @@ -59,9 +59,9 @@
"삭제",//ko
"деинсталирај",//sr
"desinstalar",//pt-pt
"desinstalar",//pt-br

Check warning on line 62 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"desinstalar",//es

Check warning on line 63 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"desinstalar",//es-419

Check warning on line 64 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"disinstallare",//it
"avinstallere",//nb-NO
"odinštalovať",//sk
Expand All @@ -71,8 +71,8 @@
"gỡ bỏ",//vi-vn
"הסרה"//he
};
private const string ExeUninstallerSuffix = ".exe";

Check warning on line 74 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)
private const string InkUninstallerSuffix = ".lnk";

Check warning on line 75 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)

private static readonly string WindowsAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps");

Expand All @@ -84,7 +84,6 @@
{
await _win32sLock.WaitAsync(token);
await _uwpsLock.WaitAsync(token);

try
{
// Collect all UWP Windows app directories
Expand Down Expand Up @@ -117,7 +116,7 @@
}
}, token);

resultList = resultList.Any() ? resultList : emptyResults;
resultList = resultList.Count != 0 ? resultList : emptyResults;

entry.SetSize(resultList.Count);
entry.SetSlidingExpiration(TimeSpan.FromHours(8));
Expand All @@ -128,14 +127,14 @@
return result;
}

private bool HideUninstallersFilter(IProgram program)

Check warning on line 130 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstallers` is not a recognized word. (unrecognized-spelling)
{
if (!_settings.HideUninstallers) return true;

Check warning on line 132 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstallers` is not a recognized word. (unrecognized-spelling)
if (program is not Win32 win32) return true;

// First check the executable path
var fileName = Path.GetFileName(win32.ExecutablePath);
// For cases when the uninstaller is named like "uninst.exe"

Check warning on line 137 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`uninst` is not a recognized word. (unrecognized-spelling)
if (commonUninstallerNames.Contains(fileName, StringComparer.OrdinalIgnoreCase)) return false;
// For cases when the uninstaller is named like "Uninstall Program Name.exe"
foreach (var prefix in commonUninstallerPrefixs)
Expand Down Expand Up @@ -250,14 +249,26 @@
}

await _win32sLock.WaitAsync();
_win32s = await context.API.LoadCacheBinaryStorageAsync(Win32CacheName, pluginCacheDirectory, new List<Win32>());
_win32sCount = _win32s.Count;
_win32sLock.Release();
try
{
_win32s = await context.API.LoadCacheBinaryStorageAsync(Win32CacheName, pluginCacheDirectory, new List<Win32>());
_win32sCount = _win32s.Count;
}
finally
{
_win32sLock.Release();
}

await _uwpsLock.WaitAsync();
_uwps = await context.API.LoadCacheBinaryStorageAsync(UwpCacheName, pluginCacheDirectory, new List<UWPApp>());
_uwpsCount = _uwps.Count;
_uwpsLock.Release();
try
{
_uwps = await context.API.LoadCacheBinaryStorageAsync(UwpCacheName, pluginCacheDirectory, new List<UWPApp>());
_uwpsCount = _uwps.Count;
}
finally
{
_uwpsLock.Release();
}
});
Context.API.LogInfo(ClassName, $"Number of preload win32 programs <{_win32sCount}>");
Context.API.LogInfo(ClassName, $"Number of preload uwps <{_uwpsCount}>");
Expand Down Expand Up @@ -408,38 +419,46 @@
return;

await _uwpsLock.WaitAsync();
if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
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));
}
finally
{
_uwpsLock.Release();
}

// Reindex UWP programs
// Reindex UWP programs
if (reindexUwps)
{
_ = Task.Run(IndexUwpProgramsAsync);
return;
}
else
{
_uwpsLock.Release();
}

await _win32sLock.WaitAsync();
if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
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));
}
finally
{
_win32sLock.Release();
}

// Reindex Win32 programs
// Reindex Win32 programs
if (reindexWin32s)
{
_ = Task.Run(IndexWin32ProgramsAsync);
return;
}
else
{
_win32sLock.Release();
}
}

public static void StartProcess(Func<ProcessStartInfo, Process> runProcess, ProcessStartInfo info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,30 @@ internal static List<ProgramSource> LoadProgramSources()
internal static async Task DisplayAllProgramsAsync()
{
await Main._win32sLock.WaitAsync();
var win32 = Main._win32s
try
{
var win32 = Main._win32s
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.Select(x => new ProgramSource(x));
ProgramSetting.ProgramSettingDisplayList.AddRange(win32);
Main._win32sLock.Release();
ProgramSetting.ProgramSettingDisplayList.AddRange(win32);
}
finally
{
Main._win32sLock.Release();
}

await Main._uwpsLock.WaitAsync();
var uwp = Main._uwps
try
{
var uwp = Main._uwps
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.Select(x => new ProgramSource(x));
ProgramSetting.ProgramSettingDisplayList.AddRange(uwp);
Main._uwpsLock.Release();
ProgramSetting.ProgramSettingDisplayList.AddRange(uwp);
}
finally
{
Main._uwpsLock.Release();
}
}

internal static async Task SetProgramSourcesStatusAsync(List<ProgramSource> selectedProgramSourcesToDisable, bool status)
Expand All @@ -44,24 +56,36 @@ internal static async Task SetProgramSourcesStatusAsync(List<ProgramSource> sele
}

await Main._win32sLock.WaitAsync();
foreach (var program in Main._win32s)
try
{
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
foreach (var program in Main._win32s)
{
program.Enabled = status;
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
{
program.Enabled = status;
}
}
}
Main._win32sLock.Release();
finally
{
Main._win32sLock.Release();
}

await Main._uwpsLock.WaitAsync();
foreach (var program in Main._uwps)
try
{
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
foreach (var program in Main._uwps)
{
program.Enabled = status;
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
{
program.Enabled = status;
}
}
}
Main._uwpsLock.Release();
finally
{
Main._uwpsLock.Release();
}
}

internal static void StoreDisabledInSettings()
Expand Down
Loading