From a04cb7cae702a80b290b8791389b436adc60454f Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Fri, 2 Dec 2022 20:47:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=9E=84=E5=BB=BA=E9=80=89=E9=A1=B9,=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=A8=E5=B1=80=E4=B8=BB=E7=AA=97=E4=BD=93?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E6=8C=87=E9=92=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 18 +++++++++++++++++- Views/MainWindow.axaml.cs | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 2ac0d006..15a40d44 100644 --- a/Program.cs +++ b/Program.cs @@ -2,6 +2,7 @@ using Avalonia.ReactiveUI; using KitX_Dashboard.Data; using KitX_Dashboard.Services; +using KitX_Dashboard.Views; using KitX_Dashboard.Views.Pages.Controls; using LiteDB; using System; @@ -28,6 +29,8 @@ internal class Program internal static LiteDatabase? ActivitiesDataBase; + internal static MainWindow? MainWindow; + /// /// 主函数, 应用程序入口; 展开 summary 查看警告 /// @@ -143,7 +146,20 @@ public static void Main(string[] args) /// Avalonia configuration, don't remove; also used by visual designer. /// Avalonia 配置项, 请不要删除; 同时也用于可视化设计器 public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() - .UsePlatformDetect().LogToTrace().UseReactiveUI(); + .UsePlatformDetect().LogToTrace().UseReactiveUI() + .With(new Win32PlatformOptions + { + UseWindowsUIComposition = true, + EnableMultitouch = true + }) + .With(new MacOSPlatformOptions + { + ShowInDock = true + }) + .With(new X11PlatformOptions + { + EnableMultiTouch = true + }); } } diff --git a/Views/MainWindow.axaml.cs b/Views/MainWindow.axaml.cs index 6f57bda3..3bb7186b 100644 --- a/Views/MainWindow.axaml.cs +++ b/Views/MainWindow.axaml.cs @@ -36,6 +36,8 @@ public MainWindow() { InitializeComponent(); + Program.MainWindow = this; + Resources["MainWindow"] = this; //(Resources["TrayIcon"] as TrayIcon).CommandParameter = this; @@ -91,6 +93,9 @@ public MainWindow() #endif } + /// + /// 建议分辨率和位置 + /// private void SuggestResolutionAndLocation() { if (Program.Config.Windows.MainWindow.Window_Width == 1280 From 3044231b28b15cd92f85c1826684d33e3f8389db Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Sat, 3 Dec 2022 00:38:44 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=BE=20Feat:=20=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=8F=92=E4=BB=B6=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?,=20=E4=BC=98=E5=8C=96=E4=BA=86=E9=BB=98=E8=AE=A4=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E8=B5=84=E6=BA=90=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.axaml.cs | 5 + Languages/en-us.axaml | 10 + Languages/fr-fr.axaml | 10 + Languages/ja-jp.axaml | 10 + Languages/ko-kr.axaml | 10 + Languages/ru-ru.axaml | 10 + Languages/zh-cn.axaml | 10 + Languages/zh-tw.axaml | 10 + .../Pages/Controls/PluginBarViewModel.cs | 21 +- .../Pages/Controls/PluginCardViewModel.cs | 2 +- ViewModels/PluginDetailWindowViewModel.cs | 183 +++++++++++++++ Views/PluginDetailWindow.axaml | 213 ++++++++++++++++++ Views/PluginDetailWindow.axaml.cs | 47 ++++ 13 files changed, 532 insertions(+), 9 deletions(-) create mode 100644 ViewModels/PluginDetailWindowViewModel.cs create mode 100644 Views/PluginDetailWindow.axaml create mode 100644 Views/PluginDetailWindow.axaml.cs diff --git a/App.axaml.cs b/App.axaml.cs index 49d68405..1c87dc09 100644 --- a/App.axaml.cs +++ b/App.axaml.cs @@ -3,6 +3,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using Avalonia.Media; +using Avalonia.Media.Imaging; using Common.BasicHelper.IO; using Common.BasicHelper.Util; using FluentAvalonia.Styling; @@ -14,6 +15,7 @@ using LiveChartsCore.SkiaSharpView; using Serilog; using System; +using System.IO; using System.Linq; using System.Threading; @@ -150,6 +152,9 @@ public override void OnFrameworkInitializationCompleted() base.OnFrameworkInitializationCompleted(); } + + public static Bitmap DefaultIcon = new(Path.GetFullPath( + $"{GlobalInfo.AssetsPath}{Program.Config.App.CoverIconFileName}")); } } diff --git a/Languages/en-us.axaml b/Languages/en-us.axaml index 87c8d9fa..49816ab1 100644 --- a/Languages/en-us.axaml +++ b/Languages/en-us.axaml @@ -67,6 +67,16 @@ Complex Description: Docs: Root Startup File Name: + Version: + Author: + Publisher: + Publish Date: + Last Update Date: + Is Market Version: + Docs + Root Startup File Name: + Functions List + Tags No other devices in network. This Device Slave diff --git a/Languages/fr-fr.axaml b/Languages/fr-fr.axaml index d3447e54..fc577653 100644 --- a/Languages/fr-fr.axaml +++ b/Languages/fr-fr.axaml @@ -67,6 +67,16 @@ décris: Documentation: nom de fichier racine de départ: + Version: + auteur: + Éditeur: + Date de publication: + Date de la dernière mise à jour: + Est-ce la version commerciale: + Documentation + Nom du fichier racine de démarrage: + Liste des fonctions + Balises Aucun autre appareil sur le réseau cet appareil trimer diff --git a/Languages/ja-jp.axaml b/Languages/ja-jp.axaml index 72a10089..a4ad8414 100644 --- a/Languages/ja-jp.axaml +++ b/Languages/ja-jp.axaml @@ -67,6 +67,16 @@ 説明: ドキュメンテーション: ルートファイル名の開始: + バージョン: + 著者: + 出版社: + 公開日: + 最終更新日: + 市場バージョンですか: + ドキュメント + 開始ルート ファイル名: + 関数リスト + タグ ネットワーク上に他のデバイスがない この装置 Slave diff --git a/Languages/ko-kr.axaml b/Languages/ko-kr.axaml index 549d9baf..66c1f497 100644 --- a/Languages/ko-kr.axaml +++ b/Languages/ko-kr.axaml @@ -67,6 +67,16 @@ 설명하다: 선적 서류 비치: 시작 루트 파일 이름: + 버전: + 작가: + 발행자: + 게시일: + 마지막 업데이트 날짜: + 마켓 버전인가요: + 문서 + 시작 루트 파일 이름: + 함수 목록 + 태그 네트워크에 다른 장치 없음 이 기기 노예 diff --git a/Languages/ru-ru.axaml b/Languages/ru-ru.axaml index 5e4a4f9d..2adacd1a 100644 --- a/Languages/ru-ru.axaml +++ b/Languages/ru-ru.axaml @@ -67,6 +67,16 @@ описывать: Документация: начальное корневое имя файла: + Версия: + автор: + Издатель: + Дата публикации: + Дата последнего обновления: + Это рыночная версия: + Документация + Имя начального корневого файла: + Список функций + Теги Нет других устройств в сети это устройство раб diff --git a/Languages/zh-cn.axaml b/Languages/zh-cn.axaml index 03b5c96e..3fb115ce 100644 --- a/Languages/zh-cn.axaml +++ b/Languages/zh-cn.axaml @@ -67,6 +67,16 @@ 描述: 文档: 起始根文件名: + 版本: + 作者: + 发行商: + 发布日期: + 最后更新日期: + 是否是市场版本: + 文档 + 起始根文件名: + 功能列表 + 标记 网络中没有其它设备 此设备 从控 diff --git a/Languages/zh-tw.axaml b/Languages/zh-tw.axaml index 96c28c7d..c63e2dca 100644 --- a/Languages/zh-tw.axaml +++ b/Languages/zh-tw.axaml @@ -67,6 +67,16 @@ 描述: 文檔: 起始根文件名: + 版本: + 作者: + 發行商: + 發行日期: + 最後更新日期: + 是否是市場版本: + 文檔 + 起始根文件名: + 功能列表 + 標記 網路中空無一物 本機 從控 diff --git a/ViewModels/Pages/Controls/PluginBarViewModel.cs b/ViewModels/Pages/Controls/PluginBarViewModel.cs index 4e5d627b..9e288181 100644 --- a/ViewModels/Pages/Controls/PluginBarViewModel.cs +++ b/ViewModels/Pages/Controls/PluginBarViewModel.cs @@ -1,14 +1,16 @@ -using KitX_Dashboard.Commands; +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using KitX_Dashboard.Commands; using KitX_Dashboard.Data; using KitX_Dashboard.Models; using KitX_Dashboard.Services; +using KitX_Dashboard.Views; using KitX_Dashboard.Views.Pages.Controls; using Serilog; using System; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics; -using System.Drawing; using System.IO; using System.Threading; @@ -22,7 +24,6 @@ public PluginBarViewModel() InitEvents(); } - internal void InitCommands() { ViewDetailsCommand = new(ViewDetails); @@ -74,15 +75,13 @@ internal Bitmap IconDisplay using var ms = new MemoryStream(src); return new(ms); } - else return new($"{GlobalInfo.AssetsPath}" + - $"{Program.Config.App.CoverIconFileName}"); + else return App.DefaultIcon; } catch (Exception e) { Log.Warning($"Icon transform error from base64 to byte[] or " + $"create bitmap from MemoryStream error: {e.Message}"); - return new($"{GlobalInfo.AssetsPath}" + - $"{Program.Config.App.CoverIconFileName}"); + return App.DefaultIcon; } } } @@ -101,7 +100,13 @@ internal Bitmap IconDisplay /// internal void ViewDetails(object _) { - + if (PluginDetail != null && Program.MainWindow != null) + new PluginDetailWindow() + { + WindowStartupLocation = WindowStartupLocation.CenterOwner + } + .SetPluginStruct(PluginDetail.PluginDetails) + .Show(Program.MainWindow); } /// diff --git a/ViewModels/Pages/Controls/PluginCardViewModel.cs b/ViewModels/Pages/Controls/PluginCardViewModel.cs index f6b66f4a..f8ec7edb 100644 --- a/ViewModels/Pages/Controls/PluginCardViewModel.cs +++ b/ViewModels/Pages/Controls/PluginCardViewModel.cs @@ -45,7 +45,7 @@ internal Bitmap IconDisplay { Log.Warning($"Icon transform error from base64 to byte[] or " + $"create bitmap from MemoryStream error: {e.Message}"); - return new($"{GlobalInfo.AssetsPath}{Program.Config.App.CoverIconFileName}"); + return App.DefaultIcon; } } } diff --git a/ViewModels/PluginDetailWindowViewModel.cs b/ViewModels/PluginDetailWindowViewModel.cs new file mode 100644 index 00000000..c5eaccc9 --- /dev/null +++ b/ViewModels/PluginDetailWindowViewModel.cs @@ -0,0 +1,183 @@ +using Avalonia.Controls; +using Avalonia.Media.Imaging; +using KitX.Web.Rules; +using KitX_Dashboard.Commands; +using Serilog; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KitX_Dashboard.ViewModels +{ + internal class PluginDetailWindowViewModel : ViewModelBase + { + public PluginDetailWindowViewModel() + { + InitCommands(); + } + + internal void InitCommands() + { + FinishCommand = new(Finish); + } + + internal PluginStruct? PluginDetail { get; set; } + + internal string? DisplayName + { + get + { + if (PluginDetail != null) + { + string key = Program.Config.App.AppLanguage; + bool? exist = PluginDetail?.DisplayName.ContainsKey(key); + if (exist != null && (bool)exist) + return PluginDetail?.DisplayName[key]; + else return PluginDetail?.Name; + } + else return PluginDetail?.Name; + } + } + + internal string? Version => PluginDetail?.Version; + + internal string? AuthorName => PluginDetail?.AuthorName; + + internal string? PublisherName => PluginDetail?.PublisherName; + + internal string? AuthorLink => PluginDetail?.AuthorLink; + + internal string? PublisherLink => PluginDetail?.PublisherLink; + + internal string? SimpleDescription + { + get + { + if (PluginDetail != null) + { + string key = Program.Config.App.AppLanguage; + bool? exist = PluginDetail?.SimpleDescription.ContainsKey(key); + if (exist != null && (bool)exist) + return PluginDetail?.SimpleDescription[key]; + else return PluginDetail?.SimpleDescription.Values.ToArray()[0]; + } + else return PluginDetail?.SimpleDescription.Values.ToArray()[0]; + } + } + + internal string? ComplexDescription + { + get + { + if (PluginDetail != null) + { + string key = Program.Config.App.AppLanguage; + bool? exist = PluginDetail?.ComplexDescription.ContainsKey(key); + if (exist != null && (bool)exist) + return PluginDetail?.ComplexDescription[key]; + else return PluginDetail?.ComplexDescription.Values.ToArray()[0]; + } + else return PluginDetail?.ComplexDescription.Values.ToArray()[0]; + } + } + + internal string? TotalDescriptionInMarkdown + { + get + { + if (PluginDetail != null) + { + string key = Program.Config.App.AppLanguage; + bool? exist = PluginDetail?.TotalDescriptionInMarkdown.ContainsKey(key); + if (exist != null && (bool)exist) + return PluginDetail?.TotalDescriptionInMarkdown[key]; + else return PluginDetail?.TotalDescriptionInMarkdown.Values.ToArray()[0]; + } + else return PluginDetail?.TotalDescriptionInMarkdown.Values.ToArray()[0]; + } + } + + internal string? PublishDate => PluginDetail?.PublishDate.ToString("yyyy.MM.dd"); + + internal string? LastUpdateDate => PluginDetail?.LastUpdateDate.ToString("yyyy.MM.dd"); + + private readonly ObservableCollection functions = new(); + + private readonly ObservableCollection tags = new(); + + internal Bitmap IconDisplay + { + get + { + try + { + if (PluginDetail != null) + { + byte[] src = Convert.FromBase64String(PluginDetail.Value.IconInBase64); + using var ms = new MemoryStream(src); + return new(ms); + } + else return App.DefaultIcon; + } + catch (Exception e) + { + Log.Warning($"Icon transform error from base64 to byte[] or " + + $"create bitmap from MemoryStream error: {e.Message}"); + return App.DefaultIcon; + } + } + } + + internal void InitFunctionsAndTags() + { + if (PluginDetail != null && PluginDetail?.Functions != null && PluginDetail?.Tags != null) + { + string langKey = Program.Config.App.AppLanguage; + foreach (var func in PluginDetail.Value.Functions) + { + StringBuilder sb = new(); + sb.Append(func.ReturnValueType); + sb.Append(" "); + if (func.DisplayNames.ContainsKey(langKey)) + sb.Append(func.DisplayNames[langKey]); + else sb.Append(func.Name); + sb.Append("("); + if (func.Parameters.Count != func.ParametersType.Count) + throw new InvalidDataException("Parameters return type count " + + "didn't match parameters count."); + int index = 0; + foreach (var param in func.Parameters) + { + sb.Append(func.ParametersType[index]); + ++index; + sb.Append(" "); + if (param.Value.ContainsKey(langKey)) + sb.Append(param.Value[langKey]); + else sb.Append(param.Key); + if (index != func.Parameters.Count) + sb.Append(", "); + } + sb.Append(")"); + Functions.Add(sb.ToString()); + } + foreach (var tag in PluginDetail.Value.Tags) + Tags.Add($"{{{tag.Key}: {tag.Value}}}"); + } + } + + internal ObservableCollection Functions => functions; + + internal ObservableCollection Tags => tags; + + internal DelegateCommand? FinishCommand { get; set; } + + internal void Finish(object parent) + { + (parent as Window)?.Close(); + } + } +} diff --git a/Views/PluginDetailWindow.axaml b/Views/PluginDetailWindow.axaml new file mode 100644 index 00000000..8a61a368 --- /dev/null +++ b/Views/PluginDetailWindow.axaml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +