Skip to content

Commit

Permalink
🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
hlaueriksson committed Aug 12, 2024
1 parent 62c6ba2 commit 6781de8
Show file tree
Hide file tree
Showing 20 changed files with 972 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Abstractions.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35122.118
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.PowerToys.Run.Plugin.Abstractions", "src\Community.PowerToys.Run.Plugin.Abstractions\Community.PowerToys.Run.Plugin.Abstractions.csproj", "{CDAA8B4A-30E2-447F-B36A-386545677F4F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Community.PowerToys.Run.Plugin.Abstractions.Tests", "tests\Community.PowerToys.Run.Plugin.Abstractions.Tests\Community.PowerToys.Run.Plugin.Abstractions.Tests.csproj", "{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Debug|ARM64.ActiveCfg = Debug|ARM64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Debug|ARM64.Build.0 = Debug|ARM64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Debug|x64.ActiveCfg = Debug|x64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Debug|x64.Build.0 = Debug|x64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Release|ARM64.ActiveCfg = Release|ARM64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Release|ARM64.Build.0 = Release|ARM64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Release|x64.ActiveCfg = Release|x64
{CDAA8B4A-30E2-447F-B36A-386545677F4F}.Release|x64.Build.0 = Release|x64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Debug|ARM64.ActiveCfg = Debug|ARM64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Debug|ARM64.Build.0 = Debug|ARM64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Debug|x64.ActiveCfg = Debug|x64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Debug|x64.Build.0 = Debug|x64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Release|ARM64.ActiveCfg = Release|ARM64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Release|ARM64.Build.0 = Release|ARM64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Release|x64.ActiveCfg = Release|x64
{C32D79E3-C01B-4B9F-A1E3-848CD80E20BE}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5DBCA627-ECA3-49D3-8747-DADC4E9D075D}
EndGlobalSection
EndGlobal
28 changes: 28 additions & 0 deletions Analyzers.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project>
<PropertyGroup>
<RunWithWarnings>true</RunWithWarnings>
<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnablePackageValidation>true</EnablePackageValidation>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="../../stylecop.json">
<Link>stylecop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.12.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>

<PropertyGroup>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
<Deterministic>true</Deterministic>
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All"/>
</ItemGroup>

</Project>
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions nuget-local.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nuget init .\src\Community.PowerToys.Run.Plugin.Abstractions\bin\ARM64\Release\ .\packages
3 changes: 3 additions & 0 deletions pack.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dotnet build .\src\Community.PowerToys.Run.Plugin.Abstractions\ -c Release /p:Platform=x64 /p:TF_BUILD=true
dotnet build .\src\Community.PowerToys.Run.Plugin.Abstractions\ -c Release /p:Platform=ARM64 /p:TF_BUILD=true
dotnet pack -c Release /p:TF_BUILD=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Platforms>x64;ARM64</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
<Version>0.1</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<Authors>Henrik Lau Eriksson</Authors>
<Description>This NuGet package simplifies the testing of PowerToys Run Plugins.

It contains interfaces and wrappers of static classes from:

- Wox.Infrastructure.dll
- Wox.Plugin.dll
</Description>
<PackageId>Community.PowerToys.Run.Plugin.Abstractions</PackageId>
<PackageProjectUrl>https://github.com/hlaueriksson/Community.PowerToys.Run.Plugin.Abstractions</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageTags>plugin;plugins;powertoys;microsoft-powertoys;powertoys-run;powertoys-run-plugin</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<Import Project="../../Analyzers.props" />

<ItemGroup>
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
<None Include="Community.PowerToys.Run.Plugin.Abstractions.props" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>

<ItemGroup>
<None Include="bin\ARM64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.dll" Pack="true" PackagePath="lib/net8.0-windows7.0/ARM64/" />
<None Include="bin\ARM64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.pdb" Pack="true" PackagePath="lib/net8.0-windows7.0/ARM64/" />
<None Include="bin\ARM64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.xml" Pack="true" PackagePath="lib/net8.0-windows7.0/ARM64/" />
</ItemGroup>

<ItemGroup>
<None Include="bin\x64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.dll" Pack="true" PackagePath="lib/net8.0-windows7.0/x64/" />
<None Include="bin\x64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.pdb" Pack="true" PackagePath="lib/net8.0-windows7.0/x64/" />
<None Include="bin\x64\Release\net8.0-windows\Community.PowerToys.Run.Plugin.Abstractions.xml" Pack="true" PackagePath="lib/net8.0-windows7.0/x64/" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Community.PowerToys.Run.Plugin.Dependencies" Version="0.83.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(Platform)' == 'ARM64'">
<Reference Include="Community.PowerToys.Run.Plugin.Abstractions.dll" HintPath="$(MSBuildThisFileDirectory)..\lib\net8.0-windows7.0\ARM64\Community.PowerToys.Run.Plugin.Abstractions.dll" />
</ItemGroup>
<ItemGroup Condition="'$(Platform)' == 'x64'">
<Reference Include="Community.PowerToys.Run.Plugin.Abstractions.dll" HintPath="$(MSBuildThisFileDirectory)..\lib\net8.0-windows7.0\x64\Community.PowerToys.Run.Plugin.Abstractions.dll" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Diagnostics;
using Wox.Infrastructure;
using static Wox.Infrastructure.Helper;

namespace Community.PowerToys.Run.Plugin.Abstractions
{
/// <summary>
/// Abstractions for <see cref="Helper" />.
/// </summary>
public interface IHelper
{
/// <inheritdoc cref="Helper.RunAsAdmin(string)"/>
void RunAsAdmin(string path);

/// <inheritdoc cref="Helper.RunAsUser(string)"/>
void RunAsUser(string path);

/// <inheritdoc cref="Helper.OpenInConsole(string)"/>
Process OpenInConsole(string path);

/// <inheritdoc cref="Helper.OpenCommandInShell(string, string, string, string, ShellRunAsType, bool)"/>
bool OpenCommandInShell(string path, string pattern, string arguments, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false);

/// <inheritdoc cref="Helper.OpenInShell(string, string, string, ShellRunAsType, bool)"/>
bool OpenInShell(string path, string? arguments = null, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false);
}

/// <inheritdoc/>
public class HelperWrapper : IHelper
{
/// <inheritdoc/>
public void RunAsAdmin(string path) =>
Helper.RunAsAdmin(path);

/// <inheritdoc/>
public void RunAsUser(string path) =>
Helper.RunAsUser(path);

/// <inheritdoc/>
public Process OpenInConsole(string path) =>
Helper.OpenInConsole(path);

/// <inheritdoc/>
public bool OpenCommandInShell(string path, string pattern, string arguments, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false) =>
Helper.OpenCommandInShell(path, pattern, arguments, workingDir, runAs, runWithHiddenWindow);

/// <inheritdoc/>
public bool OpenInShell(string path, string? arguments = null, string? workingDir = null, ShellRunAsType runAs = ShellRunAsType.None, bool runWithHiddenWindow = false) =>
Helper.OpenInShell(path, arguments, workingDir, runAs, runWithHiddenWindow);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Wox.Plugin.Common;

namespace Community.PowerToys.Run.Plugin.Abstractions
{
/// <summary>
/// Abstractions for <see cref="DefaultBrowserInfo" />.
/// </summary>
public interface IDefaultBrowserInfo
{
/// <inheritdoc cref="DefaultBrowserInfo.UpdateIfTimePassed()"/>
void UpdateIfTimePassed();
}

/// <inheritdoc/>
public class DefaultBrowserInfoWrapper : IDefaultBrowserInfo
{
/// <inheritdoc/>
public void UpdateIfTimePassed() =>
DefaultBrowserInfo.UpdateIfTimePassed();
}
}
52 changes: 52 additions & 0 deletions src/Community.PowerToys.Run.Plugin.Abstractions/Plugin/ILog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Runtime.CompilerServices;
using Wox.Plugin.Logger;

namespace Community.PowerToys.Run.Plugin.Abstractions
{
/// <summary>
/// Abstractions for <see cref="Log" />.
/// </summary>
public interface ILog
{
/// <inheritdoc cref="Log.Info(string, Type, string, string, int)"/>
void Info(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0);

/// <inheritdoc cref="Log.Debug(string, Type, string, string, int)"/>
void Debug(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0);

/// <inheritdoc cref="Log.Warn(string, Type, string, string, int)"/>
void Warn(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0);

/// <inheritdoc cref="Log.Error(string, Type, string, string, int)"/>
#pragma warning disable CA1716 // Identifiers should not match keywords
void Error(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0);
#pragma warning restore CA1716 // Identifiers should not match keywords

/// <inheritdoc cref="Log.Exception(string, Exception, Type, string, string, int)"/>
void Exception(string message, Exception ex, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0);
}

/// <inheritdoc/>
public class LogWrapper : ILog
{
/// <inheritdoc/>
public void Info(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) =>
Log.Info(message, fullClassName, methodName, sourceFilePath, sourceLineNumber);

/// <inheritdoc/>
public void Debug(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) =>
Log.Debug(message, fullClassName, methodName, sourceFilePath, sourceLineNumber);

/// <inheritdoc/>
public void Warn(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) =>
Log.Warn(message, fullClassName, methodName, sourceFilePath, sourceLineNumber);

/// <inheritdoc/>
public void Error(string message, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) =>
Log.Error(message, fullClassName, methodName, sourceFilePath, sourceLineNumber);

/// <inheritdoc/>
public void Exception(string message, Exception ex, Type fullClassName, [CallerMemberName] string methodName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) =>
Log.Exception(message, ex, fullClassName, methodName, sourceFilePath, sourceLineNumber);
}
}
8 changes: 8 additions & 0 deletions stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"documentInternalElements": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Platforms>x64;ARM64</Platforms>
<PlatformTarget>$(Platform)</PlatformTarget>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="4.10.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NLog" Version="5.0.4" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="17.2.3" />
<PackageReference Include="Verify.NUnit" Version="26.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Community.PowerToys.Run.Plugin.Abstractions\Community.PowerToys.Run.Plugin.Abstractions.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using NSubstitute;

namespace Community.PowerToys.Run.Plugin.Abstractions.Tests
{
public class MockTests
{
[Test]
public void Mock_Infrastructure_IHelper()
{
var mock = Substitute.For<IHelper>();
mock.RunAsAdmin(@"%windir%\system32\notepad.exe");
}

[Test]
public void Mock_Plugin_IDefaultBrowserInfo()
{
var mock = Substitute.For<IDefaultBrowserInfo>();
mock.UpdateIfTimePassed();
}

[Test]
public void Mock_Plugin_ILog()
{
var mock = Substitute.For<ILog>();
mock.Info("Message", GetType());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Reflection;
using FluentAssertions;

namespace Community.PowerToys.Run.Plugin.Abstractions.Tests
{
public class NamespaceTests
{
[Test]
public void Namespaces_should_be_correct()
{
var assembly = Assembly.Load("Community.PowerToys.Run.Plugin.Abstractions");
var types = assembly.GetTypes();

types.Should().AllSatisfy(x => x.Namespace.Should().Be("Community.PowerToys.Run.Plugin.Abstractions"));
}
}
}
Loading

0 comments on commit 6781de8

Please sign in to comment.