Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
500c842
improve: simplified the code of about window
hiddenblue Nov 2, 2024
5bcd661
Feature: add Exit request message and dependency
hiddenblue Nov 2, 2024
60867e3
add partial History support code : model and viewModel
hiddenblue Nov 2, 2024
0c25c3e
Create dotnet-desktop.yml
hiddenblue Nov 2, 2024
339d1a3
Feature: Add multi-language support(partial)
hiddenblue Nov 2, 2024
f0f946a
Update README with Chinese and add history property
hiddenblue Nov 2, 2024
76d43dd
Merge remote-tracking branch 'origin/Dev' into Dev
hiddenblue Nov 2, 2024
5ad4afe
feature: finisied the history load and save
hiddenblue Nov 4, 2024
cc73b96
move the localization resource file to Lang
hiddenblue Nov 4, 2024
61686ec
temp saved
hiddenblue Nov 4, 2024
f6b21aa
move the localization resource file to Lang
hiddenblue Nov 4, 2024
a20cbba
Feature: add TrayIcon support(partial)
hiddenblue Nov 4, 2024
efcfa0c
Feature: Add FilePicker winexe type restriction for windows
hiddenblue Nov 4, 2024
3871d4f
Feature: Added json sourceGenerator options to support native aot
hiddenblue Nov 4, 2024
19103d4
Improvement: combobox and slider(support mousewheel control)
hiddenblue Nov 4, 2024
f799a3d
Feature: override the Historyitem and vm equal hashcode method
hiddenblue Nov 5, 2024
5e4e81a
improved the combobox code( partial)
hiddenblue Nov 5, 2024
8d934c6
alter the mainwindow load and initialization method
hiddenblue Nov 5, 2024
f6ea805
Feature: Add native applicaitonlifetime management
hiddenblue Nov 6, 2024
5fccd17
change: move some buttonclicked handler to codebebind
hiddenblue Nov 6, 2024
3b97fac
Changes:
hiddenblue Nov 7, 2024
94145d2
improve the screen width control
hiddenblue Nov 7, 2024
3b13bc9
Feature: Add clipboard service
hiddenblue Nov 7, 2024
e1da263
improvement: modify style group
hiddenblue Nov 7, 2024
d8cd64e
Services changed
hiddenblue Nov 7, 2024
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
115 changes: 115 additions & 0 deletions .github/workflows/dotnet-desktop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow will build, test, sign and package a WPF or Windows Forms desktop application
# built on .NET Core.
# To learn how to migrate your existing application to .NET Core,
# refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework
#
# To configure this workflow:
#
# 1. Configure environment variables
# GitHub sets default environment variables for every workflow run.
# Replace the variables relative to your project in the "env" section below.
#
# 2. Signing
# Generate a signing certificate in the Windows Application
# Packaging Project or add an existing signing certificate to the project.
# Next, use PowerShell to encode the .pfx file using Base64 encoding
# by running the following Powershell script to generate the output string:
#
# $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte
# [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt'
#
# Open the output file, SigningCertificate_Encoded.txt, and copy the
# string inside. Then, add the string to the repo as a GitHub secret
# and name it "Base64_Encoded_Pfx."
# For more information on how to configure your signing certificate for
# this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing
#
# Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key".
# See "Build the Windows Application Packaging project" below to see how the secret is used.
#
# For more information on GitHub Actions, refer to https://github.com/features/actions
# For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications,
# refer to https://github.com/microsoft/github-actions-for-desktop-apps

name: .NET Core Desktop

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:

strategy:
matrix:
configuration: [Debug, Release]

runs-on: windows-latest # For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on

env:
Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln.
Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj.
Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package.
Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj.

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v2

# Execute all unit tests in the solution
- name: Execute unit tests
run: dotnet test

# Restore the application to populate the obj folder with RuntimeIdentifiers
- name: Restore the application
run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}

# Decode the base 64 encoded pfx and save the Signing_Certificate
- name: Decode the pfx
run: |
$pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}")
$certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx
[IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte)

# Create the app package by building and packaging the Windows Application Packaging project
- name: Create the app package
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 }}
env:
Appx_Bundle: Always
Appx_Bundle_Platforms: x86|x64
Appx_Package_Build_Mode: StoreUpload
Configuration: ${{ matrix.configuration }}

# Remove the pfx
- name: Remove the pfx
run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx

# Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: MSIX Package
path: ${{ env.Wap_Project_Directory }}\AppPackages
18 changes: 18 additions & 0 deletions Avalonia.CpuLimiter/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@
<FluentTheme />
<StyleInclude Source="avares://Avalonia.CpuLimiter/Icons.axaml"/>
</Application.Styles>

<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/avalonia-logo.ico"
ToolTipText="Game Launcher">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Open File"/>
<NativeMenuItem Header="Restore Window"/>
<NativeMenuItem Header="Launcher Program"/>
<NativeMenuItem Header="Settings"/>
<NativeMenuItemSeparator />
<NativeMenuItem Header="Exit Program" Click="OnExitButtonClicked"/>
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
</TrayIcons>
</TrayIcon.Icons>
</Application>
92 changes: 88 additions & 4 deletions Avalonia.CpuLimiter/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.CpuLimiter.Services;
using Avalonia.CpuLimiter.ViewModels;
using Avalonia.CpuLimiter.Views;
using Avalonia.Markup.Xaml;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Avalonia.CpuLimiter.Models;


namespace Avalonia.CpuLimiter
{
Expand All @@ -16,25 +21,39 @@ public override void Initialize()
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()

private readonly MainWindowViewModel _mainWindowViewModel = new MainWindowViewModel();

public override async void OnFrameworkInitializationCompleted()
{
Lang.Resources.Culture = new CultureInfo("zh-hans-cn");


if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
DataContext = _mainWindowViewModel
};

var services = new ServiceCollection();

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

Services = services.BuildServiceProvider();
}

desktop.ShutdownRequested += DesktopOnShutdownRequested;

ExitApplication += OnExitApplicationTriggered;
}

base.OnFrameworkInitializationCompleted();

// init and load from config.json

await InitMainWindowViewModel();
}

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

public IServiceProvider? Services { get; private set; }

private bool _canClose;

// save config to local json file
// handler to handler the close app event is triggered.
private async void DesktopOnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
{
e.Cancel = !_canClose;

if(!_canClose)
{
IEnumerable<HistoryItem> itemToSave = _mainWindowViewModel.HistoryItems.Select(item => item.GetHistoryItem());

await HistoryItemFileService.SaveHistoryToFileAsync(itemToSave);

_canClose = true;

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.Shutdown();
}
}
}


// load config from json

private async Task InitMainWindowViewModel()
{
IEnumerable<HistoryItem>? loadItem = await HistoryItemFileService.LoadHistoryFromFileAsync();

if (loadItem != null && loadItem.Count() > 0)
{
foreach (HistoryItem item in loadItem)
{
_mainWindowViewModel.HistoryItems.Add(new HistoryItemViewModel(item));
}

_mainWindowViewModel.GamePath = _mainWindowViewModel.HistoryItems[0].Path;

await HistoryItemViewModel.RemoveDuplicatedHistoryItemAsync(_mainWindowViewModel.HistoryItems);
}
}

public async void OnExitButtonClicked(object? sender, EventArgs eventArgs)
{
ExitApplication?.Invoke(this, EventArgs.Empty);

}

public void OnExitApplicationTriggered(object? sender, EventArgs eventArgs)
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Console.WriteLine("The application is exiting.");
desktop.TryShutdown();
}
}

// the program calling this Event to exit;
// App.Current.ExitApplication.invoke
public event EventHandler? ExitApplication;



}
}
17 changes: 10 additions & 7 deletions Avalonia.CpuLimiter/Avalonia.CpuLimiter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
<PublishAot>true</PublishAot>
<PublishAot>false</PublishAot>
<RootNamespace>Avalonia.CpuLimiter</RootNamespace>
</PropertyGroup>

<ItemGroup>
<AvaloniaResource Include="Assets\**" />
<AvaloniaResource Include="Lang\**" />

</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<PackageReference Include="Avalonia" Version="11.2.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.0" />
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Avalonia.CpuLimiter/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<Styles>
<Styles.Resources>
<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>
<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>
</Styles.Resources>
</Styles>
</Styles>
Loading
Loading