This commit is contained in:
Leilei Zhang
2025-06-10 19:20:47 +08:00
parent d5e457fb90
commit 5fe883b789
10 changed files with 35 additions and 16 deletions

View File

@@ -221,6 +221,7 @@
"PowerToys.CmdPalModuleInterface.dll",
"CmdPalKeyboardService.dll",
"CmdPalCalculator.dll",
"*Microsoft.CmdPal.UI_*.msix"
],
"SigningInfo": {

View File

@@ -628,6 +628,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CmdPal.Ext.Apps",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CmdPal.Ext.Bookmarks", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.Bookmark\Microsoft.CmdPal.Ext.Bookmarks.csproj", "{E09AA983-C755-474F-83D6-A5CDF528C070}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CmdPal.Ext.Calc", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.Calc\Microsoft.CmdPal.Ext.Calc.csproj", "{6D56B64D-FF1F-488F-AFED-9B9854A5D399}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CmdPal.Ext.Registry", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.Registry\Microsoft.CmdPal.Ext.Registry.csproj", "{92EC89E4-9972-453A-8A1A-3A9E230C146A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CmdPal.Ext.WindowsServices", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.WindowsServices\Microsoft.CmdPal.Ext.WindowsServices.csproj", "{51939B4F-1F62-4BFF-A6A2-C08646E5BE95}"
@@ -2280,6 +2282,14 @@ Global
{E09AA983-C755-474F-83D6-A5CDF528C070}.Release|ARM64.Build.0 = Release|ARM64
{E09AA983-C755-474F-83D6-A5CDF528C070}.Release|x64.ActiveCfg = Release|x64
{E09AA983-C755-474F-83D6-A5CDF528C070}.Release|x64.Build.0 = Release|x64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Debug|ARM64.ActiveCfg = Debug|ARM64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Debug|ARM64.Build.0 = Debug|ARM64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Debug|x64.ActiveCfg = Debug|x64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Debug|x64.Build.0 = Debug|x64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Release|ARM64.ActiveCfg = Release|ARM64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Release|ARM64.Build.0 = Release|ARM64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Release|x64.ActiveCfg = Release|x64
{6D56B64D-FF1F-488F-AFED-9B9854A5D399}.Release|x64.Build.0 = Release|x64
{92EC89E4-9972-453A-8A1A-3A9E230C146A}.Debug|ARM64.ActiveCfg = Debug|ARM64
{92EC89E4-9972-453A-8A1A-3A9E230C146A}.Debug|ARM64.Build.0 = Debug|ARM64
{92EC89E4-9972-453A-8A1A-3A9E230C146A}.Debug|x64.ActiveCfg = Debug|x64
@@ -2831,6 +2841,7 @@ Global
{367D7543-7DBA-4381-99F1-BF6142A996C4} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
{2CAC093E-5FCF-4102-9C2C-AC7DD5D9EB96} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
{37D07516-4185-43A4-924F-3C7A5D95ECF6} = {A2221D7E-55E7-4BEA-90D1-4F162D670BBF}
{6D56B64D-FF1F-488F-AFED-9B9854A5D399} = {ECB8E0D1-7603-4E5C-AB10-D1E545E6F8E2}
{8F021B46-362B-485C-BFBA-CCF83E820CBD} = {8F62026A-294B-41C6-8839-87463613F216}
{66614C26-314C-4B91-9071-76133422CFEF} = {B6C42F16-73EB-477E-8B0D-4E6CF6C20AAC}
{3846508C-77EB-4034-A702-F8BB263C4F79} = {4574FDD0-F61D-4376-98BF-E5A1262C11EC}

View File

@@ -5,11 +5,13 @@
namespace winrt::CmdPalCalculator::implementation
{
Calculator::Calculator(Windows::Foundation::Collections::IMap<hstring, double> const& constants)
Calculator::Calculator(winrt::Windows::Foundation::Collections::IPropertySet const& constants)
{
for (auto const& [k, v] : constants)
for (auto const& pair : constants)
{
m_constants.emplace(k.c_str(), v);
auto key = pair.Key();
auto value = winrt::unbox_value<double>(pair.Value());
m_constants.emplace(key.c_str(), value);
}
}

View File

@@ -8,7 +8,7 @@ namespace winrt::CmdPalCalculator::implementation
{
Calculator() = default;
Calculator(Windows::Foundation::Collections::IMap<hstring, double> const& constants);
Calculator(winrt::Windows::Foundation::Collections::IPropertySet const& constants);
winrt::hstring EvaluateExpression(winrt::hstring const& expression);

View File

@@ -4,7 +4,7 @@ namespace CmdPalCalculator
runtimeclass Calculator
{
Calculator();
Calculator(IMap<String, Double> constants);
Calculator(Windows.Foundation.Collections.IPropertySet constants);
String EvaluateExpression(String expression);
}
}

View File

@@ -66,7 +66,7 @@
</ImportGroup>
<PropertyGroup>
<TargetName>CmdPalCalculator</TargetName>
<OutDir>..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\</OutDir>
<OutDir>..\..\..\..\$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>

View File

@@ -7,6 +7,7 @@ using Microsoft.CmdPal.Common.Helpers;
using Microsoft.CmdPal.Common.Services;
using Microsoft.CmdPal.Ext.Apps;
using Microsoft.CmdPal.Ext.Bookmarks;
using Microsoft.CmdPal.Ext.Calc;
using Microsoft.CmdPal.Ext.ClipboardHistory;
using Microsoft.CmdPal.Ext.Indexer;
using Microsoft.CmdPal.Ext.Registry;
@@ -103,6 +104,7 @@ public partial class App : Application
services.AddSingleton<ICommandProvider, ClipboardHistoryCommandsProvider>();
services.AddSingleton<ICommandProvider, WindowWalkerCommandsProvider>();
services.AddSingleton<ICommandProvider, WebSearchCommandsProvider>();
services.AddSingleton<ICommandProvider, CalculatorCommandProvider>();
// GH #38440: Users might not have WinGet installed! Or they might have
// a ridiculously old version. Or might be running as admin.

View File

@@ -132,7 +132,7 @@
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.WindowsTerminal\Microsoft.CmdPal.Ext.WindowsTerminal.csproj" />
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.WindowWalker\Microsoft.CmdPal.Ext.WindowWalker.csproj" />
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.WinGet\Microsoft.CmdPal.Ext.WinGet.csproj" />
<ProjectReference Include="..\ext\Microsoft.CmdPal.Ext.Calc\Microsoft.CmdPal.Ext.Calc.csproj" />
<ProjectReference Include="..\Microsoft.Terminal.UI\Microsoft.Terminal.UI.vcxproj">
<ReferenceOutputAssembly>True</ReferenceOutputAssembly>
<Private>True</Private>

View File

@@ -7,16 +7,19 @@ using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions;
using CmdPalCalculator;
using Windows.Foundation.Collections;
namespace Microsoft.CmdPal.Ext.Calc.Helper;
public static class CalculateEngine
{
private static readonly Calculator _calculator = new Calculator(new Dictionary<string, double>
{
{ "pi", Math.PI },
{ "e", Math.E },
});
private static readonly PropertySet _constants = new()
{
{ "pi", Math.PI },
{ "e", Math.E },
};
private static readonly Calculator _calculator = new Calculator(_constants);
public const int RoundingDigits = 10;

View File

@@ -3,7 +3,7 @@
<Import Project="..\..\..\..\Common.Dotnet.AotCompatibility.props" />
<Target Name="BuildCmdPalCalculator" BeforeTargets="Build">
<MSBuild
Projects="$(SolutionDir)src\modules\cmdpal\CmdPalCalculator\CmdPalCalculator.vcxproj"
Projects="..\..\CmdPalCalculator\CmdPalCalculator.vcxproj"
Targets="Build"
Properties="Configuration=$(Configuration);Platform=$(Platform)" />
</Target>
@@ -26,11 +26,11 @@
</ItemGroup>
<ItemGroup>
<CsWinRTInputs Include="..\..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\CmdPalCalculator.winmd" />
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\CmdPalCalculator.winmd" Link="CmdPalCalculator.winmd">
<CsWinRTInputs Include="..\..\..\..\..\$(Platform)\$(Configuration)\CmdPalCalculator.winmd" />
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\CmdPalCalculator.winmd" Link="CmdPalCalculator.winmd">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\WinUI3Apps\CmdPalCalculator.dll">
<Content Include="..\..\..\..\..\$(Platform)\$(Configuration)\CmdPalCalculator.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>