mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
@@ -13,6 +13,8 @@ namespace Wox.Plugin.PluginIndicator
|
||||
var results = from keyword in PluginManager.NonGlobalPlugins.Keys
|
||||
where keyword.StartsWith(query.Terms[0])
|
||||
let metadata = PluginManager.NonGlobalPlugins[keyword].Metadata
|
||||
let disabled = PluginManager.Settings.Plugins[metadata.ID].Disabled
|
||||
where !disabled
|
||||
select new Result
|
||||
{
|
||||
Title = keyword,
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace Wox.Core.Plugin
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
|
||||
public static IPublicAPI API { private set; get; }
|
||||
private static PluginsSettings _settings;
|
||||
// todo happlebao, this should not be public, the indicator function should be embeded
|
||||
public static PluginsSettings Settings;
|
||||
private static List<PluginMetadata> _metadatas;
|
||||
private static readonly string[] Directories = { Infrastructure.Wox.PreinstalledDirectory, Infrastructure.Wox.UserDirectory };
|
||||
|
||||
@@ -65,9 +66,9 @@ namespace Wox.Core.Plugin
|
||||
public static void LoadPlugins(PluginsSettings settings)
|
||||
{
|
||||
_metadatas = PluginConfig.Parse(Directories);
|
||||
_settings = settings;
|
||||
AllPlugins = PluginsLoader.Plugins(_metadatas, _settings);
|
||||
_settings.UpdatePluginSettings(AllPlugins);
|
||||
Settings = settings;
|
||||
Settings.UpdatePluginSettings(_metadatas);
|
||||
AllPlugins = PluginsLoader.Plugins(_metadatas, Settings);
|
||||
}
|
||||
public static void InitializePlugins(IPublicAPI api)
|
||||
{
|
||||
@@ -122,13 +123,14 @@ namespace Wox.Core.Plugin
|
||||
var search = rawQuery;
|
||||
List<string> actionParameters = terms.ToList();
|
||||
if (terms.Length == 0) return null;
|
||||
if (NonGlobalPlugins.ContainsKey(terms[0]))
|
||||
if (NonGlobalPlugins.ContainsKey(terms[0]) &&
|
||||
!Settings.Plugins[NonGlobalPlugins[terms[0]].Metadata.ID].Disabled)
|
||||
{
|
||||
actionKeyword = terms[0];
|
||||
actionParameters = terms.Skip(1).ToList();
|
||||
search = string.Join(Query.TermSeperater, actionParameters.ToArray());
|
||||
}
|
||||
return new Query
|
||||
var query = new Query
|
||||
{
|
||||
Terms = terms,
|
||||
RawQuery = rawQuery,
|
||||
@@ -138,6 +140,7 @@ namespace Wox.Core.Plugin
|
||||
ActionName = actionKeyword,
|
||||
ActionParameters = actionParameters
|
||||
};
|
||||
return query;
|
||||
}
|
||||
|
||||
public static List<PluginPair> ValidPluginsForQuery(Query query)
|
||||
@@ -153,41 +156,6 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
//happlebao todo dynamic release corresponding dll / exe / process
|
||||
public static void DisablePlugin(PluginPair plugin)
|
||||
{
|
||||
var actionKeywords = plugin.Metadata.ActionKeywords;
|
||||
if (actionKeywords == null || actionKeywords.Count == 0 || actionKeywords[0] == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Remove(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var actionkeyword in plugin.Metadata.ActionKeywords)
|
||||
{
|
||||
NonGlobalPlugins.Remove(actionkeyword);
|
||||
}
|
||||
}
|
||||
AllPlugins.Remove(plugin);
|
||||
}
|
||||
|
||||
public static void EnablePlugin(PluginPair plugin)
|
||||
{
|
||||
var actionKeywords = plugin.Metadata.ActionKeywords;
|
||||
if (actionKeywords == null || actionKeywords.Count == 0 || actionKeywords[0] == Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var actionkeyword in plugin.Metadata.ActionKeywords)
|
||||
{
|
||||
NonGlobalPlugins[actionkeyword] = plugin;
|
||||
}
|
||||
}
|
||||
AllPlugins.Add(plugin);
|
||||
}
|
||||
|
||||
public static List<Result> QueryForPlugin(PluginPair pair, Query query)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
|
||||
@@ -16,9 +16,8 @@ namespace Wox.Core.Plugin
|
||||
public const string Python = "python";
|
||||
public const string PythonExecutable = "pythonw.exe";
|
||||
|
||||
public static List<PluginPair> Plugins(List<PluginMetadata> source, PluginsSettings settings)
|
||||
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
|
||||
{
|
||||
var metadatas = source.Where(m => !settings.Plugins[m.ID].Disabled).ToList();
|
||||
var csharpPlugins = CSharpPlugins(metadatas).ToList();
|
||||
var pythonPlugins = PythonPlugins(metadatas, settings.PythonDirectory);
|
||||
var executablePlugins = ExecutablePlugins(metadatas);
|
||||
|
||||
@@ -10,9 +10,8 @@ namespace Wox.Core.UserSettings
|
||||
public string PythonDirectory { get; set; }
|
||||
public Dictionary<string, Plugin> Plugins { get; set; } = new Dictionary<string, Plugin>();
|
||||
|
||||
public void UpdatePluginSettings(List<PluginPair> plugins)
|
||||
public void UpdatePluginSettings(List<PluginMetadata> metadatas)
|
||||
{
|
||||
var metadatas = plugins.Select(p => p.Metadata);
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
if (Plugins.ContainsKey(metadata.ID))
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<ListBoxItem HorizontalContentAlignment="Stretch"
|
||||
IsEnabled="False"
|
||||
IsHitTestVisible="False" x:Key="FeatureBoxSeperator">
|
||||
<Separator Width="{Binding ElementName=lbPlugins, Path=ActualWidth}" />
|
||||
<Separator Width="{Binding ElementName=PluginsListBox, Path=ActualWidth}" />
|
||||
</ListBoxItem>
|
||||
<image:ImagePathConverter x:Key="ImageConverter" />
|
||||
</Window.Resources>
|
||||
@@ -62,7 +62,7 @@
|
||||
<TextBlock DockPanel.Dock="Top" Margin="10" HorizontalAlignment="Left" Cursor="Hand"
|
||||
MouseUp="tbMorePlugins_MouseUp" x:Name="tbMorePlugins" Foreground="Blue"
|
||||
Text="{DynamicResource browserMorePlugins}" />
|
||||
<ListBox x:Name="lbPlugins" Margin="10, 0, 10, 10" SelectionChanged="lbPlugins_OnSelectionChanged"
|
||||
<ListBox x:Name="PluginsListBox" Margin="10, 0, 10, 10" SelectionChanged="lbPlugins_OnSelectionChanged"
|
||||
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.IsSharedSizeScope="True">
|
||||
<ListBox.Resources>
|
||||
@@ -119,7 +119,7 @@
|
||||
<TextBlock Grid.Row="1" x:Name="pluginSubTitle" Opacity="0.5"
|
||||
ToolTip="{Binding Source=pluginSubTitle, Path=Text}"/>
|
||||
<DockPanel Grid.Row="2" Margin="0 10 0 8">
|
||||
<CheckBox x:Name="cbDisablePlugin" Click="CbDisablePlugin_OnClick">
|
||||
<CheckBox x:Name="cbDisablePlugin" Click="OnDisablePluginClicked">
|
||||
<TextBlock Text="{DynamicResource disable}" />
|
||||
</CheckBox>
|
||||
<TextBlock x:Name="pluginActionKeywordsTitle" Margin="20 0 0 0"
|
||||
|
||||
@@ -21,6 +21,7 @@ using Wox.Core.UserSettings;
|
||||
using Wox.Helper;
|
||||
using Wox.Infrastructure.Hotkey;
|
||||
using Wox.Infrastructure.Image;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
using Wox.ViewModel;
|
||||
using Stopwatch = Wox.Infrastructure.Stopwatch;
|
||||
@@ -566,7 +567,7 @@ namespace Wox
|
||||
private void lbPlugins_OnSelectionChanged(object sender, SelectionChangedEventArgs _)
|
||||
{
|
||||
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
var pair = PluginsListBox.SelectedItem as PluginPair;
|
||||
string pluginId = string.Empty;
|
||||
List<string> actionKeywords = null;
|
||||
if (pair == null) return;
|
||||
@@ -631,24 +632,19 @@ namespace Wox
|
||||
}
|
||||
}
|
||||
|
||||
private void CbDisablePlugin_OnClick(object sender, RoutedEventArgs e)
|
||||
private void OnDisablePluginClicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CheckBox cbDisabled = e.Source as CheckBox;
|
||||
if (cbDisabled == null) return;
|
||||
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
if (pair != null)
|
||||
var checkBox = (CheckBox)e.Source;
|
||||
var pair = (PluginPair)PluginsListBox.SelectedItem;
|
||||
var id = pair.Metadata.ID;
|
||||
if (checkBox.IsChecked != null)
|
||||
{
|
||||
var id = pair.Metadata.ID;
|
||||
var customizedPluginConfig = _settings.PluginSettings.Plugins[id];
|
||||
if (customizedPluginConfig.Disabled)
|
||||
{
|
||||
PluginManager.DisablePlugin(pair);
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginManager.EnablePlugin(pair);
|
||||
}
|
||||
var disabled = (bool) checkBox.IsChecked;
|
||||
_settings.PluginSettings.Plugins[id].Disabled = disabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warn($"IsChecked for checkbox is null for plugin: {pair.Metadata.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,7 +652,7 @@ namespace Wox
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
var pair = PluginsListBox.SelectedItem as PluginPair;
|
||||
if (pair != null)
|
||||
{
|
||||
//third-party plugin
|
||||
@@ -675,7 +671,7 @@ namespace Wox
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
var pair = PluginsListBox.SelectedItem as PluginPair;
|
||||
if (pair != null)
|
||||
{
|
||||
//third-party plugin
|
||||
@@ -697,7 +693,7 @@ namespace Wox
|
||||
{
|
||||
if (e.ChangedButton == MouseButton.Left)
|
||||
{
|
||||
var pair = lbPlugins.SelectedItem as PluginPair;
|
||||
var pair = PluginsListBox.SelectedItem as PluginPair;
|
||||
if (pair != null)
|
||||
{
|
||||
//third-party plugin
|
||||
@@ -729,8 +725,8 @@ namespace Wox
|
||||
Collection = PluginManager.AllPlugins
|
||||
}
|
||||
};
|
||||
lbPlugins.ItemsSource = plugins;
|
||||
lbPlugins.SelectedIndex = 0;
|
||||
PluginsListBox.ItemsSource = plugins;
|
||||
PluginsListBox.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user