Skip to content

Commit

Permalink
💾 Feat: Merge pull request #57 from Crequency/dev=main
Browse files Browse the repository at this point in the history
[Pull Request] 公告系统完工, 一些UI修复
  • Loading branch information
Dynesshely authored Aug 11, 2022
2 parents 5c023dd + 5d63b24 commit c66d4c7
Show file tree
Hide file tree
Showing 26 changed files with 412 additions and 115 deletions.
52 changes: 28 additions & 24 deletions KitX Contracts/KitX.Contract.CSharp/KitX.Contract.CSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<BaseOutputPath>..\..\KitX Build\Contracts\CSharp\</BaseOutputPath>
<BaseIntermediateOutputPath>..\..\KitX Build\Temp\Contracts\CSharp\</BaseIntermediateOutputPath>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Dynesshely</Authors>
<Company>Crequency</Company>
<Description>Contract for KitX plugins about C#.</Description>
<PackageProjectUrl>https://github.com/Crequency/KitX/</PackageProjectUrl>
<PackageIcon>KitX-Background-ani.png</PackageIcon>
<RepositoryUrl>https://github.com/Crequency/KitX/</RepositoryUrl>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable>
<BaseOutputPath>..\..\KitX Build\Contracts\CSharp\</BaseOutputPath>
<BaseIntermediateOutputPath>..\..\KitX Build\Temp\Contracts\CSharp\</BaseIntermediateOutputPath>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>Dynesshely</Authors>
<Company>Crequency</Company>
<Description>Contract for KitX plugins about C#.</Description>
<PackageProjectUrl>https://github.com/Crequency/KitX/</PackageProjectUrl>
<PackageIcon>KitX-Background-ani.png</PackageIcon>
<RepositoryUrl>https://github.com/Crequency/KitX/</RepositoryUrl>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>

<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" Version="6.0.0" />
</ItemGroup>
<AssemblyVersion>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</AssemblyVersion>
<FileVersion>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</FileVersion>
<Version>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</Version>
</PropertyGroup>

<ItemGroup>
<None Update="KitX-Background-ani.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ComponentModel.Composition" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="KitX-Background-ani.png">
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
</ItemGroup>

</Project>
55 changes: 46 additions & 9 deletions KitX Dashboard/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
using KitX_Dashboard.Views;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;

#pragma warning disable CS8604 // 引用类型参数可能为 null。
#pragma warning disable CS8602 // 解引用可能出现空引用。

namespace KitX_Dashboard
{
Expand Down Expand Up @@ -81,38 +83,73 @@ public override async void OnFrameworkInitializationCompleted()

public static async Task CheckNewAnnouncements()
{
HttpClient client = new();
client.DefaultRequestHeaders.Accept.Clear();
HttpClient client = new(); // Http客户端
client.DefaultRequestHeaders.Accept.Clear(); // 清除请求头部

// 链接头部
string linkBase = $"http://" +
$"{Program.GlobalConfig.Config_App.APIServer}" +
$"{Program.GlobalConfig.Config_App.APIPath}";

// 获取公告列表的api链接
string link = $"{linkBase}{GlobalInfo.Api_Get_Announcements}";

// 公告列表
string msg = await client.GetStringAsync(link);
List<string>? list = JsonSerializer.Deserialize<List<string>>(msg);

// 本地已阅列表
List<string>? readed;
string confPath = Path.GetFullPath(GlobalInfo.AnnouncementsJsonPath);
if (File.Exists(confPath))
readed = JsonSerializer.Deserialize<List<string>>(
await FileHelper.ReadAllAsync(confPath)
);
else
{
readed = new()
{
"2022-05-02 11:54:29"
};
}

// 未阅读列表
List<DateTime> unreads = new();

// 添加没有阅读的公告到未阅读列表
if (list != null)
foreach (var item in list)
{
DateTime thisTurn = DateTime.Parse(item);
if (thisTurn.CompareTo(Program.GlobalConfig.Config_App.LastShowedAnnouncement) > 0)
unreads.Add(thisTurn);
}
List<string> markdown = new();
if (!readed.Contains(item))
unreads.Add(DateTime.Parse(item));

// 公告列表<发布时间, 公告内容>
Dictionary<string, string> src = new();
foreach (var item in unreads)
{
// 获取单个公告的链接
string apiLink = $"{linkBase}{GlobalInfo.Api_Get_Announcement}" +
$"?" +
$"lang={Program.GlobalConfig.Config_App.AppLanguage}" +
$"&" +
$"date={item:yyyy-MM-dd HH-mm}";
markdown.Add(JsonSerializer.Deserialize<string>(await client.GetStringAsync(apiLink)));
string? md = JsonSerializer.Deserialize<string>(await client.GetStringAsync(apiLink));
src.Add(item.ToString("yyyy-MM-dd HH:mm"), md);
}

// 结束Http客户端
client.Dispose();

if (unreads.Count > 0)
{
var toast = new AnnouncementsWindow();
toast.UpdateSource(src, readed);
toast.Show();
}
}
}
}

#pragma warning restore CS8602 // 解引用可能出现空引用。
#pragma warning restore CS8604 // 引用类型参数可能为 null。

// .....'',;;::cccllllllllllllcccc:::;;,,,''...'',,'..
Expand Down
10 changes: 3 additions & 7 deletions KitX Dashboard/Data/Config.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace KitX_Dashboard.Data
Expand Down Expand Up @@ -58,9 +57,6 @@ public class App

[JsonInclude]
public string APIPath { get; set; } = "/apps/kitx/";

[JsonInclude]
public DateTime LastShowedAnnouncement { get; set; } = DateTime.Parse("2022-05-02 11:54:29");
}

/// <summary>
Expand Down Expand Up @@ -129,10 +125,10 @@ public class MainWindow
public class AnnouncementWindow
{
[JsonInclude]
public double Window_Width { get; set; } = 600;
public double Window_Width { get; set; } = 1280;

[JsonInclude]
public double Window_Height { get; set; } = 800;
public double Window_Height { get; set; } = 720;

[JsonInclude]
public int Window_Left { get; set; } = -1;
Expand Down
2 changes: 2 additions & 0 deletions KitX Dashboard/Data/GlobalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal static class GlobalInfo

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

internal const string AnnouncementsJsonPath = "./Config/announcements.json";

}
}

Expand Down
6 changes: 3 additions & 3 deletions KitX Dashboard/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public static void LoadConfig()
/// </summary>
public static void InitConfig()
{

if (!Directory.Exists(ConfigPath))
if (!File.Exists($"{ConfigPath}/config.json"))
{
Directory.CreateDirectory(ConfigPath);
if (!Directory.Exists(ConfigPath))
Directory.CreateDirectory(ConfigPath);
SaveConfig();
}
else LoadConfig();
Expand Down
39 changes: 23 additions & 16 deletions KitX Dashboard/KitX Dashboard.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<AssemblyVersion>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</AssemblyVersion>
<FileVersion>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</FileVersion>
<Version>3.22.04.$([System.DateTime]::UtcNow.Date.Subtract($([System.DateTime]::Parse("2005-07-16"))).TotalDays)</Version>

</PropertyGroup>

<!--<PropertyGroup>
Expand Down Expand Up @@ -93,12 +93,12 @@
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
</ItemGroup>
<ItemGroup>
<Page Include="Assets\Fonts\SourceHanSans-VF.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Page>
<Page Include="Assets\Fonts\SourceHanSans-VF.ttf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KitX Rules\KitX.Web.Rules\KitX.Web.Rules.csproj" />
<ProjectReference Include="..\KitX Rules\KitX.Web.Rules\KitX.Web.Rules.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Assets\avalonia-logo.ico">
Expand Down Expand Up @@ -129,19 +129,26 @@
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AvaloniaResource>
<None Update="Assets\ThirdPartLicense.md">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<AvaloniaResource Update="Assets\Fonts\SourceHanSans-VF.ttf">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AvaloniaResource>
<Compile Update="Views\Pages\Controls\DeviceCard.axaml.cs">
<DependentUpon>DeviceCard.axaml</DependentUpon>
</Compile>
<None Update="Assets\KitX.Base64.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<AvaloniaResource Update="Assets\Fonts\SourceHanSans-VF.ttf">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</AvaloniaResource>
<Compile Update="Views\AnnouncementsWindow.axaml.cs">
<DependentUpon>AnnouncementsWindow.axaml</DependentUpon>
</Compile>
<Compile Update="Views\Pages\Controls\DeviceCard.axaml.cs">
<DependentUpon>DeviceCard.axaml</DependentUpon>
</Compile>
<None Update="Assets\KitX.Base64.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties properties_4launchsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
<ProjectExtensions>
<VisualStudio>
<UserProperties properties_4launchsettings_1json__JsonSchema="" />
</VisualStudio>
</ProjectExtensions>
</Project>
4 changes: 4 additions & 0 deletions KitX Dashboard/Languages/en-us.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@
<x:String x:Key="Text_Settings_Tab_About_Links">Links</x:String>
<x:String x:Key="Text_Settings_Tab_About_ThirdPartLicense">Third-Part License</x:String>


<x:String x:Key="Text_AnouncementWindow_Receive">Receive</x:String>
<x:String x:Key="Text_AnouncementWindow_ReceiveAll">Receive All</x:String>

</ResourceDictionary>
4 changes: 4 additions & 0 deletions KitX Dashboard/Languages/ja-jp.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@
<x:String x:Key="Text_Settings_Tab_About_Links">リンク</x:String>
<x:String x:Key="Text_Settings_Tab_About_ThirdPartLicense">サードパーティライセンス</x:String>


<x:String x:Key="Text_AnouncementWindow_Receive">受け取る</x:String>
<x:String x:Key="Text_AnouncementWindow_ReceiveAll">すべて受け取る</x:String>

</ResourceDictionary>
4 changes: 4 additions & 0 deletions KitX Dashboard/Languages/zh-cn.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,9 @@
<x:String x:Key="Text_Settings_Tab_About_Authors">制作人员</x:String>
<x:String x:Key="Text_Settings_Tab_About_Links">友情链接</x:String>
<x:String x:Key="Text_Settings_Tab_About_ThirdPartLicense">第三方许可</x:String>


<x:String x:Key="Text_AnouncementWindow_Receive">收到</x:String>
<x:String x:Key="Text_AnouncementWindow_ReceiveAll">收到全部</x:String>

</ResourceDictionary>
4 changes: 4 additions & 0 deletions KitX Dashboard/Languages/zh-cnt.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@
<x:String x:Key="Text_Settings_Tab_About_Links">友情鏈接</x:String>
<x:String x:Key="Text_Settings_Tab_About_ThirdPartLicense">第三方許可</x:String>


<x:String x:Key="Text_AnouncementWindow_Receive">收到</x:String>
<x:String x:Key="Text_AnouncementWindow_ReceiveAll">收到全部</x:String>

</ResourceDictionary>
Loading

0 comments on commit c66d4c7

Please sign in to comment.