mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
[stylecop] Wox.Core - last amount needed to fully integrate (#5877)
* Looks like it was done * StyleCop enabled for WoxCore
This commit is contained in:
@@ -21,7 +21,7 @@ namespace Wox.Core.Plugin
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Json RPC Request(in query response) that client sent to Wox
|
||||
/// </summary>
|
||||
public class JsonRPCClientRequestModel : JsonRPCRequestModel
|
||||
{
|
||||
public bool DontHideAfterAction { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string rpc = base.ToString();
|
||||
return rpc + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
29
src/modules/launcher/Wox.Core/Plugin/JsonRPCErrorModel.cs
Normal file
29
src/modules/launcher/Wox.Core/Plugin/JsonRPCErrorModel.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
public class JsonRPCErrorModel
|
||||
{
|
||||
public int Code { get; set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
||||
25
src/modules/launcher/Wox.Core/Plugin/JsonRPCModelBase.cs
Normal file
25
src/modules/launcher/Wox.Core/Plugin/JsonRPCModelBase.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
public class JsonRPCModelBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,12 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
internal abstract class JsonRPCPlugin : IPlugin, IContextMenu
|
||||
{
|
||||
protected PluginInitContext context;
|
||||
protected PluginInitContext Context { get; set; }
|
||||
|
||||
public const string JsonRPC = "JsonRPC";
|
||||
|
||||
/// <summary>
|
||||
/// The language this JsonRPCPlugin support
|
||||
/// Gets or sets the language this JsonRPCPlugin support
|
||||
/// </summary>
|
||||
public abstract string SupportedLanguage { get; set; }
|
||||
|
||||
@@ -67,21 +68,27 @@ namespace Wox.Core.Plugin
|
||||
|
||||
private List<Result> DeserializedResult(string output)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(output))
|
||||
if (!string.IsNullOrEmpty(output))
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
|
||||
JsonRPCQueryResponseModel queryResponseModel = JsonConvert.DeserializeObject<JsonRPCQueryResponseModel>(output);
|
||||
if (queryResponseModel.Result == null) return null;
|
||||
if (queryResponseModel.Result == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (JsonRPCResult result in queryResponseModel.Result)
|
||||
{
|
||||
JsonRPCResult result1 = result;
|
||||
result.Action = c =>
|
||||
{
|
||||
if (result1.JsonRPCAction == null) return false;
|
||||
if (result1.JsonRPCAction == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(result1.JsonRPCAction.Method))
|
||||
if (!string.IsNullOrEmpty(result1.JsonRPCAction.Method))
|
||||
{
|
||||
if (result1.JsonRPCAction.Method.StartsWith("Wox."))
|
||||
{
|
||||
@@ -92,7 +99,7 @@ namespace Wox.Core.Plugin
|
||||
string actionResponse = ExecuteCallback(result1.JsonRPCAction);
|
||||
JsonRPCRequestModel jsonRpcRequestModel = JsonConvert.DeserializeObject<JsonRPCRequestModel>(actionResponse);
|
||||
if (jsonRpcRequestModel != null
|
||||
&& !String.IsNullOrEmpty(jsonRpcRequestModel.Method)
|
||||
&& !string.IsNullOrEmpty(jsonRpcRequestModel.Method)
|
||||
&& jsonRpcRequestModel.Method.StartsWith("Wox."))
|
||||
{
|
||||
ExecuteWoxAPI(jsonRpcRequestModel.Method.Substring(4), jsonRpcRequestModel.Parameters);
|
||||
@@ -136,18 +143,21 @@ namespace Wox.Core.Plugin
|
||||
/// <summary>
|
||||
/// Execute external program and return the output
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="arguments"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="fileName">file to execute</param>
|
||||
/// <param name="arguments">args to pass in to that exe</param>
|
||||
/// <returns>results</returns>
|
||||
protected string Execute(string fileName, string arguments)
|
||||
{
|
||||
ProcessStartInfo start = new ProcessStartInfo();
|
||||
start.FileName = fileName;
|
||||
start.Arguments = arguments;
|
||||
start.UseShellExecute = false;
|
||||
start.CreateNoWindow = true;
|
||||
start.RedirectStandardOutput = true;
|
||||
start.RedirectStandardError = true;
|
||||
ProcessStartInfo start = new ProcessStartInfo
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = arguments,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
};
|
||||
|
||||
return Execute(start);
|
||||
}
|
||||
|
||||
@@ -206,7 +216,7 @@ namespace Wox.Core.Plugin
|
||||
|
||||
public void Init(PluginInitContext ctx)
|
||||
{
|
||||
context = ctx;
|
||||
Context = ctx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
|
||||
{
|
||||
public new List<JsonRPCResult> Result { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -16,38 +16,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
public class JsonRPCErrorModel
|
||||
{
|
||||
public int Code { get; set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCModelBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCResponseModel : JsonRPCModelBase
|
||||
{
|
||||
public string Result { get; set; }
|
||||
|
||||
public JsonRPCErrorModel Error { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCQueryResponseModel : JsonRPCResponseModel
|
||||
{
|
||||
public new List<JsonRPCResult> Result { get; set; }
|
||||
}
|
||||
|
||||
public class JsonRPCRequestModel : JsonRPCModelBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
@@ -103,40 +75,4 @@ namespace Wox.Core.Plugin
|
||||
.Replace(@"""", @"\\""""");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Json RPC Request that Wox sent to client
|
||||
/// </summary>
|
||||
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
string rpc = base.ToString();
|
||||
return rpc + "}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Json RPC Request(in query response) that client sent to Wox
|
||||
/// </summary>
|
||||
public class JsonRPCClientRequestModel : JsonRPCRequestModel
|
||||
{
|
||||
public bool DontHideAfterAction { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string rpc = base.ToString();
|
||||
return rpc + "}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represent the json-rpc result item that client send to Wox
|
||||
/// Typically, we will send back this request model to client after user select the result item
|
||||
/// But if the request method starts with "Wox.", we will invoke the public APIs we expose.
|
||||
/// </summary>
|
||||
public class JsonRPCResult : Result
|
||||
{
|
||||
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
|
||||
}
|
||||
}
|
||||
27
src/modules/launcher/Wox.Core/Plugin/JsonRPCResponseModel.cs
Normal file
27
src/modules/launcher/Wox.Core/Plugin/JsonRPCResponseModel.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
public class JsonRPCResponseModel : JsonRPCModelBase
|
||||
{
|
||||
public string Result { get; set; }
|
||||
|
||||
public JsonRPCErrorModel Error { get; set; }
|
||||
}
|
||||
}
|
||||
32
src/modules/launcher/Wox.Core/Plugin/JsonRPCResult.cs
Normal file
32
src/modules/launcher/Wox.Core/Plugin/JsonRPCResult.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
using Wox.Plugin;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent the json-rpc result item that client send to Wox
|
||||
/// Typically, we will send back this request model to client after user select the result item
|
||||
/// But if the request method starts with "Wox.", we will invoke the public APIs we expose.
|
||||
/// </summary>
|
||||
public class JsonRPCResult : Result
|
||||
{
|
||||
public JsonRPCClientRequestModel JsonRPCAction { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
/* We basically follow the Json-RPC 2.0 spec (http://www.jsonrpc.org/specification) to invoke methods between Wox and other plugins,
|
||||
* like python or other self-execute program. But, we added additional infos (proxy and so on) into rpc request. Also, we didn't use the
|
||||
* "id" and "jsonrpc" in the request, since it's not so useful in our request model.
|
||||
*
|
||||
* When execute a query:
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCQueryResponseModel--------- client
|
||||
*
|
||||
* When execute a action (which mean user select an item in reulst item):
|
||||
* Wox -------JsonRPCServerRequestModel--------> client
|
||||
* Wox <------JsonRPCResponseModel-------------- client
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
/// <summary>
|
||||
/// Json RPC Request that Wox sent to client
|
||||
/// </summary>
|
||||
public class JsonRPCServerRequestModel : JsonRPCRequestModel
|
||||
{
|
||||
public override string ToString()
|
||||
{
|
||||
string rpc = base.ToString();
|
||||
return rpc + "}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
@@ -20,8 +20,8 @@ namespace Wox.Core.Plugin
|
||||
/// <summary>
|
||||
/// Parse plugin metadata in giving directories
|
||||
/// </summary>
|
||||
/// <param name="pluginDirectories"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="pluginDirectories">directories with plugins</param>
|
||||
/// <returns>List with plugin meta data</returns>
|
||||
public static List<PluginMetadata> Parse(string[] pluginDirectories)
|
||||
{
|
||||
PluginMetadatas.Clear();
|
||||
|
||||
@@ -87,9 +87,7 @@ namespace Wox.Core.Plugin
|
||||
// {
|
||||
// Plugins.Initialize();
|
||||
// }
|
||||
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||
"Restart Wox to take effect?",
|
||||
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine} Restart Wox to take effect?", "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||
{
|
||||
PluginManager.API.RestartApp();
|
||||
}
|
||||
@@ -119,8 +117,9 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
throw new Exception(error);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
@@ -130,8 +129,9 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
throw new Exception(error);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
@@ -141,8 +141,9 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
throw new Exception(error);
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
return metadata;
|
||||
@@ -156,10 +157,15 @@ namespace Wox.Core.Plugin
|
||||
/// <param name="overWrite">overwrite</param>
|
||||
private static void UnZip(string zippedFile, string strDirectory, bool overWrite)
|
||||
{
|
||||
if (strDirectory == "")
|
||||
if (strDirectory == string.Empty)
|
||||
{
|
||||
strDirectory = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
if (!strDirectory.EndsWith("\\"))
|
||||
strDirectory = strDirectory + "\\";
|
||||
{
|
||||
strDirectory += "\\";
|
||||
}
|
||||
|
||||
using (ZipInputStream s = new ZipInputStream(File.OpenRead(zippedFile)))
|
||||
{
|
||||
@@ -167,18 +173,20 @@ namespace Wox.Core.Plugin
|
||||
|
||||
while ((theEntry = s.GetNextEntry()) != null)
|
||||
{
|
||||
string directoryName = "";
|
||||
string pathToZip = "";
|
||||
string directoryName = string.Empty;
|
||||
string pathToZip = string.Empty;
|
||||
pathToZip = theEntry.Name;
|
||||
|
||||
if (pathToZip != "")
|
||||
if (pathToZip != string.Empty)
|
||||
{
|
||||
directoryName = Path.GetDirectoryName(pathToZip) + "\\";
|
||||
}
|
||||
|
||||
string fileName = Path.GetFileName(pathToZip);
|
||||
|
||||
Directory.CreateDirectory(strDirectory + directoryName);
|
||||
|
||||
if (fileName != "")
|
||||
if (fileName != string.Empty)
|
||||
{
|
||||
if ((File.Exists(strDirectory + directoryName + fileName) && overWrite) || (!File.Exists(strDirectory + directoryName + fileName)))
|
||||
{
|
||||
@@ -190,9 +198,13 @@ namespace Wox.Core.Plugin
|
||||
int size = s.Read(data, 0, data.Length);
|
||||
|
||||
if (size > 0)
|
||||
{
|
||||
streamWriter.Write(data, 0, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
streamWriter.Close();
|
||||
|
||||
@@ -24,20 +24,20 @@ namespace Wox.Core.Plugin
|
||||
private static IEnumerable<PluginPair> _contextMenuPlugins = new List<PluginPair>();
|
||||
|
||||
/// <summary>
|
||||
/// Directories that will hold Wox plugin directory
|
||||
/// Gets directories that will hold Wox plugin directory
|
||||
/// </summary>
|
||||
public static List<PluginPair> AllPlugins { get; private set; }
|
||||
|
||||
public static IPublicAPI API { get; private set; }
|
||||
|
||||
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
|
||||
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
|
||||
|
||||
public static IPublicAPI API { private set; get; }
|
||||
|
||||
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.PluginsDirectory };
|
||||
|
||||
// todo happlebao, this should not be public, the indicator function should be embedded
|
||||
public static PluginSettings Settings;
|
||||
public static PluginSettings Settings { get; set; }
|
||||
|
||||
private static List<PluginMetadata> _metadatas;
|
||||
private static readonly string[] Directories = { Constant.PreinstalledDirectory, Constant.PluginsDirectory };
|
||||
|
||||
private static void ValidateUserDirectory()
|
||||
{
|
||||
@@ -74,7 +74,7 @@ namespace Wox.Core.Plugin
|
||||
/// because InitializePlugins needs API, so LoadPlugins needs to be called first
|
||||
/// todo happlebao The API should be removed
|
||||
/// </summary>
|
||||
/// <param name="settings"></param>
|
||||
/// <param name="settings">Plugin settings</param>
|
||||
public static void LoadPlugins(PluginSettings settings)
|
||||
{
|
||||
_metadatas = PluginConfig.Parse(Directories);
|
||||
@@ -86,7 +86,6 @@ namespace Wox.Core.Plugin
|
||||
/// <summary>
|
||||
/// Call initialize for all plugins
|
||||
/// </summary>
|
||||
/// <returns>return the list of failed to init plugins or null for none</returns>
|
||||
public static void InitializePlugins(IPublicAPI api)
|
||||
{
|
||||
API = api;
|
||||
@@ -100,7 +99,7 @@ namespace Wox.Core.Plugin
|
||||
pair.Plugin.Init(new PluginInitContext
|
||||
{
|
||||
CurrentPluginMetadata = pair.Metadata,
|
||||
API = API
|
||||
API = API,
|
||||
});
|
||||
});
|
||||
pair.Metadata.InitTime += milliseconds;
|
||||
@@ -118,7 +117,9 @@ namespace Wox.Core.Plugin
|
||||
foreach (var plugin in AllPlugins)
|
||||
{
|
||||
if (IsGlobalPlugin(plugin.Metadata))
|
||||
{
|
||||
GlobalPlugins.Add(plugin);
|
||||
}
|
||||
|
||||
// Plugins may have multiple ActionKeywords, eg. WebSearch
|
||||
plugin.Metadata.ActionKeywords.Where(x => x != Query.GlobalPluginWildcardSign)
|
||||
@@ -129,7 +130,7 @@ namespace Wox.Core.Plugin
|
||||
if (failedPlugins.Any())
|
||||
{
|
||||
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
|
||||
API.ShowMsg($"Fail to Init Plugins", $"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help", "", false);
|
||||
API.ShowMsg($"Fail to Init Plugins", $"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help", string.Empty, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,14 +192,15 @@ namespace Wox.Core.Plugin
|
||||
/// <summary>
|
||||
/// get specified plugin, return null if not found
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="id">id of plugin</param>
|
||||
/// <returns>plugin</returns>
|
||||
public static PluginPair GetPluginForId(string id)
|
||||
{
|
||||
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||
}
|
||||
|
||||
public static IEnumerable<PluginPair> GetPluginsForInterface<T>() where T : IFeatures
|
||||
public static IEnumerable<PluginPair> GetPluginsForInterface<T>()
|
||||
where T : IFeatures
|
||||
{
|
||||
return AllPlugins.Where(p => p.Plugin is T);
|
||||
}
|
||||
@@ -278,7 +280,9 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
|
||||
if (oldActionkeyword != Query.GlobalPluginWildcardSign)
|
||||
{
|
||||
NonGlobalPlugins.Remove(oldActionkeyword);
|
||||
}
|
||||
|
||||
plugin.Metadata.ActionKeywords.Remove(oldActionkeyword);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Wox.Plugin;
|
||||
|
||||
@@ -48,9 +47,10 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception($"|PluginsLoader.CSharpPlugins|Couldn't load assembly for {metadata.Name}", e);
|
||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Couldn't load assembly for {metadata.Name}", e);
|
||||
return;
|
||||
}
|
||||
|
||||
var types = assembly.GetTypes();
|
||||
Type type;
|
||||
try
|
||||
@@ -59,9 +59,10 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (InvalidOperationException e)
|
||||
{
|
||||
Log.Exception($"|PluginsLoader.CSharpPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e);
|
||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Can't find class implement IPlugin for <{metadata.Name}>", e);
|
||||
return;
|
||||
}
|
||||
|
||||
IPlugin plugin;
|
||||
try
|
||||
{
|
||||
@@ -69,14 +70,14 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Exception($"|PluginsLoader.CSharpPlugins|Can't create instance for <{metadata.Name}>", e);
|
||||
Infrastructure.Logger.Log.Exception($"|PluginsLoader.CSharpPlugins|Can't create instance for <{metadata.Name}>", e);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
PluginPair pair = new PluginPair
|
||||
{
|
||||
Plugin = plugin,
|
||||
Metadata = metadata
|
||||
Metadata = metadata,
|
||||
};
|
||||
plugins.Add(pair);
|
||||
});
|
||||
@@ -93,7 +94,7 @@ namespace Wox.Core.Plugin
|
||||
var plugins = metadatas.Select(metadata => new PluginPair
|
||||
{
|
||||
Plugin = new ExecutablePlugin(metadata.ExecuteFilePath),
|
||||
Metadata = metadata
|
||||
Metadata = metadata,
|
||||
});
|
||||
return plugins;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Wox.Core.Plugin
|
||||
|
||||
// Obsolete value initialisation
|
||||
ActionName = actionKeyword,
|
||||
ActionParameters = actionParameters
|
||||
ActionParameters = actionParameters,
|
||||
};
|
||||
|
||||
return query;
|
||||
|
||||
@@ -8,24 +8,41 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
internal static class AvailableLanguages
|
||||
{
|
||||
public static Language English = new Language("en", "English");
|
||||
public static Language Chinese = new Language("zh-cn", "中文");
|
||||
public static Language Chinese_TW = new Language("zh-tw", "中文(繁体)");
|
||||
public static Language Ukrainian = new Language("uk-UA", "Українська");
|
||||
public static Language Russian = new Language("ru", "Русский");
|
||||
public static Language French = new Language("fr", "Français");
|
||||
public static Language Japanese = new Language("ja", "日本語");
|
||||
public static Language Dutch = new Language("nl", "Dutch");
|
||||
public static Language Polish = new Language("pl", "Polski");
|
||||
public static Language Danish = new Language("da", "Dansk");
|
||||
public static Language German = new Language("de", "Deutsch");
|
||||
public static Language Korean = new Language("ko", "한국어");
|
||||
public static Language Serbian = new Language("sr", "Srpski");
|
||||
public static Language Portuguese_BR = new Language("pt-br", "Português (Brasil)");
|
||||
public static Language Italian = new Language("it", "Italiano");
|
||||
public static Language Norwegian_Bokmal = new Language("nb-NO", "Norsk Bokmål");
|
||||
public static Language Slovak = new Language("sk", "Slovenský");
|
||||
public static Language Turkish = new Language("tr", "Türkçe");
|
||||
public static Language English { get; set; } = new Language("en", "English");
|
||||
|
||||
public static Language Chinese { get; set; } = new Language("zh-cn", "中文");
|
||||
|
||||
public static Language Chinese_TW { get; set; } = new Language("zh-tw", "中文(繁体)");
|
||||
|
||||
public static Language Ukrainian { get; set; } = new Language("uk-UA", "Українська");
|
||||
|
||||
public static Language Russian { get; set; } = new Language("ru", "Русский");
|
||||
|
||||
public static Language French { get; set; } = new Language("fr", "Français");
|
||||
|
||||
public static Language Japanese { get; set; } = new Language("ja", "日本語");
|
||||
|
||||
public static Language Dutch { get; set; } = new Language("nl", "Dutch");
|
||||
|
||||
public static Language Polish { get; set; } = new Language("pl", "Polski");
|
||||
|
||||
public static Language Danish { get; set; } = new Language("da", "Dansk");
|
||||
|
||||
public static Language German { get; set; } = new Language("de", "Deutsch");
|
||||
|
||||
public static Language Korean { get; set; } = new Language("ko", "한국어");
|
||||
|
||||
public static Language Serbian { get; set; } = new Language("sr", "Srpski");
|
||||
|
||||
public static Language Portuguese_BR { get; set; } = new Language("pt-br", "Português (Brasil)");
|
||||
|
||||
public static Language Italian { get; set; } = new Language("it", "Italiano");
|
||||
|
||||
public static Language Norwegian_Bokmal { get; set; } = new Language("nb-NO", "Norsk Bokmål");
|
||||
|
||||
public static Language Slovak { get; set; } = new Language("sk", "Slovenský");
|
||||
|
||||
public static Language Turkish { get; set; } = new Language("tr", "Türkçe");
|
||||
|
||||
public static List<Language> GetAvailableLanguages()
|
||||
{
|
||||
@@ -48,7 +65,7 @@ namespace Wox.Core.Resource
|
||||
Italian,
|
||||
Norwegian_Bokmal,
|
||||
Slovak,
|
||||
Turkish
|
||||
Turkish,
|
||||
};
|
||||
return languages;
|
||||
}
|
||||
|
||||
@@ -11,15 +11,18 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
public static class FontHelper
|
||||
{
|
||||
static FontWeightConverter fontWeightConverter = new FontWeightConverter();
|
||||
private static readonly FontWeightConverter _fontWeightConverter = new FontWeightConverter();
|
||||
|
||||
public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value)
|
||||
{
|
||||
if (value == null) return FontWeights.Normal;
|
||||
if (value == null)
|
||||
{
|
||||
return FontWeights.Normal;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (FontWeight)fontWeightConverter.ConvertFromInvariantString(value);
|
||||
return (FontWeight)_fontWeightConverter.ConvertFromInvariantString(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -27,15 +30,18 @@ namespace Wox.Core.Resource
|
||||
}
|
||||
}
|
||||
|
||||
static FontStyleConverter fontStyleConverter = new FontStyleConverter();
|
||||
private static readonly FontStyleConverter _fontStyleConverter = new FontStyleConverter();
|
||||
|
||||
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value)
|
||||
{
|
||||
if (value == null) return FontStyles.Normal;
|
||||
if (value == null)
|
||||
{
|
||||
return FontStyles.Normal;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (FontStyle)fontStyleConverter.ConvertFromInvariantString(value);
|
||||
return (FontStyle)_fontStyleConverter.ConvertFromInvariantString(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -43,14 +49,18 @@ namespace Wox.Core.Resource
|
||||
}
|
||||
}
|
||||
|
||||
static FontStretchConverter fontStretchConverter = new FontStretchConverter();
|
||||
private static readonly FontStretchConverter _fontStretchConverter = new FontStretchConverter();
|
||||
|
||||
public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value)
|
||||
{
|
||||
if (value == null) return FontStretches.Normal;
|
||||
if (value == null)
|
||||
{
|
||||
return FontStretches.Normal;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (FontStretch)fontStretchConverter.ConvertFromInvariantString(value);
|
||||
return (FontStretch)_fontStretchConverter.ConvertFromInvariantString(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -62,9 +72,9 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
return family.FamilyTypefaces.OrderBy(o =>
|
||||
{
|
||||
return Math.Abs(o.Stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * 100 +
|
||||
return (Math.Abs(o.Stretch.ToOpenTypeStretch() - FontStretches.Normal.ToOpenTypeStretch()) * 100) +
|
||||
Math.Abs(o.Weight.ToOpenTypeWeight() - FontWeights.Normal.ToOpenTypeWeight()) +
|
||||
(o.Style == FontStyles.Normal ? 0 : o.Style == FontStyles.Oblique ? 1 : 2) * 1000;
|
||||
((o.Style == FontStyles.Normal ? 0 : o.Style == FontStyles.Oblique ? 1 : 2) * 1000);
|
||||
}).FirstOrDefault() ?? family.FamilyTypefaces.FirstOrDefault();
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,19 @@ namespace Wox.Core.Resource
|
||||
var languageToSet = GetLanguageByLanguageCode(languageCodeToSet);
|
||||
|
||||
if (Settings.ShouldUsePinyin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (languageToSet != AvailableLanguages.Chinese && languageToSet != AvailableLanguages.Chinese_TW)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Do you want to turn on search with Pinyin?", string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -143,7 +149,7 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
var r = new ResourceDictionary
|
||||
{
|
||||
Source = new Uri(f, UriKind.Absolute)
|
||||
Source = new Uri(f, UriKind.Absolute),
|
||||
};
|
||||
dicts.Add(r);
|
||||
_oldResources.Add(r);
|
||||
@@ -174,8 +180,11 @@ namespace Wox.Core.Resource
|
||||
{
|
||||
foreach (var p in PluginManager.GetPluginsForInterface<IPluginI18n>())
|
||||
{
|
||||
var pluginI18N = p.Plugin as IPluginI18n;
|
||||
if (pluginI18N == null) return;
|
||||
if (!(p.Plugin is IPluginI18n pluginI18N))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
p.Metadata.Name = pluginI18N.GetTranslatedPluginTitle();
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj" />
|
||||
</ItemGroup>
|
||||
<!--<ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
|
||||
<Link>GlobalSuppressions.cs</Link>
|
||||
</Compile>
|
||||
@@ -81,5 +81,5 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>-->
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user