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