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
{
private readonly ProcessStartInfo _startInfo;
public override string SupportedLanguage { get; set; } = AllowedLanguage.Executable;
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,
* 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.
@ -74,25 +77,29 @@ namespace Wox.Core.Plugin
{
return "null";
}
if (parameter is string)
{
return string.Format(@"\""{0}\""", ReplaceEscapes(parameter.ToString()));
}
if (parameter is int || parameter is float || parameter is double)
{
return string.Format(@"{0}", parameter);
}
if (parameter is bool)
{
return string.Format(@"{0}", parameter.ToString().ToLower());
}
return parameter.ToString();
}
private string ReplaceEscapes(string str)
{
return str.Replace(@"\", @"\\") //Escapes in ProcessStartInfo
.Replace(@"\", @"\\") //Escapes itself when passed to client
return str.Replace(@"\", @"\\") // Escapes in ProcessStartInfo
.Replace(@"\", @"\\") // Escapes itself when passed to client
.Replace(@"""", @"\\""""");
}
}

View File

@ -28,7 +28,9 @@ namespace Wox.Core.Plugin
public abstract string SupportedLanguage { get; set; }
protected abstract string ExecuteQuery(Query query);
protected abstract string ExecuteCallback(JsonRPCRequestModel rpcRequest);
protected abstract string ExecuteContextMenu(Result selectedResult);
public List<Result> Query(Query query)
@ -50,10 +52,10 @@ namespace Wox.Core.Plugin
string output = ExecuteContextMenu(selectedResult);
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.
//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.
//return DeserializedResult(output);
// 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.
// We should remove this, or identify and test officially supported use cases and Deserialize this properly.
// return DeserializedResult(output);
throw new NotImplementedException();
}
catch (Exception e)
@ -97,10 +99,12 @@ namespace Wox.Core.Plugin
}
}
}
return !result1.JsonRPCAction.DontHideAfterAction;
};
results.Add(result);
}
return results;
}
else
@ -120,7 +124,7 @@ namespace Wox.Core.Plugin
}
catch (Exception)
{
#if (DEBUG)
#if DEBUG
{
throw;
}

View File

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

View File

@ -22,6 +22,7 @@ namespace Wox.Core.Plugin
{
Directory.Delete(tempFolder, true);
}
UnZip(path, tempFolder, true);
string iniPath = Path.Combine(tempFolder, "plugin.json");
@ -71,21 +72,21 @@ namespace Wox.Core.Plugin
{
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();
}
UnZip(path, newPluginPath, true);
Directory.Delete(tempFolder, true);
//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
//file is been used now.
//current solution is to restart wox. Ugly.
//if (MainWindow.Initialized)
//{
// 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
// file is been used now.
// current solution is to restart wox. Ugly.
// if (MainWindow.Initialized)
// {
// 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)
@ -114,7 +115,7 @@ namespace Wox.Core.Plugin
catch (Exception)
{
string error = $"Parse plugin config {configPath} failed: json format is not valid";
#if (DEBUG)
#if DEBUG
{
throw new Exception(error);
}
@ -125,17 +126,18 @@ namespace Wox.Core.Plugin
if (!AllowedLanguage.IsAllowed(metadata.Language))
{
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
#if (DEBUG)
#if DEBUG
{
throw new Exception(error);
}
#endif
return null;
}
if (!File.Exists(metadata.ExecuteFilePath))
{
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
#if (DEBUG)
#if DEBUG
{
throw new Exception(error);
}
@ -192,6 +194,7 @@ namespace Wox.Core.Plugin
else
break;
}
streamWriter.Close();
}
}

View File

@ -26,8 +26,8 @@ namespace Wox.Core.Plugin
/// <summary>
/// Directories that will hold Wox plugin directory
/// </summary>
public static List<PluginPair> AllPlugins { get; private set; }
public static readonly List<PluginPair> GlobalPlugins = new List<PluginPair>();
public static readonly Dictionary<string, PluginPair> NonGlobalPlugins = new Dictionary<string, PluginPair>();
@ -255,6 +255,7 @@ namespace Wox.Core.Plugin
{
NonGlobalPlugins[newActionKeyword] = plugin;
}
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}", () =>
{
#if DEBUG
var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(metadata.ExecuteFilePath);
var types = assembly.GetTypes();
@ -83,6 +82,7 @@ namespace Wox.Core.Plugin
});
metadata.InitTime += milliseconds;
}
return plugins;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -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>