2022-10-29 18:42:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-09-08 12:16:47 +00:00
|
|
|
|
using System.Linq;
|
2025-04-08 08:29:03 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Plugin.Program.Views.Models;
|
2019-09-08 12:16:47 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Plugin.Program.Views.Commands
|
2019-09-08 12:16:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
internal static class ProgramSettingDisplay
|
|
|
|
|
|
{
|
2022-10-24 15:26:41 +00:00
|
|
|
|
internal static List<ProgramSource> LoadProgramSources()
|
2019-09-08 12:16:47 +00:00
|
|
|
|
{
|
2019-10-15 09:21:55 +00:00
|
|
|
|
// Even though these are disabled, we still want to display them so users can enable later on
|
2022-10-24 15:26:41 +00:00
|
|
|
|
return Main._settings
|
|
|
|
|
|
.DisabledProgramSources
|
|
|
|
|
|
.Union(Main._settings.ProgramSources)
|
|
|
|
|
|
.ToList();
|
2019-09-08 12:16:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
internal static async Task DisplayAllProgramsAsync()
|
2019-09-08 12:16:47 +00:00
|
|
|
|
{
|
2025-04-08 08:29:03 +00:00
|
|
|
|
await Main._win32sLock.WaitAsync();
|
2025-09-15 07:40:49 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var win32 = Main._win32s
|
2022-10-29 18:42:35 +00:00
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
|
|
|
|
|
.Select(x => new ProgramSource(x));
|
2025-09-15 07:40:49 +00:00
|
|
|
|
ProgramSetting.ProgramSettingDisplayList.AddRange(win32);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._win32sLock.Release();
|
|
|
|
|
|
}
|
2019-09-08 12:16:47 +00:00
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
await Main._uwpsLock.WaitAsync();
|
2025-09-15 07:40:49 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
var uwp = Main._uwps
|
2022-10-29 18:42:35 +00:00
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
|
|
|
|
|
.Select(x => new ProgramSource(x));
|
2025-09-15 07:40:49 +00:00
|
|
|
|
ProgramSetting.ProgramSettingDisplayList.AddRange(uwp);
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._uwpsLock.Release();
|
|
|
|
|
|
}
|
2019-09-08 12:16:47 +00:00
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
internal static async Task SetProgramSourcesStatusAsync(List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
2019-09-08 12:18:55 +00:00
|
|
|
|
{
|
2022-10-29 18:42:35 +00:00
|
|
|
|
foreach(var program in ProgramSetting.ProgramSettingDisplayList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
|
|
|
|
|
|
{
|
|
|
|
|
|
program.Enabled = status;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
await Main._win32sLock.WaitAsync();
|
2025-09-15 07:40:49 +00:00
|
|
|
|
try
|
2022-10-29 18:42:35 +00:00
|
|
|
|
{
|
2025-09-15 07:40:49 +00:00
|
|
|
|
foreach (var program in Main._win32s)
|
2022-10-29 18:42:35 +00:00
|
|
|
|
{
|
2025-09-15 07:40:49 +00:00
|
|
|
|
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
|
|
|
|
|
|
{
|
|
|
|
|
|
program.Enabled = status;
|
|
|
|
|
|
}
|
2022-10-29 18:42:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-15 07:40:49 +00:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._win32sLock.Release();
|
|
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
await Main._uwpsLock.WaitAsync();
|
2025-09-15 07:40:49 +00:00
|
|
|
|
try
|
2022-10-29 18:42:35 +00:00
|
|
|
|
{
|
2025-09-15 07:40:49 +00:00
|
|
|
|
foreach (var program in Main._uwps)
|
2022-10-29 18:42:35 +00:00
|
|
|
|
{
|
2025-09-15 07:40:49 +00:00
|
|
|
|
if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
|
|
|
|
|
|
{
|
|
|
|
|
|
program.Enabled = status;
|
|
|
|
|
|
}
|
2022-10-29 18:42:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-15 07:40:49 +00:00
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._uwpsLock.Release();
|
|
|
|
|
|
}
|
2019-09-09 21:57:03 +00:00
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2022-10-24 15:26:41 +00:00
|
|
|
|
internal static void StoreDisabledInSettings()
|
2019-09-09 21:57:03 +00:00
|
|
|
|
{
|
2022-10-25 09:39:01 +00:00
|
|
|
|
// Disabled, not in DisabledProgramSources or ProgramSources
|
|
|
|
|
|
var tmp = ProgramSetting.ProgramSettingDisplayList
|
2019-09-09 21:57:03 +00:00
|
|
|
|
.Where(t1 => !t1.Enabled
|
2022-10-25 09:39:01 +00:00
|
|
|
|
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier)
|
2022-10-28 10:06:44 +00:00
|
|
|
|
&& !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier));
|
2022-10-25 09:39:01 +00:00
|
|
|
|
|
|
|
|
|
|
Main._settings.DisabledProgramSources.AddRange(tmp);
|
2019-09-08 12:18:55 +00:00
|
|
|
|
}
|
2019-10-14 21:05:21 +00:00
|
|
|
|
|
2022-10-24 15:26:41 +00:00
|
|
|
|
internal static void RemoveDisabledFromSettings()
|
2019-10-14 21:05:21 +00:00
|
|
|
|
{
|
2022-10-29 18:42:35 +00:00
|
|
|
|
Main._settings.DisabledProgramSources.RemoveAll(t1 => t1.Enabled);
|
2019-10-14 21:05:21 +00:00
|
|
|
|
}
|
2019-10-15 11:39:55 +00:00
|
|
|
|
|
2025-04-08 08:29:03 +00:00
|
|
|
|
internal static async Task<bool> IsReindexRequiredAsync(this List<ProgramSource> selectedItems)
|
2019-10-15 11:39:55 +00:00
|
|
|
|
{
|
2022-10-20 08:47:49 +00:00
|
|
|
|
// Not in cache
|
2025-04-08 08:29:03 +00:00
|
|
|
|
await Main._win32sLock.WaitAsync();
|
|
|
|
|
|
await Main._uwpsLock.WaitAsync();
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (selectedItems.Any(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
|
2022-10-20 08:47:49 +00:00
|
|
|
|
&& selectedItems.Any(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)))
|
2025-04-08 08:29:03 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
finally
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._win32sLock.Release();
|
|
|
|
|
|
Main._uwpsLock.Release();
|
|
|
|
|
|
}
|
2019-10-15 11:39:55 +00:00
|
|
|
|
|
2019-10-16 19:43:18 +00:00
|
|
|
|
// ProgramSources holds list of user added directories,
|
2019-10-15 11:39:55 +00:00
|
|
|
|
// so when we enable/disable we need to reindex to show/not show the programs
|
|
|
|
|
|
// that are found in those directories.
|
2022-10-20 08:47:49 +00:00
|
|
|
|
if (selectedItems.Any(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)))
|
2019-10-15 11:39:55 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2019-09-08 12:16:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|