Skip to content

Commit 6c77cae

Browse files
authored
Merge pull request #1 from hiddenblue/Dev
merge from dev
2 parents a00b1f1 + d8cd64e commit 6c77cae

26 files changed

+1250
-151
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
7+
# built on .NET Core.
8+
# To learn how to migrate your existing application to .NET Core,
9+
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
10+
#
11+
# To configure this workflow:
12+
#
13+
# 1. Configure environment variables
14+
# GitHub sets default environment variables for every workflow run.
15+
# Replace the variables relative to your project in the "env" section below.
16+
#
17+
# 2. Signing
18+
# Generate a signing certificate in the Windows Application
19+
# Packaging Project or add an existing signing certificate to the project.
20+
# Next, use PowerShell to encode the .pfx file using Base64 encoding
21+
# by running the following Powershell script to generate the output string:
22+
#
23+
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
24+
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
25+
#
26+
# Open the output file, SigningCertificate_Encoded.txt, and copy the
27+
# string inside. Then, add the string to the repo as a GitHub secret
28+
# and name it "Base64_Encoded_Pfx."
29+
# For more information on how to configure your signing certificate for
30+
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
31+
#
32+
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
33+
# See "Build the Windows Application Packaging project" below to see how the secret is used.
34+
#
35+
# For more information on GitHub Actions, refer to https://github.com/features/actions
36+
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
37+
# refer to https://github.com/microsoft/github-actions-for-desktop-apps
38+
39+
name: .NET Core Desktop
40+
41+
on:
42+
push:
43+
branches: [ "master" ]
44+
pull_request:
45+
branches: [ "master" ]
46+
47+
jobs:
48+
49+
build:
50+
51+
strategy:
52+
matrix:
53+
configuration: [Debug, Release]
54+
55+
runs-on: windows-latest # For a list of available runner types, refer to
56+
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
57+
58+
env:
59+
Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln.
60+
Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
61+
Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
62+
Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.
63+
64+
steps:
65+
- name: Checkout
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 0
69+
70+
# Install the .NET Core workload
71+
- name: Install .NET Core
72+
uses: actions/setup-dotnet@v4
73+
with:
74+
dotnet-version: 8.0.x
75+
76+
# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
77+
- name: Setup MSBuild.exe
78+
uses: microsoft/setup-msbuild@v2
79+
80+
# Execute all unit tests in the solution
81+
- name: Execute unit tests
82+
run: dotnet test
83+
84+
# Restore the application to populate the obj folder with RuntimeIdentifiers
85+
- name: Restore the application
86+
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
87+
env:
88+
Configuration: ${{ matrix.configuration }}
89+
90+
# Decode the base 64 encoded pfx and save the Signing_Certificate
91+
- name: Decode the pfx
92+
run: |
93+
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
94+
$certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
95+
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)
96+
97+
# Create the app package by building and packaging the Windows Application Packaging project
98+
- name: Create the app package
99+
run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }}
100+
env:
101+
Appx_Bundle: Always
102+
Appx_Bundle_Platforms: x86|x64
103+
Appx_Package_Build_Mode: StoreUpload
104+
Configuration: ${{ matrix.configuration }}
105+
106+
# Remove the pfx
107+
- name: Remove the pfx
108+
run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx
109+
110+
# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
111+
- name: Upload build artifacts
112+
uses: actions/upload-artifact@v3
113+
with:
114+
name: MSIX Package
115+
path: ${{ env.Wap_Project_Directory }}\AppPackages

Avalonia.CpuLimiter/App.axaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,22 @@
1313
<FluentTheme />
1414
<StyleInclude Source="avares://Avalonia.CpuLimiter/Icons.axaml"/>
1515
</Application.Styles>
16+
17+
<TrayIcon.Icons>
18+
<TrayIcons>
19+
<TrayIcon Icon="/Assets/avalonia-logo.ico"
20+
ToolTipText="Game Launcher">
21+
<TrayIcon.Menu>
22+
<NativeMenu>
23+
<NativeMenuItem Header="Open File"/>
24+
<NativeMenuItem Header="Restore Window"/>
25+
<NativeMenuItem Header="Launcher Program"/>
26+
<NativeMenuItem Header="Settings"/>
27+
<NativeMenuItemSeparator />
28+
<NativeMenuItem Header="Exit Program" Click="OnExitButtonClicked"/>
29+
</NativeMenu>
30+
</TrayIcon.Menu>
31+
</TrayIcon>
32+
</TrayIcons>
33+
</TrayIcon.Icons>
1634
</Application>

Avalonia.CpuLimiter/App.axaml.cs

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
using Avalonia;
21
using Avalonia.Controls.ApplicationLifetimes;
32
using Avalonia.CpuLimiter.Services;
43
using Avalonia.CpuLimiter.ViewModels;
54
using Avalonia.CpuLimiter.Views;
65
using Avalonia.Markup.Xaml;
76
using Microsoft.Extensions.DependencyInjection;
87
using System;
8+
using System.Collections.Generic;
9+
using System.Globalization;
10+
using System.Linq;
11+
using System.Threading.Tasks;
12+
using Avalonia.CpuLimiter.Models;
13+
914

1015
namespace Avalonia.CpuLimiter
1116
{
@@ -16,25 +21,39 @@ public override void Initialize()
1621
AvaloniaXamlLoader.Load(this);
1722
}
1823

19-
public override void OnFrameworkInitializationCompleted()
24+
25+
private readonly MainWindowViewModel _mainWindowViewModel = new MainWindowViewModel();
26+
27+
public override async void OnFrameworkInitializationCompleted()
2028
{
29+
Lang.Resources.Culture = new CultureInfo("zh-hans-cn");
30+
31+
2132
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
2233
{
2334
desktop.MainWindow = new MainWindow
2435
{
25-
DataContext = new MainWindowViewModel(),
36+
DataContext = _mainWindowViewModel
2637
};
2738

2839
var services = new ServiceCollection();
2940

3041
services.AddSingleton<IFilesService>(x => new FilesService(desktop.MainWindow));
42+
services.AddSingleton<IClipBoardService>(x => new ClipBoardService(desktop));
43+
_mainWindowViewModel.ClipBoardService = services.BuildServiceProvider().GetService<IClipBoardService>()!;
3144

3245
Services = services.BuildServiceProvider();
33-
}
3446

47+
desktop.ShutdownRequested += DesktopOnShutdownRequested;
3548

49+
ExitApplication += OnExitApplicationTriggered;
50+
}
3651

3752
base.OnFrameworkInitializationCompleted();
53+
54+
// init and load from config.json
55+
56+
await InitMainWindowViewModel();
3857
}
3958

4059
// services provider
@@ -43,5 +62,70 @@ public override void OnFrameworkInitializationCompleted()
4362
public new static App? Current => Application.Current as App;
4463

4564
public IServiceProvider? Services { get; private set; }
65+
66+
private bool _canClose;
67+
68+
// save config to local json file
69+
// handler to handler the close app event is triggered.
70+
private async void DesktopOnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
71+
{
72+
e.Cancel = !_canClose;
73+
74+
if(!_canClose)
75+
{
76+
IEnumerable<HistoryItem> itemToSave = _mainWindowViewModel.HistoryItems.Select(item => item.GetHistoryItem());
77+
78+
await HistoryItemFileService.SaveHistoryToFileAsync(itemToSave);
79+
80+
_canClose = true;
81+
82+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
83+
{
84+
desktop.Shutdown();
85+
}
86+
}
87+
}
88+
89+
90+
// load config from json
91+
92+
private async Task InitMainWindowViewModel()
93+
{
94+
IEnumerable<HistoryItem>? loadItem = await HistoryItemFileService.LoadHistoryFromFileAsync();
95+
96+
if (loadItem != null && loadItem.Count() > 0)
97+
{
98+
foreach (HistoryItem item in loadItem)
99+
{
100+
_mainWindowViewModel.HistoryItems.Add(new HistoryItemViewModel(item));
101+
}
102+
103+
_mainWindowViewModel.GamePath = _mainWindowViewModel.HistoryItems[0].Path;
104+
105+
await HistoryItemViewModel.RemoveDuplicatedHistoryItemAsync(_mainWindowViewModel.HistoryItems);
106+
}
107+
}
108+
109+
public async void OnExitButtonClicked(object? sender, EventArgs eventArgs)
110+
{
111+
ExitApplication?.Invoke(this, EventArgs.Empty);
112+
113+
}
114+
115+
public void OnExitApplicationTriggered(object? sender, EventArgs eventArgs)
116+
{
117+
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
118+
{
119+
Console.WriteLine("The application is exiting.");
120+
desktop.TryShutdown();
121+
}
122+
}
123+
124+
// the program calling this Event to exit;
125+
// App.Current.ExitApplication.invoke
126+
public event EventHandler? ExitApplication;
127+
128+
129+
46130
}
47131
}

Avalonia.CpuLimiter/Avalonia.CpuLimiter.csproj

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@
66
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
77
<ApplicationManifest>app.manifest</ApplicationManifest>
88
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
9-
<PublishAot>true</PublishAot>
9+
<PublishAot>false</PublishAot>
1010
<RootNamespace>Avalonia.CpuLimiter</RootNamespace>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
1414
<AvaloniaResource Include="Assets\**" />
15+
<AvaloniaResource Include="Lang\**" />
16+
1517
</ItemGroup>
1618

1719
<ItemGroup>
18-
<PackageReference Include="Avalonia" Version="11.1.0" />
19-
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
20-
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
21-
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
20+
<PackageReference Include="Avalonia" Version="11.2.0" />
21+
<PackageReference Include="Avalonia.Desktop" Version="11.2.0" />
22+
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.0" />
23+
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.0" />
2224
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
23-
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
24-
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
25+
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.0" />
26+
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.0" />
27+
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
2528
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
2629
</ItemGroup>
2730
</Project>

Avalonia.CpuLimiter/Icons.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Styles>
1111
<Styles.Resources>
1212
<StreamGeometry x:Key="GamesRegular">M14.9978834,5 C18.8638767,5 21.9978834,8.13400675 21.9978834,12 C21.9978834,15.7854517 18.9931001,18.8690987 15.2385332,18.995941 L14.9978834,19 L9.00211656,19 C5.13612331,19 2.00211656,15.8659932 2.00211656,12 C2.00211656,8.21454828 5.00689994,5.13090132 8.76146681,5.00405902 L9.00211656,5 L14.9978834,5 Z M14.9978834,6.5 L9.00211656,6.5 C5.96455044,6.5 3.50211656,8.96243388 3.50211656,12 C3.50211656,14.9634791 5.84589657,17.3795391 8.78090942,17.4956328 L9.00211656,17.5 L14.9978834,17.5 C18.0354496,17.5 20.4978834,15.0375661 20.4978834,12 C20.4978834,9.03652085 18.1541034,6.62046086 15.2190906,6.5043672 L14.9978834,6.5 Z M8,9 C8.41421356,9 8.75,9.33578644 8.75,9.75 L8.74911656,11.248 L10.25,11.2487458 C10.6642136,11.2487458 11,11.5845322 11,11.9987458 C11,12.4129593 10.6642136,12.7487458 10.25,12.7487458 L8.74911656,12.748 L8.75,14.25 C8.75,14.6642136 8.41421356,15 8,15 C7.58578644,15 7.25,14.6642136 7.25,14.25 L7.24911656,12.748 L5.75,12.7487458 C5.33578644,12.7487458 5,12.4129593 5,11.9987458 C5,11.5845322 5.33578644,11.2487458 5.75,11.2487458 L7.24911656,11.248 L7.25,9.75 C7.25,9.33578644 7.58578644,9 8,9 Z M14.75,12.5 C15.4403559,12.5 16,13.0596441 16,13.75 C16,14.4403559 15.4403559,15 14.75,15 C14.0596441,15 13.5,14.4403559 13.5,13.75 C13.5,13.0596441 14.0596441,12.5 14.75,12.5 Z M16.75,9 C17.4403559,9 18,9.55964406 18,10.25 C18,10.9403559 17.4403559,11.5 16.75,11.5 C16.0596441,11.5 15.5,10.9403559 15.5,10.25 C15.5,9.55964406 16.0596441,9 16.75,9 Z</StreamGeometry>
13+
<StreamGeometry x:Key="DeleteRegular">M24,7.25 C27.1017853,7.25 29.629937,9.70601719 29.7458479,12.7794443 L29.75,13 L37,13 C37.6903559,13 38.25,13.5596441 38.25,14.25 C38.25,14.8972087 37.7581253,15.4295339 37.1278052,15.4935464 L37,15.5 L35.909,15.5 L34.2058308,38.0698451 C34.0385226,40.2866784 32.1910211,42 29.9678833,42 L18.0321167,42 C15.8089789,42 13.9614774,40.2866784 13.7941692,38.0698451 L12.09,15.5 L11,15.5 C10.3527913,15.5 9.8204661,15.0081253 9.75645361,14.3778052 L9.75,14.25 C9.75,13.6027913 10.2418747,13.0704661 10.8721948,13.0064536 L11,13 L18.25,13 C18.25,9.82436269 20.8243627,7.25 24,7.25 Z M33.4021054,15.5 L14.5978946,15.5 L16.2870795,37.8817009 C16.3559711,38.7945146 17.116707,39.5 18.0321167,39.5 L29.9678833,39.5 C30.883293,39.5 31.6440289,38.7945146 31.7129205,37.8817009 L33.4021054,15.5 Z M27.25,20.75 C27.8972087,20.75 28.4295339,21.2418747 28.4935464,21.8721948 L28.5,22 L28.5,33 C28.5,33.6903559 27.9403559,34.25 27.25,34.25 C26.6027913,34.25 26.0704661,33.7581253 26.0064536,33.1278052 L26,33 L26,22 C26,21.3096441 26.5596441,20.75 27.25,20.75 Z M20.75,20.75 C21.3972087,20.75 21.9295339,21.2418747 21.9935464,21.8721948 L22,22 L22,33 C22,33.6903559 21.4403559,34.25 20.75,34.25 C20.1027913,34.25 19.5704661,33.7581253 19.5064536,33.1278052 L19.5,33 L19.5,22 C19.5,21.3096441 20.0596441,20.75 20.75,20.75 Z M24,9.75 C22.2669685,9.75 20.8507541,11.1064548 20.7551448,12.8155761 L20.75,13 L27.25,13 C27.25,11.2050746 25.7949254,9.75 24,9.75 Z</StreamGeometry>
1314
</Styles.Resources>
1415
</Styles>
1516
</Styles>

0 commit comments

Comments
 (0)