Update disable logic and add unique identifier for programs

This commit is contained in:
Jeremy Wu
2019-09-10 07:57:03 +10:00
parent 4a6242b3a0
commit 10fb76377c
7 changed files with 94 additions and 42 deletions

View File

@@ -18,38 +18,73 @@ namespace Wox.Plugin.Program.Views.Commands
return list;
}
internal static void LoadAllApplications(this List<ProgramSource> listToUpdate)
internal static void LoadAllApplications(this List<ProgramSource> list)
{
Main._win32s
Main._win32s
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.Name, Location = t1.ParentDirectory, Enabled = t1.Enabled }));
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
.Add(
new ProgramSource {
Name = t1.Name,
Location = t1.ParentDirectory,
UniqueIdentifier = t1.UniqueIdentifier,
Enabled = t1.Enabled
}));
Main._uwps
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.DisplayName, Location = t1.Package.Location, Enabled = t1.Enabled }));
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
.Add(
new ProgramSource {
Name = t1.DisplayName,
Location = t1.Package.Location,
UniqueIdentifier = t1.UniqueIdentifier,
Enabled = t1.Enabled
})
);
}
internal static void DisableProgramSources(this List<ProgramSource> listToUpdate, List<ProgramSource> selectedprogramSourcesToDisable)
internal static void DisableProgramSources(this List<ProgramSource> list, List<ProgramSource> selectedprogramSourcesToDisable)
{
ProgramSetting.ProgramSettingDisplayList
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
Main._win32s
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.ParentDirectory && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
Main._uwps
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.DisplayName && x.Location == t1.Package.Location && t1.Enabled))
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
}
internal static void StoreDisabledInSettings(this List<ProgramSource> list)
{
Main._settings.ProgramSources
.Where(t1 => selectedprogramSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
.ToList()
.ForEach(t1 => t1.Enabled = false);
ProgramSetting.ProgramSettingDisplayList
.Where(t1 => !t1.Enabled
&& !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
.ToList()
.ForEach(x => Main._settings.ProgramSources
.Add(
new Settings.ProgramSource
{
Name = x.Name,
Location = x.Location,
UniqueIdentifier = x.UniqueIdentifier,
Enabled = false
}
));
}
}
}

View File

@@ -13,6 +13,7 @@ namespace Wox.Plugin.Program.Views.Models
public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public string UniqueIdentifier { get; set; }
public bool Enabled { get; set; } = true;
}
}

View File

@@ -168,6 +168,8 @@ namespace Wox.Plugin.Program.Views
.SelectedItems.Cast<ProgramSource>()
.ToList());
ProgramSettingDisplayList.StoreDisabledInSettings();
programSourceView.SelectedItems.Clear();
programSourceView.Items.Refresh();