34 lines
997 B
C#
Raw Normal View History

2025-10-11 18:25:59 +08:00
using Microsoft.Extensions.DependencyInjection;
using XiaoZhiSharp_MauiBlazorApp.Services;
namespace XiaoZhiSharp_MauiBlazorApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}
protected override Window CreateWindow(IActivationState? activationState)
{
var window = new Window(new MainPage()) { Title = "XiaoZhiSharp_MauiBlazorApp" };
// 添加窗口关闭事件处理
window.Destroying += Window_Destroying;
return window;
}
private void Window_Destroying(object? sender, EventArgs e)
{
// 在窗口关闭时获取XiaoZhi_AgentService并释放
var agentService = IPlatformApplication.Current?.Services?.GetService<XiaoZhi_AgentService>();
if (agentService != null)
{
agentService.Dispose();
}
}
}
}