From d4c5ad65314048a0a968c5d27d4117a63417606d Mon Sep 17 00:00:00 2001
From: MakesYT <2696703792@qq.com>
Date: Fri, 30 Aug 2024 19:16:11 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Toast=E9=83=A8=E5=88=86?=
=?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Core.Window/Core.Window.csproj | 4 +++
Core/Core.csproj | 2 ++
Core/SDKs/Services/MQTT/MQTTManager.cs | 18 ++++++-----
Core/SDKs/Services/Plugin/PluginManager.cs | 11 +++++--
Kitopia.sln | 4 +--
KitopiaAvalonia/KitopiaAvalonia.csproj | 7 +++--
KitopiaAvalonia/Program.cs | 10 +++---
KitopiaAvalonia/Services/ToastService.cs | 35 +++++++++++++++++----
KitopiaAvalonia/Windows/MainWindow.axaml.cs | 2 +-
PluginCore | 2 +-
10 files changed, 66 insertions(+), 29 deletions(-)
diff --git a/Core.Window/Core.Window.csproj b/Core.Window/Core.Window.csproj
index ca8d900..905c35c 100644
--- a/Core.Window/Core.Window.csproj
+++ b/Core.Window/Core.Window.csproj
@@ -2,6 +2,7 @@
net8.0-windows10.0.17763.0
+ win-x86;win-x64;win-arm64
true
@@ -9,6 +10,8 @@
enable
enable
true
+ None
+ true
@@ -28,6 +31,7 @@
+
diff --git a/Core/Core.csproj b/Core/Core.csproj
index 340bc7e..fe55cfd 100644
--- a/Core/Core.csproj
+++ b/Core/Core.csproj
@@ -4,6 +4,8 @@
net8.0-windows10.0.17763.0
+ None
+ true
diff --git a/Core/SDKs/Services/MQTT/MQTTManager.cs b/Core/SDKs/Services/MQTT/MQTTManager.cs
index c0c91c2..3626791 100644
--- a/Core/SDKs/Services/MQTT/MQTTManager.cs
+++ b/Core/SDKs/Services/MQTT/MQTTManager.cs
@@ -11,6 +11,7 @@
using MQTTnet.Protocol;
using MQTTnet.Server;
using Newtonsoft.Json.Linq;
+using PluginCore;
namespace Core.SDKs.Services.MQTT;
@@ -95,6 +96,7 @@ public static async Task Init()
Server.ClientConnectedAsync+= Server_ClientConnectedAsync;
Server.ClientDisconnectedAsync+= Server_ClientDisconnectedAsync;
Server.InterceptingPublishAsync += Server_InterceptingPublishAsync;
+
try
@@ -148,15 +150,15 @@ private static async Task Server_InterceptingPublishAsync(InterceptingPublishEve
{
//0 : pluginId
//1 : pluginVersionInt
- if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime appLifetime)
+
+ var onlinePluginInfo =await PluginManager.GetOnlinePluginInfo(int.Parse(jObject["pluginId"].ToString()));
+ if (onlinePluginInfo == null)
{
- var onlinePluginInfo =await PluginManager.GetOnlinePluginInfo(int.Parse(jObject["pluginId"].ToString()));
- if (onlinePluginInfo == null)
- {
- break;
- }
- PluginManager.DownloadPluginOnline(onlinePluginInfo,int.Parse(jObject["pluginVersionInt"].ToString()));
+ ServiceManager.Services.GetService().Show("来自URL的操作失败",$"下载安装插件ID:{jObject["pluginVersionInt"]}不存在");
+ break;
}
+ PluginManager.DownloadPluginOnline(onlinePluginInfo,int.Parse(jObject["pluginVersionInt"].ToString()));
+ ServiceManager.Services.GetService().Show("来自URL的操作",$"下载安装插件{onlinePluginInfo.Name}ID:{jObject["pluginVersionInt"]}成功");
break;
}
default:
@@ -165,7 +167,7 @@ private static async Task Server_InterceptingPublishAsync(InterceptingPublishEve
}
catch (Exception e)
{
- Log.Error("错误",e);
+ Log.Error("来自URL的操作出现错误",e);
}
}
diff --git a/Core/SDKs/Services/Plugin/PluginManager.cs b/Core/SDKs/Services/Plugin/PluginManager.cs
index d5ff2b7..247901e 100644
--- a/Core/SDKs/Services/Plugin/PluginManager.cs
+++ b/Core/SDKs/Services/Plugin/PluginManager.cs
@@ -365,11 +365,11 @@ public static void DeletePluginWithoutCheck(PluginInfo pluginInfoEx)
CustomScenarioManger.Reload();
}
- public static Task GetOnlinePluginInfo(int id)
+ public static Task GetOnlinePluginInfo(int id)
{
return GetOnlinePluginInfo(id.ToString());
}
- public static async Task GetOnlinePluginInfo(string pluginSignName)
+ public static async Task GetOnlinePluginInfo(string pluginSignName)
{
try
{
@@ -382,7 +382,12 @@ public static async Task GetOnlinePluginInfo(string pluginSign
var sendAsync =await _httpClient.SendAsync(request);
var stringAsync =await sendAsync.Content.ReadAsStringAsync();
var deserializeObject = (JObject)JsonConvert.DeserializeObject(stringAsync);
- return deserializeObject["data"].ToObject();
+ var jToken = deserializeObject["data"];
+ if (jToken.Type==JTokenType.Integer)
+ {
+ return null;
+ }
+ return jToken.ToObject();
}
catch (Exception e)
{
diff --git a/Kitopia.sln b/Kitopia.sln
index f5668d7..500659d 100644
--- a/Kitopia.sln
+++ b/Kitopia.sln
@@ -115,8 +115,6 @@ Global
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|ARM.Build.0 = Debug|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|arm64.ActiveCfg = Debug|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|arm64.Build.0 = Debug|Any CPU
- {595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x64.ActiveCfg = Debug|Any CPU
- {595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x64.Build.0 = Debug|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x86.ActiveCfg = Debug|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x86.Build.0 = Debug|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -129,6 +127,8 @@ Global
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Release|x64.Build.0 = Release|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Release|x86.ActiveCfg = Release|Any CPU
{595EC7E6-699C-4E29-B958-098510A2BEEB}.Release|x86.Build.0 = Release|Any CPU
+ {595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x64.ActiveCfg = Debug|x64
+ {595EC7E6-699C-4E29-B958-098510A2BEEB}.Debug|x64.Build.0 = Debug|x64
{C54EDD27-6A70-45D6-AF11-386DC4ACF139}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C54EDD27-6A70-45D6-AF11-386DC4ACF139}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C54EDD27-6A70-45D6-AF11-386DC4ACF139}.Debug|ARM.ActiveCfg = Debug|Any CPU
diff --git a/KitopiaAvalonia/KitopiaAvalonia.csproj b/KitopiaAvalonia/KitopiaAvalonia.csproj
index 10246fb..db6707e 100644
--- a/KitopiaAvalonia/KitopiaAvalonia.csproj
+++ b/KitopiaAvalonia/KitopiaAvalonia.csproj
@@ -4,7 +4,9 @@
net8.0-windows10.0.17763.0
-
+ win-x86;win-x64;win-arm64
+ None
+ true
@@ -31,6 +33,8 @@
none
0.0.2.073
11.2.999-cibuild0050397-alpha
+ Debug;Release
+ AnyCPU;x64
@@ -70,7 +74,6 @@
-
diff --git a/KitopiaAvalonia/Program.cs b/KitopiaAvalonia/Program.cs
index c8ad3fd..adec42a 100644
--- a/KitopiaAvalonia/Program.cs
+++ b/KitopiaAvalonia/Program.cs
@@ -30,8 +30,6 @@
using KitopiaAvalonia.Windows;
using log4net;
using log4net.Config;
-
-using Microsoft.Toolkit.Uwp.Notifications;
using PluginCore;
using HotKeyManager = Core.SDKs.HotKey.HotKeyManager;
using ScreenCaptureWindow = KitopiaAvalonia.Services.ScreenCaptureWindow;
@@ -55,13 +53,13 @@ public static void Main(string[] args)
try
{
// RxApp.DefaultExceptionHandler = new MyCoolObservableExceptionHandler();
- TaskScheduler.UnobservedTaskException += (sender, eventArgs) => { log.Error(eventArgs.Exception); };
+ TaskScheduler.UnobservedTaskException += (sender, eventArgs) => { log.Error("错误",eventArgs.Exception); };
- AppDomain.CurrentDomain.UnhandledException += (sender, e) => { log.Fatal(e.ExceptionObject); };
+ AppDomain.CurrentDomain.UnhandledException += (sender, e) => { log.Fatal("错误",(Exception)e.ExceptionObject); };
AppDomain.CurrentDomain.ProcessExit += (sender, e) =>
{
log.Info("程序退出");
- ToastNotificationManagerCompat.Uninstall();
+ ServiceManager.Services.GetService().Unregister();
};
Task.Run(async () =>
{
@@ -193,7 +191,7 @@ public static void OnStartup(string[] arg)
MqttManager.Init().Wait();
log.Info("MQTT初始化完成");
-
+ ServiceManager.Services.GetService().Init();
HotKeyManager.Init();
log.Debug("注册热键管理器完成");
ConfigManger.Init();
diff --git a/KitopiaAvalonia/Services/ToastService.cs b/KitopiaAvalonia/Services/ToastService.cs
index 2224461..925f612 100644
--- a/KitopiaAvalonia/Services/ToastService.cs
+++ b/KitopiaAvalonia/Services/ToastService.cs
@@ -1,7 +1,10 @@
#region
+using System.Threading.Tasks;
+using System.Windows.Threading;
using log4net;
-using Microsoft.Toolkit.Uwp.Notifications;
+using Microsoft.Windows.AppNotifications;
+using Microsoft.Windows.AppNotifications.Builder;
using PluginCore;
#endregion
@@ -12,13 +15,33 @@ public class ToastService : IToastService
{
private static readonly ILog log = LogManager.GetLogger(nameof(ToastService));
+ public void Init()
+ {
+ AppNotificationManager notificationManager = AppNotificationManager.Default;
+
+ notificationManager.NotificationInvoked += OnNotificationInvoked;
+
+ notificationManager.Register();
+ }
+
+ private void OnNotificationInvoked(AppNotificationManager sender, AppNotificationActivatedEventArgs args)
+ {
+
+ }
+
public void Show(string header, string text)
{
- log.Debug(nameof(ToastService) + "的接口" + nameof(Show) + "被调用");
- new ToastContentBuilder()
- .AddText(header)
- .AddText(text)
- .Show();
+ log.Debug($"{nameof(ToastService)}的接口{nameof(Show)}被调用,header:{header},text:{text}");
+ var appNotification = new AppNotificationBuilder()
+ .AddText(header)
+ .AddText(text)
+ .BuildNotification();
+ AppNotificationManager.Default.Show(appNotification);
+ }
+
+ public void Unregister()
+ {
+ AppNotificationManager.Default.Unregister();
}
}
\ No newline at end of file
diff --git a/KitopiaAvalonia/Windows/MainWindow.axaml.cs b/KitopiaAvalonia/Windows/MainWindow.axaml.cs
index e889b0e..8bb3d6b 100644
--- a/KitopiaAvalonia/Windows/MainWindow.axaml.cs
+++ b/KitopiaAvalonia/Windows/MainWindow.axaml.cs
@@ -14,7 +14,7 @@
using Core.SDKs.Services.Plugin;
using Core.ViewModel;
using log4net;
-using Microsoft.Extensions.DependencyInjection;
+
using Ursa.Controls;
using HotKeyManager = Core.SDKs.HotKey.HotKeyManager;
diff --git a/PluginCore b/PluginCore
index 55342e9..d026ed5 160000
--- a/PluginCore
+++ b/PluginCore
@@ -1 +1 @@
-Subproject commit 55342e96a37011a98d2c23db803525e475efc817
+Subproject commit d026ed5000fb3f922ac6bf2cad4eac1e37da63bd