2019-09-08 12:16:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
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-20 08:15:56 +00:00
|
|
|
|
internal static List<ProgramSource> LoadProgramSources(this List<ProgramSource> programSources)
|
2019-09-08 12:16:47 +00:00
|
|
|
|
{
|
2022-10-24 15:16:09 +00:00
|
|
|
|
var list = new List<ProgramSource>(programSources);
|
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
|
|
|
|
|
|
Main._settings
|
|
|
|
|
|
.DisabledProgramSources
|
2019-10-15 11:39:55 +00:00
|
|
|
|
.Where(t1 => !Main._settings
|
|
|
|
|
|
.ProgramSources // program sourcces added above already, so exlcude
|
|
|
|
|
|
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
|
|
|
|
|
|
.Select(x => x)
|
|
|
|
|
|
.ToList()
|
2022-10-20 09:15:16 +00:00
|
|
|
|
.ForEach(x => list.Add(new ProgramSource(x)));
|
2019-09-08 12:16:47 +00:00
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-09 21:57:03 +00:00
|
|
|
|
internal static void LoadAllApplications(this List<ProgramSource> list)
|
2019-09-08 12:16:47 +00:00
|
|
|
|
{
|
2019-09-09 21:57:03 +00:00
|
|
|
|
Main._win32s
|
|
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-08 12:16:47 +00:00
|
|
|
|
.ToList()
|
2022-10-20 09:15:16 +00:00
|
|
|
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
|
2019-09-08 12:16:47 +00:00
|
|
|
|
|
|
|
|
|
|
Main._uwps
|
2019-09-09 21:57:03 +00:00
|
|
|
|
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-08 12:16:47 +00:00
|
|
|
|
.ToList()
|
2022-10-20 09:15:16 +00:00
|
|
|
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
|
2019-09-08 12:16:47 +00:00
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2019-10-14 21:05:21 +00:00
|
|
|
|
internal static void SetProgramSourcesStatus(this List<ProgramSource> list, List<ProgramSource> selectedProgramSourcesToDisable, bool status)
|
2019-09-08 12:18:55 +00:00
|
|
|
|
{
|
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 12:18:55 +00:00
|
|
|
|
.ToList()
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
Main._win32s
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 12:18:55 +00:00
|
|
|
|
.ToList()
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
|
|
|
|
|
Main._uwps
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
|
2019-09-08 12:18:55 +00:00
|
|
|
|
.ToList()
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.ForEach(t1 => t1.Enabled = status);
|
2019-09-09 21:57:03 +00:00
|
|
|
|
}
|
2019-09-08 12:18:55 +00:00
|
|
|
|
|
2019-09-09 21:57:03 +00:00
|
|
|
|
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
|
|
|
|
|
|
{
|
2019-09-08 12:18:55 +00:00
|
|
|
|
Main._settings.ProgramSources
|
2019-09-09 21:57:03 +00:00
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
|
2019-09-08 12:18:55 +00:00
|
|
|
|
.ToList()
|
|
|
|
|
|
.ForEach(t1 => t1.Enabled = false);
|
2019-09-09 21:57:03 +00:00
|
|
|
|
|
|
|
|
|
|
ProgramSetting.ProgramSettingDisplayList
|
|
|
|
|
|
.Where(t1 => !t1.Enabled
|
2019-10-14 21:05:21 +00:00
|
|
|
|
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
|
2019-09-09 21:57:03 +00:00
|
|
|
|
.ToList()
|
2019-10-14 21:05:21 +00:00
|
|
|
|
.ForEach(x => Main._settings.DisabledProgramSources
|
2022-10-20 08:55:14 +00:00
|
|
|
|
.Add(new DisabledProgramSource(x)));
|
2019-09-08 12:18:55 +00:00
|
|
|
|
}
|
2019-10-14 21:05:21 +00:00
|
|
|
|
|
|
|
|
|
|
internal static void RemoveDisabledFromSettings(this List<ProgramSource> list)
|
|
|
|
|
|
{
|
|
|
|
|
|
Main._settings.ProgramSources
|
|
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
.ForEach(t1 => t1.Enabled = true);
|
|
|
|
|
|
|
|
|
|
|
|
Main._settings.DisabledProgramSources
|
|
|
|
|
|
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
.ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
|
|
|
|
|
|
}
|
2019-10-15 11:39:55 +00:00
|
|
|
|
|
|
|
|
|
|
internal static bool IsReindexRequired(this List<ProgramSource> selectedItems)
|
|
|
|
|
|
{
|
2022-10-20 08:47:49 +00:00
|
|
|
|
// Not in cache
|
|
|
|
|
|
if (selectedItems.Any(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
|
|
|
|
|
|
&& selectedItems.Any(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)))
|
2019-10-15 11:39:55 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|