Skip to content

Commit

Permalink
修复 Toast部分情况下错误
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Aug 30, 2024
1 parent 017e0bd commit d4c5ad6
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 29 deletions.
4 changes: 4 additions & 0 deletions Core.Window/Core.Window.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

<PropertyGroup>
<TargetFrameworks>net8.0-windows10.0.17763.0</TargetFrameworks>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup>
<UseWPF>true</UseWPF>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<WindowsPackageType>None</WindowsPackageType>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,6 +31,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240802000" />
<PackageReference Include="Vanara.Core" Version="4.0.1"/>
<PackageReference Include="Vanara.PInvoke.FirewallApi" Version="4.0.1"/>
<PackageReference Include="Vanara.PInvoke.NetApi32" Version="4.0.1"/>
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net8.0-windows10.0.17763.0</TargetFrameworks>
<WindowsPackageType>None</WindowsPackageType>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

<PropertyGroup>
Expand Down
18 changes: 10 additions & 8 deletions Core/SDKs/Services/MQTT/MQTTManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using MQTTnet.Protocol;
using MQTTnet.Server;
using Newtonsoft.Json.Linq;
using PluginCore;

namespace Core.SDKs.Services.MQTT;

Expand Down Expand Up @@ -95,6 +96,7 @@ public static async Task Init()
Server.ClientConnectedAsync+= Server_ClientConnectedAsync;
Server.ClientDisconnectedAsync+= Server_ClientDisconnectedAsync;
Server.InterceptingPublishAsync += Server_InterceptingPublishAsync;



try
Expand Down Expand Up @@ -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<IToastService>().Show("来自URL的操作失败",$"下载安装插件ID:{jObject["pluginVersionInt"]}不存在");
break;
}
PluginManager.DownloadPluginOnline(onlinePluginInfo,int.Parse(jObject["pluginVersionInt"].ToString()));
ServiceManager.Services.GetService<IToastService>().Show("来自URL的操作",$"下载安装插件{onlinePluginInfo.Name}ID:{jObject["pluginVersionInt"]}成功");
break;
}
default:
Expand All @@ -165,7 +167,7 @@ private static async Task Server_InterceptingPublishAsync(InterceptingPublishEve
}
catch (Exception e)
{
Log.Error("错误",e);
Log.Error("来自URL的操作出现错误",e);
}

}
Expand Down
11 changes: 8 additions & 3 deletions Core/SDKs/Services/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ public static void DeletePluginWithoutCheck(PluginInfo pluginInfoEx)
CustomScenarioManger.Reload();
}

public static Task<OnlinePluginInfo> GetOnlinePluginInfo(int id)
public static Task<OnlinePluginInfo?> GetOnlinePluginInfo(int id)
{
return GetOnlinePluginInfo(id.ToString());
}
public static async Task<OnlinePluginInfo> GetOnlinePluginInfo(string pluginSignName)
public static async Task<OnlinePluginInfo?> GetOnlinePluginInfo(string pluginSignName)
{
try
{
Expand All @@ -382,7 +382,12 @@ public static async Task<OnlinePluginInfo> 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<OnlinePluginInfo>();
var jToken = deserializeObject["data"];
if (jToken.Type==JTokenType.Integer)
{
return null;
}
return jToken.ToObject<OnlinePluginInfo>();
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions Kitopia.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions KitopiaAvalonia/KitopiaAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<TargetFrameworks>net8.0-windows10.0.17763.0</TargetFrameworks>

<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<WindowsPackageType>None</WindowsPackageType>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
Expand All @@ -31,6 +33,8 @@
<DebugType Condition="'$(Configuration)' == 'Release'">none</DebugType>
<Version>0.0.2.073</Version>
<AvaloniaVersion>11.2.999-cibuild0050397-alpha</AvaloniaVersion>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>


Expand Down Expand Up @@ -70,7 +74,6 @@
<PackageReference Include="log4net" Version="2.0.17"/>
<PackageReference Include="Markdown.Avalonia" Version="11.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/>
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3"/>
<PackageReference Include="System.Drawing.Common" Version="8.0.6"/>
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 4 additions & 6 deletions KitopiaAvalonia/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<IToastService>().Unregister();
};
Task.Run(async () =>
{
Expand Down Expand Up @@ -193,7 +191,7 @@ public static void OnStartup(string[] arg)

MqttManager.Init().Wait();
log.Info("MQTT初始化完成");

ServiceManager.Services.GetService<IToastService>().Init();
HotKeyManager.Init();
log.Debug("注册热键管理器完成");
ConfigManger.Init();
Expand Down
35 changes: 29 additions & 6 deletions KitopiaAvalonia/Services/ToastService.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion KitopiaAvalonia/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion PluginCore
Submodule PluginCore updated 1 files
+2 −0 IToastService.cs

0 comments on commit d4c5ad6

Please sign in to comment.