Skip to content

Commit

Permalink
Code and doc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWei512 committed Jun 10, 2023
1 parent 43d2eb9 commit 9b5566d
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 58 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/Build MSIX sideload package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ jobs:
run: |
msbuild $env:SOLUTION_NAME `
/p:Configuration=${{ matrix.configuration }} `
/p:Platform=${{ matrix.platform }} `
/p:PublishReadyToRun=false
/p:Platform=${{ matrix.platform }}
- name: 🧪 Unit testing
if: matrix.platform == 'x64' # GitHub Action only provides x64 Windows machines, which cannot run cross-compiled ARM64 tests
Expand Down
2 changes: 1 addition & 1 deletion doc/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ This app is developed with C#, Windows App SDK (WinUI 3) and Template Studio.

Before contributing, you need to install the toolchain:

1. Follow [Microsoft's guide](https://learn.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment) to install Visual Studio and Windows App SDK workloads.
1. Follow [Microsoft's guide](https://learn.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment) to install Visual Studio and Windows App SDK (C#) workloads.

2. (Optional) Install these Visual Studio extensions:

Expand Down
2 changes: 1 addition & 1 deletion doc/Contributing.zh-hans.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

在贡献之前,你需要安装工具链:

1. 根据 [微软的教程](https://learn.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment) 安装 Visual Studio 和 Windows App SDK 工作负载
1. 根据 [微软的教程](https://learn.microsoft.com/windows/apps/windows-app-sdk/set-up-your-development-environment) 安装 Visual Studio 和 Windows App SDK (C#) 工作负荷

2. (可选)安装这些 Visual Studio 扩展:

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyStarX.Core/EnergyStarX.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>EnergyStarX.Core</RootNamespace>
<Platforms>x86;x64;arm64;AnyCPU</Platforms>
<Platforms>x64;arm64;AnyCPU</Platforms>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/EnergyStarX.Test/EnergyStarX.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
<PropertyGroup>
<TargetFramework>net7.0-windows10.0.22000.0</TargetFramework>
<RootNamespace>EnergyStarX.Test</RootNamespace>
<Platforms>x86;x64;arm64</Platforms>
<Platforms>x64;arm64</Platforms>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<ProjectPriFileName>resources.pri</ProjectPriFileName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -20,6 +21,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EnergyStarX.Core\EnergyStarX.Core.csproj" />
<ProjectReference Include="..\EnergyStarX\EnergyStarX.csproj" />
Expand Down
16 changes: 0 additions & 16 deletions src/EnergyStarX.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ Global
Debug|Any CPU = Debug|Any CPU
Debug|arm64 = Debug|arm64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|arm64 = Release|arm64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|Any CPU.ActiveCfg = Debug|x64
Expand All @@ -30,9 +28,6 @@ Global
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x64.ActiveCfg = Debug|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x64.Build.0 = Debug|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x64.Deploy.0 = Debug|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x86.ActiveCfg = Debug|x86
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x86.Build.0 = Debug|x86
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Debug|x86.Deploy.0 = Debug|x86
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|Any CPU.ActiveCfg = Release|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|Any CPU.Build.0 = Release|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|Any CPU.Deploy.0 = Release|x64
Expand All @@ -42,41 +37,30 @@ Global
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x64.ActiveCfg = Release|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x64.Build.0 = Release|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x64.Deploy.0 = Release|x64
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x86.ActiveCfg = Release|x86
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x86.Build.0 = Release|x86
{C4557E9E-B309-4F5F-A1D9-8682618694AA}.Release|x86.Deploy.0 = Release|x86
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|arm64.ActiveCfg = Debug|arm64
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|arm64.Build.0 = Debug|arm64
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|x64.ActiveCfg = Debug|x64
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|x64.Build.0 = Debug|x64
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|x86.ActiveCfg = Debug|x86
{7C91E59C-3232-491B-B223-7000D1C52507}.Debug|x86.Build.0 = Debug|x86
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|Any CPU.Build.0 = Release|Any CPU
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|arm64.ActiveCfg = Release|arm64
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|arm64.Build.0 = Release|arm64
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|x64.ActiveCfg = Release|x64
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|x64.Build.0 = Release|x64
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|x86.ActiveCfg = Release|x86
{7C91E59C-3232-491B-B223-7000D1C52507}.Release|x86.Build.0 = Release|x86
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|Any CPU.ActiveCfg = Debug|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|Any CPU.Build.0 = Debug|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|arm64.ActiveCfg = Debug|arm64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|arm64.Build.0 = Debug|arm64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|x64.ActiveCfg = Debug|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|x64.Build.0 = Debug|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|x86.ActiveCfg = Debug|x86
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Debug|x86.Build.0 = Debug|x86
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|Any CPU.ActiveCfg = Release|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|Any CPU.Build.0 = Release|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|arm64.ActiveCfg = Release|arm64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|arm64.Build.0 = Release|arm64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|x64.ActiveCfg = Release|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|x64.Build.0 = Release|x64
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|x86.ActiveCfg = Release|x86
{2ACAD499-1A03-4DBC-955D-70A7F2A72809}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
57 changes: 29 additions & 28 deletions src/EnergyStarX/EnergyStarX.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<RootNamespace>EnergyStarX</RootNamespace>
<ApplicationIcon>Assets/WindowIcon.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<Platforms>x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>Properties\PublishProfiles\win10-$(Platform).pubxml</PublishProfile>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -32,10 +32,6 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
</PropertyGroup> -->

<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Labs.WinUI.SettingsControls" Version="0.0.18" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.0" />
Expand All @@ -59,32 +55,11 @@
<ItemGroup>
<ProjectReference Include="..\EnergyStarX.Core\EnergyStarX.Core.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Helpers\SettingsHelper.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SettingsHelper.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<ItemGroup>
<Folder Include="Assets\InApp\" />
</ItemGroup>

<ItemGroup>
<None Include="Helpers\SettingsHelper.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SettingsHelper.tt</DependentUpon>
</None>
</ItemGroup>

<ItemGroup>
<Content Update="Assets\InApp\CheckButton.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand All @@ -107,7 +82,21 @@
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
<None Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Helpers\SettingsHelper.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>SettingsHelper.cs</LastGenOutput>
</None>
</ItemGroup>

<ItemGroup>
<None Include="Helpers\SettingsHelper.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>SettingsHelper.tt</DependentUpon>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -118,6 +107,18 @@
</Compile>
</ItemGroup>

<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>

<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>
3 changes: 1 addition & 2 deletions src/EnergyStarX/Properties/PublishProfiles/win10-x64.pubxml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
<PublishDir>bin\$(Configuration)\$(TargetFramework)\$(RuntimeIdentifier)\publish\</PublishDir>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun Condition="'$(Configuration)' == 'Debug'">False</PublishReadyToRun>
<PublishReadyToRun Condition="'$(Configuration)' != 'Debug'">True</PublishReadyToRun>
<PublishReadyToRun>False</PublishReadyToRun>
</PropertyGroup>
</Project>
32 changes: 29 additions & 3 deletions src/EnergyStarX/Services/EnergyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void ApplyProcessBlacklist(string processBlacklistString)
}

/// <summary>
/// Returns true if "ThrottleStatus" changes after this method executes. Otherwise false.
/// Returns true if <see cref="ThrottleStatus"/> changes after this method executes. Otherwise false.
/// </summary>
private bool UpdateThrottleStatusAndNotify()
{
Expand Down Expand Up @@ -295,8 +295,13 @@ private bool UpdateThrottleStatusAndNotify()
}

/// <summary>
/// Returns true if "ThrottleStatus" changes after this method executes. Otherwise false.
/// Start throttling to <paramref name="toThrottleStatus"/>.
/// </summary>
///
/// <returns>
/// Returns true if <paramref name="toThrottleStatus"/> is not <see cref="ThrottleStatus.Stopped"/> and throttling has started.
/// Otherwise false.
/// </returns>
private bool StartThrottling(ThrottleStatus toThrottleStatus)
{
lock (lockObject)
Expand All @@ -316,8 +321,13 @@ private bool StartThrottling(ThrottleStatus toThrottleStatus)
}

/// <summary>
/// Returns true if "ThrottleStatus" changes after this method executes. Otherwise false.
/// Stop throttling from <paramref name="fromThrottleStatus"/>.
/// </summary>
///
/// <returns>
/// Returns true if <paramref name="fromThrottleStatus"/> is not <see cref="ThrottleStatus.Stopped"/> and throttling has stopped.
/// Otherwise false.
/// </returns>
private bool StopThrottling(ThrottleStatus fromThrottleStatus)
{
lock (lockObject)
Expand All @@ -335,6 +345,14 @@ private bool StopThrottling(ThrottleStatus fromThrottleStatus)
}
}

/// <summary>
/// Throttle background processes according to <paramref name="toThrottleStatus"/>.
/// </summary>
///
/// <returns>
/// Returns true if <paramref name="toThrottleStatus"/> is not <see cref="ThrottleStatus.Stopped"/> and user background processes got throttled.
/// Otherwise false.
/// </returns>
private bool ThrottleUserBackgroundProcesses(ThrottleStatus toThrottleStatus)
{
lock (lockObject)
Expand All @@ -361,6 +379,14 @@ private bool ThrottleUserBackgroundProcesses(ThrottleStatus toThrottleStatus)
}
}

/// <summary>
/// Recover throttled user processes from <paramref name="fromThrottleStatus"/>.
/// </summary>
///
/// <returns>
/// Returns true if <paramref name="fromThrottleStatus"/> is not <see cref="ThrottleStatus.Stopped"/> and user processes got recovered from being throttled.
/// Otherwise false.
/// </returns>
private bool RecoverUserProcesses(ThrottleStatus fromThrottleStatus)
{
lock (lockObject)
Expand Down
2 changes: 2 additions & 0 deletions src/EnergyStarX/Services/NavigationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ public bool NavigateTo(string pageKey, object? parameter = null, bool clearNavig
{
frame.Tag = clearNavigation;
object? vmBeforeNavigation = frame.GetPageViewModel();

bool navigated = transitionInfo is null ?
frame.Navigate(pageType, parameter) :
frame.Navigate(pageType, parameter, transitionInfo);

if (navigated)
{
lastParameterUsed = parameter;
Expand Down

0 comments on commit 9b5566d

Please sign in to comment.