Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PT Run] System plugin: Add IP and MAC #17023

Merged
merged 19 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ dllhost
dllmain
dlls
DNLEN
Dns
doctype
DONOTROUND
DONTVALIDATEPATH
Expand Down Expand Up @@ -625,6 +626,8 @@ gabime
GAC
gacutil
GBarm
Gbits
Gbps
GBs
GCLP
gcnew
Expand Down Expand Up @@ -912,6 +915,7 @@ IPrincipal
IProgram
IProperty
IPublic
IPv
IQuery
IRead
IReference
Expand Down Expand Up @@ -1146,6 +1150,7 @@ Mato
MAXIMIZEBOX
MAXSHORTCUTSIZE
maxversiontested
Mbits
MBs
mdtext
mdtxt
Expand Down Expand Up @@ -2077,6 +2082,7 @@ UNCPRIORITY
undef
UNDNAME
unescape
Unicast
Unindent
Uninitialize
uninstall
Expand Down Expand Up @@ -2261,6 +2267,7 @@ WIXUI
WKSG
Wlkr
wmain
Wman
WMKEYDOWN
WMKEYUP
wmp
Expand Down Expand Up @@ -2303,6 +2310,7 @@ WTSAT
Wubi
WVC
Wwan
Wwanpp
xamarin
XAttribute
xbf
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/spell-check/patterns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ TestCase\("[^"]+"
\[DataRow\("[0-9A-F]{6}", \d{3}.\d{1}, \d{3}.\d{1}, \d{3}.\d{1}\)\]
\[DataRow\("[0-9A-F]{6}", "[BCGMRY]\d\d?", \d{3}, \d{3}\)\]

# version suffix <word>v#
[Vv]\d+(?:\b|(?=[a-zA-Z_]))

# Windows paths
\\native
\\netcoreapp
\\netstandard
\\network
\\notifications
\\recyclebin
\\Registry
Expand Down
33 changes: 33 additions & 0 deletions doc/devdocs/modules/launcher/plugins/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Available commands:
* Hibernate
* Empty Recycle Bin
* UEFI Firmware Settings (Only available on systems, that boot in UEFI mode.)
* IP / MAC / Address => Show informations about network connections.

## Optional plugin settings

Expand All @@ -24,6 +25,7 @@ Available commands:
|--------------|-----------|------------|
| `ConfirmSystemCommands` | `false` | Show a dialog to confirm system commands |
| `LocalizeSystemCommands` | `true` | Use localized system commands instead of English ones |
| `ReduceNetworkResultScore` | `true` | Reduce the priority of 'IP' and 'MAC' results to improve the order in the global results |

* The optional plugin settings are implemented via the [`ISettingProvider`](/src/modules/launcher/Wox.Plugin/ISettingProvider.cs) interface from `Wox.Plugin` project. All available settings for the plugin are defined in the [`Main`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Main.cs) class of the plugin.

Expand All @@ -35,12 +37,43 @@ Available commands:

* While parsing, the plugin uses [`FuzzyMatch`](/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs) to get characters matching a result in the list.

### [`Commands.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs)
- The [`Commands`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/Commands.cs) class contains the definition of all available commands/results.

### [`ResultHelper.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs)
- The [`ResultHelper`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/ResultHelper.cs) class contains methods for working with the results and some of the result features (tool tip, copy to clipboard, execute command).

### [`NetworkConnectionProperties.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs)
- The [`NetworkConnectionProperties`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/NetworkConnectionProperties.cs) class contains methods to get the properties of a network interface/connection.
- An instance of this class collects/provides all required informations about one connection/adapter.

### [`SystemPluginContext.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs)
- An instance of the class [`SystemPluginContext`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System/Components/SystemPluginContext.cs) contains/defines the context data of a system plugin result. We select the context menu based on the defined properties.
- It is used for the `ContextData` property of the [`Wox.Plugin.Result`](/src/modules/launcher/Wox.Plugin/Result.cs).


### UEFI command

* The UEFI command is only available on systems, that boot in UEFI mode.

* This is validated by checking the result of the method [`GetSystemFirmwareType`](/src/modules/launcher/Wox.Plugin/Common/Win32/Win32Helpers.cs), which uses the native method [`GetFirmwareType`](/src/modules/launcher/Wox.Plugin/Common/Win32/NativeMethods.cs) in `kernel32.dll`.

## Search

### Score

* [`CalculateSearchScore`](/src/modules/launcher/Wox.Infrastructure/StringMatcher.cs) A match found near the beginning of a string is scored more than a match found near the end. A match is scored more if the characters in the patterns are closer to each other, while the score is lower if they are more spread out.
* For network results (IP address and MAC address) the score is reduced by 25 percent.

### Network results on global queries
- The network results (IP and MAC address) are only shown on global queries, if the search term starts with either IP, MAC or Address. (We compare case-insensitive.)

## [Unit Tests](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests)
We have a [Unit Test project](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests) that executes various test to ensure that the plugin works as expected.

### [`ImageTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs)
- The [`ImageTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/ImageTests.cs) class contains tests to validate that each result shows the expected and correct image.

### [`QueryTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs)
- The [`QueryTests.cs`](/src/modules/launcher/Plugins/Microsoft.PowerToys.Run.Plugin.System.UnitTests/QueryTests.cs) class contains tests to validate that the user gets the correct results when searching.

2 changes: 1 addition & 1 deletion installer/PowerToysSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@

<?define SystemComponentFiles=plugin.json;Microsoft.PowerToys.Run.Plugin.System.deps.json;Microsoft.PowerToys.Run.Plugin.System.dll?>

<?define SystemImagesComponentFiles=lock.dark.png;lock.light.png;logoff.dark.png;logoff.light.png;recyclebin.dark.png;recyclebin.light.png;restart.dark.png;restart.light.png;shutdown.dark.png;shutdown.light.png;sleep.dark.png;sleep.light.png;firmwareSettings.dark.png;firmwareSettings.light.png?>
<?define SystemImagesComponentFiles=lock.dark.png;lock.light.png;logoff.dark.png;logoff.light.png;recyclebin.dark.png;recyclebin.light.png;restart.dark.png;restart.light.png;shutdown.dark.png;shutdown.light.png;sleep.dark.png;sleep.light.png;firmwareSettings.dark.png;firmwareSettings.light.png;networkAdapter.dark.png;networkAdapter.light.png?>

<?define TimeDateComponentFiles=Microsoft.PowerToys.Run.Plugin.TimeDate.deps.json;Microsoft.PowerToys.Run.Plugin.TimeDate.dll;plugin.json;PowerToys.ManagedTelemetry.dll?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public void Setup()
[DataRow("hibernate", "Images\\sleep.dark.png")]
[DataRow("empty recycle", "Images\\recyclebin.dark.png")]
[DataRow("uefi firmware settings", "Images\\firmwareSettings.dark.png")]
[DataRow("ip v4 addr", "Images\\networkAdapter.dark.png")]
[DataRow("ip v6 addr", "Images\\networkAdapter.dark.png")]
htcfreek marked this conversation as resolved.
Show resolved Hide resolved
[DataRow("mac addr", "Images\\networkAdapter.dark.png")]
public void IconThemeDarkTest(string typedString, string expectedResult)
{
// Setup
Expand All @@ -52,6 +55,9 @@ public void IconThemeDarkTest(string typedString, string expectedResult)
[DataRow("hibernate", "Images\\sleep.light.png")]
[DataRow("empty recycle", "Images\\recyclebin.light.png")]
[DataRow("uefi firmware settings", "Images\\firmwareSettings.light.png")]
[DataRow("ipv4 addr", "Images\\networkAdapter.light.png")]
[DataRow("ipv6 addr", "Images\\networkAdapter.light.png")]
[DataRow("mac addr", "Images\\networkAdapter.light.png")]
public void IconThemeLightTest(string typedString, string expectedResult)
{
// Setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -27,6 +28,11 @@ public void Setup()
[DataRow("sleep", "Put computer to sleep")]
[DataRow("hibernate", "Hibernate computer")]
[DataRow("empty recycle", "Empty Recycle Bin")]
[DataRow("ip", "IPv4 address of")]
[DataRow("address", "IPv4 address of")] // searching for address should show ipv4 first
[DataRow("ip v4", "IPv4 address of")]
[DataRow("ip v6", "IPv6 address of")]
htcfreek marked this conversation as resolved.
Show resolved Hide resolved
[DataRow("mac addr", "MAC address of")]
public void EnvironmentIndependentQueryResults(string typedString, string expectedResult)
{
// Setup
Expand All @@ -37,7 +43,7 @@ public void EnvironmentIndependentQueryResults(string typedString, string expect
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;

// Assert
Assert.AreEqual(expectedResult, result);
Assert.IsTrue(result.StartsWith(expectedResult, StringComparison.OrdinalIgnoreCase));
}

[TestMethod]
Expand Down
Loading