Skip to content
Open
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
92 changes: 55 additions & 37 deletions Plugins/Flow.Launcher.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
{
"uninst.exe",
"unins000.exe",
"uninst000.exe",

Check warning on line 45 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 48 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 @@ -61,9 +61,9 @@
"삭제",//ko
"деинсталирај",//sr
"desinstalar",//pt-pt
"desinstalar",//pt-br

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)
"desinstalar",//es

Check warning on line 65 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 66 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 @@ -73,7 +73,7 @@
"gỡ bỏ",//vi-vn
"הסרה"//he
};
private const string ExeUninstallerSuffix = ".exe";

Check warning on line 76 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";

private static readonly string WindowsAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps");
Expand Down Expand Up @@ -334,7 +334,7 @@
}
}

public static async Task IndexWin32ProgramsAsync()
public static async Task IndexWin32ProgramsAsync(bool resetCache)
{
await _win32sLock.WaitAsync();
try
Expand All @@ -345,7 +345,10 @@
{
_win32s.Add(win32);
}
ResetCache();
if (resetCache)
{
ResetCache();
}
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
lock (_lastIndexTimeLock)
{
Expand All @@ -362,7 +365,7 @@
}
}

public static async Task IndexUwpProgramsAsync()
public static async Task IndexUwpProgramsAsync(bool resetCache)
{
await _uwpsLock.WaitAsync();
try
Expand All @@ -373,7 +376,10 @@
{
_uwps.Add(uwp);
}
ResetCache();
if (resetCache)
{
ResetCache();
}
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
lock (_lastIndexTimeLock)
{
Expand All @@ -394,12 +400,12 @@
{
var win32Task = Task.Run(async () =>
{
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", IndexWin32ProgramsAsync);
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", () => IndexWin32ProgramsAsync(true));
});

var uwpTask = Task.Run(async () =>
{
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", IndexUwpProgramsAsync);
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", () => IndexUwpProgramsAsync(true));
});

await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);
Expand Down Expand Up @@ -442,12 +448,26 @@
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",
Expand All @@ -458,52 +478,50 @@
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(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(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)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Flow.Launcher.Plugin.Program/Programs/UWPPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private static IEnumerable<Package> CurrentUserPackages()
}

private static readonly Channel<byte> PackageChangeChannel = Channel.CreateBounded<byte>(1);
private static PackageCatalog? catalog;
private static PackageCatalog catalog;

public static async Task WatchPackageChangeAsync()
{
Expand All @@ -317,7 +317,7 @@ public static async Task WatchPackageChangeAsync()
{
await Task.Delay(3000).ConfigureAwait(false);
PackageChangeChannel.Reader.TryRead(out _);
await Task.Run(Main.IndexUwpProgramsAsync);
await Main.IndexUwpProgramsAsync(true).ConfigureAwait(false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ public static async Task MonitorDirectoryChangeAsync()
{
}

await Task.Run(Main.IndexWin32ProgramsAsync);
await Main.IndexWin32ProgramsAsync(true).ConfigureAwait(false);
}
}

Expand Down
Loading