Skip to content

Commit

Permalink
💾 🎇 Feat, Style(Step 2): All-round optimization
Browse files Browse the repository at this point in the history
- Separate platform specific operations out
- Fixed some typo errors
  • Loading branch information
Dynesshely committed Jan 9, 2025
1 parent 1cf6af0 commit 5b17387
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 57 deletions.
3 changes: 2 additions & 1 deletion KitX Dashboard Assets/KitX.Dashboard.Assets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<RootNamespace>KitX.Dashboard.Assets</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Remove="KitX-Icon-1024x-margin-2x.png" />
Expand Down Expand Up @@ -42,4 +43,4 @@
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion KitX Dashboard Core/KitX.Dashboard.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>KitX.Dashboard.Core</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion KitX Dashboard Fonts/KitX.Dashboard.Fonts.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>KitX.Dashboard.Fonts</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<TrimMode>copyused</TrimMode>
Expand All @@ -18,4 +19,4 @@
<PackageReference Include="Avalonia" Version="11.2.3" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
</ItemGroup>
</Project>
</Project>
3 changes: 2 additions & 1 deletion KitX Dashboard Repair Tool/KitX.Dashboard.RepairTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>KitX.Dashboard.RepairTool</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
</PropertyGroup>

</Project>
</Project>
3 changes: 2 additions & 1 deletion KitX Dashboard Updater/KitX.Dashboard.Updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>KitX.Dashboard.Updater</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -11,4 +12,4 @@
<PackageReference Include="Common.Update.Replacer" Version="1.0.1.2" />
</ItemGroup>

</Project>
</Project>
24 changes: 13 additions & 11 deletions KitX Dashboard Updater/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Common.Update.Replacer;

namespace KitX.Updater
namespace KitX.Dashboard.Updater
{
public class Updater
{
Expand Down Expand Up @@ -34,32 +34,34 @@ public static void Main(string[] args)
++i;
_rootDir = args[i];
}
else throw new Exception("参数 --source-dir 缺少值");
else
throw new Exception("参数 --source-dir 缺少值");
break;
case "--update-from":
if (i != args.Length - 1)
{
++i;
_newFilesDir = args[i];
}
else throw new Exception("参数 --update-from 缺少值");
else
throw new Exception("参数 --update-from 缺少值");
break;
}
}

Replacer replacer = new Replacer()
.SetSourceDir(_newFilesDir)
.SetRootDir(_rootDir);
Replacer replacer = new Replacer().SetSourceDir(_newFilesDir).SetRootDir(_rootDir);
replacer.Replace();
}
catch (Exception e)
{
DoColor(ConsoleColor.Red, new(() =>
{
Console.WriteLine(e.Message);
}));
DoColor(
ConsoleColor.Red,
new(() =>
{
Console.WriteLine(e.Message);
})
);
}
}
}
}

File renamed without changes.
12 changes: 4 additions & 8 deletions KitX Dashboard/ConstantTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ internal static class ConstantTable

internal const string AssetsPath = "./Assets/";

internal const string KXPTempReleasePath = "Temp/";

internal const string UpdateSavePath = "./Update/";

internal const string IconBase64FileName = "KitX.Base64.txt";

private const string activitiesDataBaseFilePath = $"{DataPath}Activities.db";

private const string thirdPartLicenseFilePath = $"{AssetsPath}ThirdPartLicense.md";
private const string thirdPartyLicenseFilePath = $"{AssetsPath}ThirdPartyLicense.md";

internal static string ActivitiesDataBaseFilePath => activitiesDataBaseFilePath.GetFullPath();

internal static string ThirdPartLicenseFilePath => thirdPartLicenseFilePath.GetFullPath();
internal static string ThirdPartyLicenseFilePath => thirdPartyLicenseFilePath.GetFullPath();

internal static bool IsExchangingDeviceKey = false;

Expand Down Expand Up @@ -55,11 +53,9 @@ internal static class ConstantTable

internal static DateTime ServerBuildTime = new();

internal const string Api_Get_Announcements = "get-announcements.php";

internal const string Api_Get_Announcement = "get-announcement.php";
internal const string ApiGetAnnouncements = "get-announcements.php";

internal static string MyMacAddress = string.Empty;
internal const string ApiGetAnnouncement = "get-announcement.php";

internal static string KitXIconBase64 = string.Empty;

Expand Down
57 changes: 38 additions & 19 deletions KitX Dashboard/KitX.Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>false</AvaloniaUseCompiledBindingsByDefault>
<RootNamespace>KitX.Dashboard</RootNamespace>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -83,9 +84,10 @@
Condition below is needed to remove Avalonia.Diagnostics package from build output in Release
configuration
-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.3" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics"
Version="11.2.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.3" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.1" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.2.0.7" />
<PackageReference Include="AvaloniaEdit.TextMate" Version="11.1.0" />
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Deadpikle.AvaloniaProgressRing" Version="0.10.10" />
Expand All @@ -96,7 +98,8 @@
<PackageReference Include="Markdown.Avalonia" Version="11.0.3-a1" />
<PackageReference Include="Material.Icons.Avalonia" Version="2.1.10" />
<PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
<PackageReference Include="nulastudio.NetBeauty" Version="2.1.2.1" Condition="$(Is2Publish) == 'True'" />
<PackageReference Include="nulastudio.NetBeauty" Version="2.1.2.1"
Condition="$(Is2Publish) == 'True'" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
Expand All @@ -105,32 +108,48 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Common.Activity" Version="1.1.6509.914" Condition="!Exists('..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj')" />
<PackageReference Include="Common.BasicHelper" Version="1.3.584.228" Condition="!Exists('..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj')" />
<PackageReference Include="Common.Update.Checker" Version="1.0.1.3" Condition="!Exists('..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj')" />
<PackageReference Include="Csharpell.Core" Version="0.5.335.689" Condition="!Exists('..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj')" />
<PackageReference Include="Common.Activity" Version="1.1.6509.914"
Condition="!Exists('..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj')" />
<PackageReference Include="Common.BasicHelper" Version="1.3.584.228"
Condition="!Exists('..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj')" />
<PackageReference Include="Common.Update.Checker" Version="1.0.1.3"
Condition="!Exists('..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj')" />
<PackageReference Include="Csharpell.Core" Version="0.5.335.689"
Condition="!Exists('..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj')" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KitX Dashboard Assets\KitX.Dashboard.Assets.csproj" />
<ProjectReference Include="..\KitX Dashboard Fonts\KitX.Dashboard.Fonts.csproj" />
<ProjectReference Include="..\..\..\KitX Standard\KitX File Formats\KitX.FileFormats.CSharp\KitX.FileFormats.CSharp.csproj" />
<ProjectReference Include="..\..\..\KitX Standard\KitX Shared\KitX.Shared.CSharp\KitX.Shared.CSharp.csproj" />
<ProjectReference
Include="..\Specific\KitX Dashboard Specific MsWindows\KitX.Dashboard.Specific.MsWindows.csproj" />
<ProjectReference
Include="..\..\..\KitX Standard\KitX File Formats\KitX.FileFormats.CSharp\KitX.FileFormats.CSharp.csproj" />
<ProjectReference
Include="..\..\..\KitX Standard\KitX Shared\KitX.Shared.CSharp\KitX.Shared.CSharp.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj" Condition="Exists('..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj')" />
<ProjectReference Include="..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj" Condition="Exists('..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj')" />
<ProjectReference Include="..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj" Condition="Exists('..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj')" />
<ProjectReference Include="..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj" Condition="Exists('..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj')" />
<ProjectReference
Include="..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj"
Condition="Exists('..\..\..\Reference\Common.Activity\Common.Activity\Common.Activity.csproj')" />
<ProjectReference
Include="..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj"
Condition="Exists('..\..\..\Reference\Common.BasicHelper\Common.BasicHelper\Common.BasicHelper.csproj')" />
<ProjectReference
Include="..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj"
Condition="Exists('..\..\..\Reference\Common.Update\Common.Update.Checker\Common.Update.Checker.csproj')" />
<ProjectReference
Include="..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj"
Condition="Exists('..\..\..\Reference\CSharpell\Csharpell.Core\Csharpell.Core.csproj')" />
</ItemGroup>

<ItemGroup>
<Compile Update="Views\AnnouncementsWindow.axaml.cs">
<DependentUpon>AnnouncementsWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Pages\DevicesPage.axaml.cs">
<DependentUpon>DevicesPage.axaml</DependentUpon>
</Compile>
<Compile Update="Views\AnnouncementsWindow.axaml.cs">
<DependentUpon>AnnouncementsWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Pages\DevicesPage.axaml.cs">
<DependentUpon>DevicesPage.axaml</DependentUpon>
</Compile>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions KitX Dashboard/Managers/AnnouncementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task CheckNewAnnouncements()

var link = new StringBuilder()
.Append(linkBase)
.Append(ConstantTable.Api_Get_Announcements)
.Append(ConstantTable.ApiGetAnnouncements)
.ToString();

try
Expand Down Expand Up @@ -58,7 +58,7 @@ select DateTime.Parse(item)
foreach (var item in unreads)
{
var apiLink = new StringBuilder()
.Append($"{linkBase}{ConstantTable.Api_Get_Announcement}")
.Append($"{linkBase}{ConstantTable.ApiGetAnnouncement}")
.Append('?')
.Append($"lang={ConfigManager.Instance.AppConfig.App.AppLanguage}")
.Append('&')
Expand Down
14 changes: 6 additions & 8 deletions KitX Dashboard/Utils/WindowsUtils.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
using System;
using System.Runtime.InteropServices;
using Avalonia.Platform;
using Common.BasicHelper.Graphics.Screen;
using KitX.Dashboard.Specific.MsWindows.Graphics;

namespace KitX.Dashboard.Utils;

internal static class WindowsUtils
{
[DllImport("user32.dll")]
private static extern int GetDpiForSystem();

private const int DefaultDpi = 96;

internal static Resolution SuggestResolution(
this Resolution res,
Screen? screen,
Expand All @@ -37,15 +32,18 @@ out Resolution? notScaled
{
notScaled = suggest.Clone();

int dpi = GetDpiForSystem();
float scale = (float)dpi / DefaultDpi;
float scale = DpiUtils.GetScale();

suggest.Width /= scale;
suggest.Height /= scale;

suggest = suggest.Integerization();
}

if (OperatingSystem.IsMacOS()) { }

if (OperatingSystem.IsLinux()) { }

return suggest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public sealed override void InitCommands()

LoadThirdPartyLicenseCommand = ReactiveCommand.Create(async () =>
{
var license = await FileHelper.ReadAllAsync(ConstantTable.ThirdPartLicenseFilePath);
var license = await FileHelper.ReadAllAsync(ConstantTable.ThirdPartyLicenseFilePath);

ThirdPartyLicenseString = license;
});
Expand All @@ -42,12 +42,12 @@ public sealed override void InitCommands()

internal static string VersionText => $"v{Assembly.GetEntryAssembly()?.GetName().Version}";

private string thirdPartyLicenseString = string.Empty;
private string _thirdPartyLicenseString = string.Empty;

internal string ThirdPartyLicenseString
{
get => thirdPartyLicenseString;
set => this.RaiseAndSetIfChanged(ref thirdPartyLicenseString, value);
get => _thirdPartyLicenseString;
set => this.RaiseAndSetIfChanged(ref _thirdPartyLicenseString, value);
}

public static bool AboutAreaExpanded
Expand Down
21 changes: 21 additions & 0 deletions Specific/KitX Dashboard Specific MsWindows/Graphics/DpiUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Runtime.InteropServices;

namespace KitX.Dashboard.Specific.MsWindows.Graphics;

public partial class DpiUtils
{
[LibraryImport("user32.dll")]
private static partial int GetDpiForSystem();

private const int DefaultDpi = 96;

public static int GetDpi() => GetDpiForSystem();

public static float GetScale()
{
int dpi = GetDpiForSystem();
float scale = (float)dpi / DefaultDpi;

return scale;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>KitX.Dashboard.Specific.MsWindows</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

</Project>

0 comments on commit 5b17387

Please sign in to comment.