Porting to Flow

This commit is contained in:
Kevin Zhang 2021-07-19 16:32:57 +08:00
parent e223d13f24
commit 89ef3a97bf
8 changed files with 46 additions and 88 deletions

View file

@ -5,10 +5,8 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Input;
using Flow.Launcher.Plugin;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{
@ -24,23 +22,18 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
/// <param name="result">The result for the context menu entires</param>
/// <param name="assemblyName">The name of the this assembly</param>
/// <returns>A list with context menu entries</returns>
internal static List<ContextMenuResult> GetContextMenu(in Result result, in string assemblyName)
internal static List<Result> GetContextMenu(in Result result, in string assemblyName)
{
if (!(result?.ContextData is WindowsSetting entry))
if (result?.ContextData is not WindowsSetting entry)
{
return new List<ContextMenuResult>(0);
return new List<Result>(0);
}
var list = new List<ContextMenuResult>(1)
var list = new List<Result>(1)
{
new ContextMenuResult
new()
{
AcceleratorKey = Key.C,
AcceleratorModifiers = ModifierKeys.Control,
Action = _ => TryToCopyToClipBoard(entry.Command),
FontFamily = "Segoe MDL2 Assets",
Glyph = "\xE8C8", // E8C8 => Symbol: Copy
PluginName = assemblyName,
Title = $"{Resources.CopyCommand} (Ctrl+C)",
},
};

View file

@ -9,7 +9,6 @@ using System.Linq;
using System.Reflection;
using System.Text.Json;
using System.Text.Json.Serialization;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{

View file

@ -7,9 +7,8 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Flow.Launcher.Plugin;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
using Wox.Plugin;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{
@ -80,7 +79,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
toolTipText.Append($"{Resources.Note}: {entry.Note}");
}
result.ToolTipData = new ToolTipData(entry.Name, toolTipText.ToString());
result.TitleToolTip = toolTipText.ToString();
}
/// <summary>

View file

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{

View file

@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Wox.Plugin.Logger;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper
{

24
Log.cs Normal file
View file

@ -0,0 +1,24 @@
using System;
using System.Runtime.CompilerServices;
using Flow.Launcher.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
{
public static class Log
{
private static IPublicAPI _api;
public static void Init(IPublicAPI api)
{
_api = api;
}
public static void Exception(string message, Exception exception, Type type, [CallerMemberName] string methodName = "")
{
_api.LogException(type.FullName, message, exception, methodName);
}
public static void Warn(string message, Type type, [CallerMemberName] string methodName = "")
{
_api.LogWarn(type.FullName, message, methodName);
}
}
}

39
Main.cs
View file

@ -6,17 +6,16 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ManagedCommon;
using Flow.Launcher.Plugin;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Helper;
using Microsoft.PowerToys.Run.Plugin.WindowsSettings.Properties;
using Wox.Plugin;
namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
{
/// <summary>
/// Main class of this plugin that implement all used interfaces.
/// </summary>
public class Main : IPlugin, IContextMenu, IPluginI18n, IDisposable
public sealed class Main : IPlugin, IContextMenu, IPluginI18n, IDisposable
{
/// <summary>
/// The path to the symbol for a light theme.
@ -79,8 +78,6 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
public void Init(PluginInitContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_context.API.ThemeChanged += OnThemeChanged;
UpdateIconPath(_context.API.GetCurrentTheme());
_settingsList = JsonSettingsListHelper.ReadAllPossibleSettings();
_settingsList = UnsupportedSettingsHelper.FilterByBuild(_settingsList);
@ -126,7 +123,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
return true;
}
if (!(found.AltNames is null))
if (found.AltNames is not null)
{
foreach (var altName in found.AltNames)
{
@ -146,7 +143,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
/// </summary>
/// <param name="selectedResult">The <see cref="Result"/> for the list with context menu entries.</param>
/// <returns>A list context menu entries.</returns>
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
public List<Result> LoadContextMenus(Result selectedResult)
{
return ContextMenuHelper.GetContextMenu(selectedResult, _assemblyName);
}
@ -162,18 +159,13 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
/// Wrapper method for <see cref="Dispose"/> that dispose additional objects and events form the plugin itself.
/// </summary>
/// <param name="disposing">Indicate that the plugin is disposed.</param>
protected virtual void Dispose(bool disposing)
private void Dispose(bool disposing)
{
if (_disposed || !disposing)
{
return;
}
if (_context != null && _context.API != null)
{
_context.API.ThemeChanged -= OnThemeChanged;
}
_disposed = true;
}
@ -192,26 +184,5 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsSettings
{
return Description;
}
/// <summary>
/// Change all theme-based elements (typical called when the plugin theme has changed).
/// </summary>
/// <param name="oldtheme">The old <see cref="Theme"/>.</param>
/// <param name="newTheme">The new <see cref="Theme"/>.</param>
private void OnThemeChanged(Theme oldtheme, Theme newTheme)
{
UpdateIconPath(newTheme);
}
/// <summary>
/// Update all icons (typical called when the plugin theme has changed).
/// </summary>
/// <param name="theme">The new <see cref="Theme"/> for the icons.</param>
private void UpdateIconPath(Theme theme)
{
_defaultIconPath = theme == Theme.Light || theme == Theme.HighContrastWhite
? _lightSymbol
: _darkSymbol;
}
}
}

View file

@ -1,13 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Import Project="..\..\..\..\Version.props" />
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0-windows</TargetFramework>
<ProjectGuid>{5043CECE-E6A7-4867-9CBE-02D27D83747A}</ProjectGuid>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.PowerToys.Run.Plugin.WindowsSettings</RootNamespace>
<AssemblyName>Microsoft.PowerToys.Run.Plugin.WindowsSettings</AssemblyName>
<Version>$(Version).0</Version>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<Platforms>x64</Platforms>
@ -18,12 +15,11 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<OutputPath>..\..\..\..\..\x64\Debug\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.WindowsSettings\</OutputPath>
<OutputPath>Debug\WindowsSettings\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>false</Optimize>
<DebugType>full</DebugType>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<LangVersion>8.0</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
@ -31,11 +27,10 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutputPath>..\..\..\..\..\x64\Release\modules\launcher\Plugins\Microsoft.PowerToys.Run.Plugin.WindowsSettings\</OutputPath>
<OutputPath>Release\WindowsSettings\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<LangVersion>8.0</LangVersion>
<DebugType>portable</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
@ -46,29 +41,12 @@
<None Remove="WindowsSettings.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Wox.Infrastructure\Wox.Infrastructure.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="WindowsSettings.json">
@ -76,14 +54,6 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
@ -108,4 +78,8 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Flow.Launcher.Plugin" Version="2.0.0" />
</ItemGroup>
</Project>