mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 20:27:36 +02:00
Refactor Plugins.Program
This commit is contained in:
@@ -9,6 +9,7 @@ using Wox.Infrastructure;
|
|||||||
using Wox.Infrastructure.Logger;
|
using Wox.Infrastructure.Logger;
|
||||||
using Wox.Infrastructure.Storage;
|
using Wox.Infrastructure.Storage;
|
||||||
using Wox.Plugin.Program.Programs;
|
using Wox.Plugin.Program.Programs;
|
||||||
|
using Wox.Plugin.Program.Views;
|
||||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program
|
||||||
@@ -135,32 +136,11 @@ namespace Wox.Plugin.Program
|
|||||||
var t2 = Task.Run(() => { IndexUWPPrograms(); });
|
var t2 = Task.Run(() => { IndexUWPPrograms(); });
|
||||||
|
|
||||||
Task.WaitAll(t1, t2);
|
Task.WaitAll(t1, t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void AddLoadedApplicationsToSettings()
|
|
||||||
{
|
|
||||||
_win32s
|
|
||||||
.Where(t1 => !_settings.ProgramSources.Any(x => x.Name == t1.Name))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(t1 => _settings.ProgramSources.Add(new Settings.ProgramSource (){Name = t1.Name, Location = t1.ParentDirectory }));
|
|
||||||
|
|
||||||
_uwps
|
|
||||||
.Where(t1 => !_settings.ProgramSources.Any(x => x.Name == t1.DisplayName))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(t1 => _settings.ProgramSources.Add(new Settings.ProgramSource() { Name = t1.DisplayName, Location = t1.Package.Location }));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DisableProgramSources(List<Settings.ProgramSource> programSourcesToDisable)
|
|
||||||
{
|
|
||||||
_settings.ProgramSources
|
|
||||||
.Where(t1 => programSourcesToDisable.Any(x => x.Name == t1.Name && x.Location == t1.Location && t1.Enabled))
|
|
||||||
.ToList()
|
|
||||||
.ForEach(t1 => t1.Enabled = false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Control CreateSettingPanel()
|
public Control CreateSettingPanel()
|
||||||
{
|
{
|
||||||
return new ProgramSetting(_context, _settings);
|
return new ProgramSetting(_context, _settings, _win32s, _uwps);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetTranslatedPluginTitle()
|
public string GetTranslatedPluginTitle()
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Wox.Plugin.Program.Views.Models;
|
||||||
|
|
||||||
|
namespace Wox.Plugin.Program.Views.Commands
|
||||||
|
{
|
||||||
|
internal static class ProgramSettingDisplay
|
||||||
|
{
|
||||||
|
internal static List<ProgramSource> LoadProgramSources(this List<Settings.ProgramSource> programSources)
|
||||||
|
{
|
||||||
|
var list = new List<ProgramSource>();
|
||||||
|
|
||||||
|
programSources.ForEach(x => list.Add(new ProgramSource { Enabled = x.Enabled, Location = x.Location, Name = x.Name }));
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void LoadAllApplications(this List<ProgramSource> listToUpdate)
|
||||||
|
{
|
||||||
|
Main._win32s
|
||||||
|
.ToList()
|
||||||
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.Name, Location = t1.ParentDirectory, Enabled = t1.Enabled }));
|
||||||
|
|
||||||
|
Main._uwps
|
||||||
|
.ToList()
|
||||||
|
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource { Name = t1.DisplayName, Location = t1.Package.Location, Enabled = t1.Enabled }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<UserControl x:Class="Wox.Plugin.Program.ProgramSetting"
|
<UserControl x:Class="Wox.Plugin.Program.Views.ProgramSetting"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
@@ -6,9 +6,11 @@ using System.Threading.Tasks;
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
using Wox.Plugin.Program.Views.Models;
|
||||||
|
using Wox.Plugin.Program.Views.Commands;
|
||||||
using Wox.Plugin.Program.Programs;
|
using Wox.Plugin.Program.Programs;
|
||||||
|
|
||||||
namespace Wox.Plugin.Program
|
namespace Wox.Plugin.Program.Views
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interaction logic for ProgramSetting.xaml
|
/// Interaction logic for ProgramSetting.xaml
|
||||||
@@ -17,8 +19,9 @@ namespace Wox.Plugin.Program
|
|||||||
{
|
{
|
||||||
private PluginInitContext context;
|
private PluginInitContext context;
|
||||||
private Settings _settings;
|
private Settings _settings;
|
||||||
|
internal static List<ProgramSource> ProgramSettingDisplayList { get; set; }
|
||||||
|
|
||||||
public ProgramSetting(PluginInitContext context, Settings settings)
|
public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win32s, UWP.Application[] uwps)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -28,7 +31,9 @@ namespace Wox.Plugin.Program
|
|||||||
|
|
||||||
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
private void Setting_Loaded(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
programSourceView.ItemsSource = _settings.ProgramSources;
|
ProgramSettingDisplayList = _settings.ProgramSources.LoadProgramSources();
|
||||||
|
programSourceView.ItemsSource = ProgramSettingDisplayList;
|
||||||
|
|
||||||
StartMenuEnabled.IsChecked = _settings.EnableStartMenuSource;
|
StartMenuEnabled.IsChecked = _settings.EnableStartMenuSource;
|
||||||
RegistryEnabled.IsChecked = _settings.EnableRegistrySource;
|
RegistryEnabled.IsChecked = _settings.EnableRegistrySource;
|
||||||
}
|
}
|
||||||
@@ -151,14 +156,17 @@ namespace Wox.Plugin.Program
|
|||||||
|
|
||||||
private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e)
|
private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Main.AddLoadedApplicationsToSettings();
|
ProgramSettingDisplayList.LoadAllApplications();
|
||||||
|
|
||||||
programSourceView.Items.Refresh();
|
programSourceView.Items.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnDisableProgramSource_OnClick(object sender, RoutedEventArgs e)
|
private void btnDisableProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Main.DisableProgramSources(programSourceView.SelectedItems.Cast<Settings.ProgramSource>().ToList());
|
ProgramSettingDisplayList
|
||||||
|
.DisableProgramSources(programSourceView
|
||||||
|
.SelectedItems.Cast<ProgramSource>()
|
||||||
|
.ToList());
|
||||||
|
|
||||||
programSourceView.SelectedItems.Clear();
|
programSourceView.SelectedItems.Clear();
|
||||||
|
|
||||||
@@ -71,13 +71,15 @@
|
|||||||
<Compile Include="AddProgramSource.xaml.cs">
|
<Compile Include="AddProgramSource.xaml.cs">
|
||||||
<DependentUpon>AddProgramSource.xaml</DependentUpon>
|
<DependentUpon>AddProgramSource.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Views\Commands\ProgramSettingDisplay.cs" />
|
||||||
<Compile Include="FileChangeWatcher.cs" />
|
<Compile Include="FileChangeWatcher.cs" />
|
||||||
|
<Compile Include="Views\Models\ProgramSource.cs" />
|
||||||
<Compile Include="Programs\IProgram.cs" />
|
<Compile Include="Programs\IProgram.cs" />
|
||||||
<Compile Include="Programs\UWP.cs" />
|
<Compile Include="Programs\UWP.cs" />
|
||||||
<Compile Include="Programs\Win32.cs" />
|
<Compile Include="Programs\Win32.cs" />
|
||||||
<Compile Include="SuffixesConverter.cs" />
|
<Compile Include="SuffixesConverter.cs" />
|
||||||
<Compile Include="Main.cs" />
|
<Compile Include="Main.cs" />
|
||||||
<Compile Include="ProgramSetting.xaml.cs">
|
<Compile Include="Views\ProgramSetting.xaml.cs">
|
||||||
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
<DependentUpon>ProgramSetting.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Settings.cs" />
|
<Compile Include="Settings.cs" />
|
||||||
@@ -130,7 +132,7 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
<Page Include="ProgramSetting.xaml">
|
<Page Include="Views\ProgramSetting.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
Reference in New Issue
Block a user