-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
145 lines (127 loc) · 5.69 KB
/
App.xaml.cs
File metadata and controls
145 lines (127 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
namespace TimeTask
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
// 增强型语音监听服务
private EnhancedAudioCaptureService _enhancedAudioService;
// 原有的录音服务(保留备用)
private AudioCaptureService _legacyAudioService;
// 任务草稿管理器
private TaskDraftManager _draftManager;
// 通知管理器
private NotificationManager _notificationManager;
// 自动更新服务
private AutoUpdateService _autoUpdateService;
protected override void OnStartup(StartupEventArgs e)
{
I18n.InitializeFromSettings();
base.OnStartup(e); // Call base implementation
VoiceRuntimeLog.Info("App startup.");
VoiceRuntimeLog.Info($"ProcessBitness: {(Environment.Is64BitProcess ? "x64" : "x86")}, OS: {(Environment.Is64BitOperatingSystem ? "x64" : "x86")}");
VoiceRuntimeLog.Info($"BaseDirectory: {AppDomain.CurrentDomain.BaseDirectory}");
VoiceRuntimeLog.Info($"Config: VoiceAsrProvider={ConfigurationManager.AppSettings["VoiceAsrProvider"]}, FunAsrAutoBootstrap={ConfigurationManager.AppSettings["FunAsrAutoBootstrap"]}");
VoiceListenerStatusCenter.Publish(VoiceListenerState.Unavailable, I18n.T("Voice_StatusUnavailable"));
FunAsrRuntimeManager.KickoffIfNeeded();
// 启动自动更新检查(后台执行)
try
{
_autoUpdateService = new AutoUpdateService(Dispatcher);
_autoUpdateService.StartBackgroundCheck();
}
catch (Exception ex)
{
VoiceRuntimeLog.Error("AutoUpdateService startup failed.", ex);
}
// Check for API Key configuration
string apiKey = System.Configuration.ConfigurationManager.AppSettings["OpenAIApiKey"];
const string PlaceholderApiKey = "YOUR_API_KEY_GOES_HERE";
if (string.IsNullOrWhiteSpace(apiKey) || apiKey == PlaceholderApiKey)
{
System.Windows.MessageBox.Show(
I18n.T("App_ApiKeyWarningText"),
I18n.T("App_ApiKeyWarningTitle"),
System.Windows.MessageBoxButton.OK,
System.Windows.MessageBoxImage.Warning
);
}
// 初始化草稿管理器
try
{
_draftManager = new TaskDraftManager();
Console.WriteLine($"[App] TaskDraftManager initialized. Current drafts: {_draftManager.Count}");
}
catch (Exception ex)
{
Console.WriteLine($"[App] Failed to initialize TaskDraftManager: {ex.Message}");
}
// 启动通知管理器
try
{
_notificationManager = new NotificationManager(_draftManager);
Console.WriteLine("[App] NotificationManager initialized.");
}
catch (Exception ex)
{
Console.WriteLine($"[App] Failed to initialize NotificationManager: {ex.Message}");
}
// 启动增强型智能语音监听服务
try
{
_enhancedAudioService = new EnhancedAudioCaptureService();
_enhancedAudioService.Start();
var stats = _enhancedAudioService.GetStats();
Console.WriteLine($"[App] EnhancedAudioCaptureService started. Stats: {stats.totalDetections} detections, {stats.potentialTasks} potential tasks");
}
catch (Exception ex)
{
Console.WriteLine($"[App] EnhancedAudioCaptureService start failed: {ex.Message}");
VoiceRuntimeLog.Error("EnhancedAudioCaptureService start failed.", ex);
// 回退到原有服务
Console.WriteLine("[App] Falling back to legacy AudioCaptureService...");
try
{
_legacyAudioService = new AudioCaptureService();
_legacyAudioService.Start();
VoiceRuntimeLog.Info("Legacy AudioCaptureService started as fallback.");
VoiceListenerStatusCenter.Publish(VoiceListenerState.Ready, I18n.T("Voice_StatusReady"));
}
catch (Exception ex2)
{
Console.WriteLine($"[App] Legacy AudioCaptureService also failed: {ex2.Message}");
VoiceRuntimeLog.Error("Legacy AudioCaptureService start failed.", ex2);
VoiceListenerStatusCenter.Publish(VoiceListenerState.Unavailable, I18n.T("Voice_StatusUnavailable"));
MessageBox.Show(
I18n.Tf("App_VoiceInitFailedTextFormat", VoiceRuntimeLog.LogFilePath),
I18n.T("App_VoiceInitFailedTitle"),
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}
}
protected override void OnExit(ExitEventArgs e)
{
try
{
_notificationManager?.Dispose();
_notificationManager = null;
_enhancedAudioService?.Dispose();
_enhancedAudioService = null;
_legacyAudioService?.Dispose();
_legacyAudioService = null;
_draftManager?.Dispose();
_draftManager = null;
}
catch { }
base.OnExit(e);
}
}
}