style cop wox.core whitespace changes (#5744)

* whitespace changes

* undoing csproj tweak to keep stylecop off
This commit is contained in:
Clint Rutkas 2020-08-06 16:51:47 -07:00 committed by GitHub
parent b95a1fb604
commit d7994ca67d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 54 additions and 29 deletions

View File

@ -10,6 +10,7 @@ namespace Wox.Core.Plugin
internal class ExecutablePlugin : JsonRPCPlugin internal class ExecutablePlugin : JsonRPCPlugin
{ {
private readonly ProcessStartInfo _startInfo; private readonly ProcessStartInfo _startInfo;
public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable; public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
public ExecutablePlugin(string filename) public ExecutablePlugin(string filename)

View File

@ -1,4 +1,7 @@
 // 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, /* 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 * 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. * "id" and "jsonrpc" in the request, since it's not so useful in our request model.
@ -74,25 +77,29 @@ namespace Wox.Core.Plugin
{ {
return "null"; return "null";
} }
if (parameter is string) if (parameter is string)
{ {
return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString())); return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString()));
} }
if (parameter is int || parameter is float || parameter is double) if (parameter is int || parameter is float || parameter is double)
{ {
return string.Format(@"{0}", parameter); return string.Format(@"{0}", parameter);
} }
if (parameter is bool) if (parameter is bool)
{ {
return string.Format(@"{0}", parameter.ToString().ToLower()); return string.Format(@"{0}", parameter.ToString().ToLower());
} }
return parameter.ToString(); return parameter.ToString();
} }
private string ReplaceEscapes(string str) private string ReplaceEscapes(string str)
{ {
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo return str.Replace(@"\", @"\\") // Escapes in ProcessStartInfo
.Replace(@"\", @"\\") //Escapes itself when passed to client .Replace(@"\", @"\\") // Escapes itself when passed to client
.Replace(@"""", @"\\"""""); .Replace(@"""", @"\\""""");
} }
} }

View File

@ -28,7 +28,9 @@ namespace Wox.Core.Plugin
public abstract string SupportedLanguage { get; set; } public abstract string SupportedLanguage { get; set; }
protected abstract string ExecuteQuery(Query query); protected abstract string ExecuteQuery(Query query);
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest); protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
protected abstract string ExecuteContextMenu(Result selectedResult); protected abstract string ExecuteContextMenu(Result selectedResult);
public List<Result> Query(Query query) public List<Result> Query(Query query)
@ -50,10 +52,10 @@ namespace Wox.Core.Plugin
string output = ExecuteContextMenu(selectedResult); string output = ExecuteContextMenu(selectedResult);
try try
{ {
//This should not hit. If it does it's because Wox shares the same interface for querying context menu items as well as search results. In this case please file a bug. // This should not hit. If it does it's because Wox shares the same interface for querying context menu items as well as search results. In this case please file a bug.
//To my knowledge we aren't supporting this JSonRPC commands in Launcher, and am not able to repro this, but I will leave this here for the time being in case I'm proven wrong. // To my knowledge we aren't supporting this JSonRPC commands in Launcher, and am not able to repro this, but I will leave this here for the time being in case I'm proven wrong.
//We should remove this, or identify and test officially supported use cases and Deserialize this properly. // We should remove this, or identify and test officially supported use cases and Deserialize this properly.
//return DeserializedResult(output); // return DeserializedResult(output);
throw new NotImplementedException(); throw new NotImplementedException();
} }
catch (Exception e) catch (Exception e)
@ -97,10 +99,12 @@ namespace Wox.Core.Plugin
} }
} }
} }
return !result1.JsonRPCAction.DontHideAfterAction; return !result1.JsonRPCAction.DontHideAfterAction;
}; };
results.Add(result); results.Add(result);
} }
return results; return results;
} }
else else
@ -120,7 +124,7 @@ namespace Wox.Core.Plugin
} }
catch (Exception) catch (Exception)
{ {
#if (DEBUG) #if DEBUG
{ {
throw; throw;
} }

View File

@ -12,7 +12,6 @@ using Wox.Plugin;
namespace Wox.Core.Plugin namespace Wox.Core.Plugin
{ {
internal abstract class PluginConfig internal abstract class PluginConfig
{ {
private const string PluginConfigName = "plugin.json"; private const string PluginConfigName = "plugin.json";
@ -72,8 +71,10 @@ namespace Wox.Core.Plugin
{ {
metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath)); metadata = JsonConvert.DeserializeObject<PluginMetadata>(File.ReadAllText(configPath));
metadata.PluginDirectory = pluginDirectory; metadata.PluginDirectory = pluginDirectory;
// for plugins which doesn't has ActionKeywords key // for plugins which doesn't has ActionKeywords key
metadata.ActionKeywords = metadata.ActionKeywords ?? new List<string> { metadata.ActionKeyword }; metadata.ActionKeywords = metadata.ActionKeywords ?? new List<string> { metadata.ActionKeyword };
// for plugin still use old ActionKeyword // for plugin still use old ActionKeyword
metadata.ActionKeyword = metadata.ActionKeywords?[0]; metadata.ActionKeyword = metadata.ActionKeywords?[0];
} }

View File

@ -22,6 +22,7 @@ namespace Wox.Core.Plugin
{ {
Directory.Delete(tempFolder, true); Directory.Delete(tempFolder, true);
} }
UnZip(path, tempFolder, true); UnZip(path, tempFolder, true);
string iniPath = Path.Combine(tempFolder, "plugin.json"); string iniPath = Path.Combine(tempFolder, "plugin.json");
@ -71,21 +72,21 @@ namespace Wox.Core.Plugin
{ {
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory)) if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
{ {
//when plugin is in use, we can't delete them. That's why we need to make plugin folder a random name // when plugin is in use, we can't delete them. That's why we need to make plugin folder a random name
File.Create(Path.Combine(existingPlugin.Metadata.PluginDirectory, "NeedDelete.txt")).Close(); File.Create(Path.Combine(existingPlugin.Metadata.PluginDirectory, "NeedDelete.txt")).Close();
} }
UnZip(path, newPluginPath, true); UnZip(path, newPluginPath, true);
Directory.Delete(tempFolder, true); Directory.Delete(tempFolder, true);
//existing plugins could be loaded by the application, // existing plugins could be loaded by the application,
//if we try to delete those kind of plugins, we will get a error that indicate the // if we try to delete those kind of plugins, we will get a error that indicate the
//file is been used now. // file is been used now.
//current solution is to restart wox. Ugly. // current solution is to restart wox. Ugly.
//if (MainWindow.Initialized) // if (MainWindow.Initialized)
//{ // {
// Plugins.Initialize(); // Plugins.Initialize();
//} // }
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" + if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
"Restart Wox to take effect?", "Restart Wox to take effect?",
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
@ -114,7 +115,7 @@ namespace Wox.Core.Plugin
catch (Exception) catch (Exception)
{ {
string error = $"Parse plugin config {configPath} failed: json format is not valid"; string error = $"Parse plugin config {configPath} failed: json format is not valid";
#if (DEBUG) #if DEBUG
{ {
throw new Exception(error); throw new Exception(error);
} }
@ -125,17 +126,18 @@ namespace Wox.Core.Plugin
if (!AllowedLanguage.IsAllowed(metadata.Language)) if (!AllowedLanguage.IsAllowed(metadata.Language))
{ {
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}"; string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
#if (DEBUG) #if DEBUG
{ {
throw new Exception(error); throw new Exception(error);
} }
#endif #endif
return null; return null;
} }
if (!File.Exists(metadata.ExecuteFilePath)) if (!File.Exists(metadata.ExecuteFilePath))
{ {
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist"; string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
#if (DEBUG) #if DEBUG
{ {
throw new Exception(error); throw new Exception(error);
} }
@ -192,6 +194,7 @@ namespace Wox.Core.Plugin
else else
break; break;
} }
streamWriter.Close(); streamWriter.Close();
} }
} }

View File

@ -26,8 +26,8 @@ namespace Wox.Core.Plugin
/// <summary> /// <summary>
/// Directories that will hold Wox plugin directory /// Directories that will hold Wox plugin directory
/// </summary> /// </summary>
public static List<PluginPair> AllPlugins { get; private set; } public static List<PluginPair> AllPlugins { get; private set; }
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>(); public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>(); public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
@ -255,6 +255,7 @@ namespace Wox.Core.Plugin
{ {
NonGlobalPlugins[newActionKeyword] = plugin; NonGlobalPlugins[newActionKeyword] = plugin;
} }
plugin.Metadata.ActionKeywords.Add(newActionKeyword); plugin.Metadata.ActionKeywords.Add(newActionKeyword);
} }

View File

@ -35,7 +35,6 @@ namespace Wox.Core.Plugin
{ {
var milliseconds = Stopwatch.Debug($"|PluginsLoader.CSharpPlugins|Constructor init cost for {metadata.Name}", () => var milliseconds = Stopwatch.Debug($"|PluginsLoader.CSharpPlugins|Constructor init cost for {metadata.Name}", () =>
{ {
#if DEBUG #if DEBUG
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(metadata.ExecuteFilePath); var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(metadata.ExecuteFilePath);
var types = assembly.GetTypes(); var types = assembly.GetTypes();
@ -83,6 +82,7 @@ namespace Wox.Core.Plugin
}); });
metadata.InitTime += milliseconds; metadata.InitTime += milliseconds;
} }
return plugins; return plugins;
} }

View File

@ -43,6 +43,7 @@ namespace Wox.Core.Plugin
RawQuery = rawQuery, RawQuery = rawQuery,
ActionKeyword = actionKeyword, ActionKeyword = actionKeyword,
Search = search, Search = search,
// Obsolete value initialisation // Obsolete value initialisation
ActionName = actionKeyword, ActionName = actionKeyword,
ActionParameters = actionParameters ActionParameters = actionParameters

View File

@ -12,6 +12,7 @@ namespace Wox.Core.Resource
public static class FontHelper public static class FontHelper
{ {
static FontWeightConverter fontWeightConverter = new FontWeightConverter(); static FontWeightConverter fontWeightConverter = new FontWeightConverter();
public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value) public static FontWeight GetFontWeightFromInvariantStringOrNormal(string value)
{ {
if (value == null) return FontWeights.Normal; if (value == null) return FontWeights.Normal;
@ -27,6 +28,7 @@ namespace Wox.Core.Resource
} }
static FontStyleConverter fontStyleConverter = new FontStyleConverter(); static FontStyleConverter fontStyleConverter = new FontStyleConverter();
public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value) public static FontStyle GetFontStyleFromInvariantStringOrNormal(string value)
{ {
if (value == null) return FontStyles.Normal; if (value == null) return FontStyles.Normal;
@ -42,6 +44,7 @@ namespace Wox.Core.Resource
} }
static FontStretchConverter fontStretchConverter = new FontStretchConverter(); static FontStretchConverter fontStretchConverter = new FontStretchConverter();
public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value) public static FontStretch GetFontStretchFromInvariantStringOrNormal(string value)
{ {
if (value == null) return FontStretches.Normal; if (value == null) return FontStretches.Normal;

View File

@ -19,6 +19,7 @@ namespace Wox.Core.Resource
public class Internationalization public class Internationalization
{ {
public Settings Settings { get; set; } public Settings Settings { get; set; }
private const string Folder = "Languages"; private const string Folder = "Languages";
private const string DefaultFile = "en.xaml"; private const string DefaultFile = "en.xaml";
private const string Extension = ".xaml"; private const string Extension = ".xaml";
@ -29,6 +30,7 @@ namespace Wox.Core.Resource
{ {
AddPluginLanguageDirectories(); AddPluginLanguageDirectories();
LoadDefaultLanguage(); LoadDefaultLanguage();
// we don't want to load /Languages/en.xaml twice // we don't want to load /Languages/en.xaml twice
// so add wox language directory after load plugin language files // so add wox language directory after load plugin language files
AddWoxLanguageDirectory(); AddWoxLanguageDirectory();
@ -97,6 +99,7 @@ namespace Wox.Core.Resource
{ {
LoadLanguage(language); LoadLanguage(language);
} }
UpdatePluginMetadataTranslations(); UpdatePluginMetadataTranslations();
} }

View File

@ -23,6 +23,7 @@ namespace Wox.Core.Resource
} }
} }
} }
return instance; return instance;
} }
} }

View File

@ -67,7 +67,7 @@
<ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj" /> <ProjectReference Include="..\Wox.Infrastructure\Wox.Infrastructure.csproj" />
<ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj" /> <ProjectReference Include="..\Wox.Plugin\Wox.Plugin.csproj" />
</ItemGroup> </ItemGroup>
<!-- <ItemGroup> <!--<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs"> <Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link> <Link>GlobalSuppressions.cs</Link>
</Compile> </Compile>