From e7923d012078dc10ae15df380725c44933b464d4 Mon Sep 17 00:00:00 2001 From: Haze <709547807@qq.com> Date: Fri, 13 Mar 2026 13:24:50 +0800 Subject: [PATCH] fix(electron): improve error handling during app initialization and updater events (#461) --- electron/main/index.ts | 4 +++- electron/main/updater.ts | 6 ++++++ src/components/channels/ChannelConfigModal.tsx | 7 ++++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index 194bbfc4c..ec0a70b40 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -365,7 +365,9 @@ app.on('second-instance', () => { // Application lifecycle app.whenReady().then(() => { - initialize(); + void initialize().catch((error) => { + logger.error('Application initialization failed:', error); + }); // Register activate handler AFTER app is ready to prevent // "Cannot create BrowserWindow before app is ready" on macOS. diff --git a/electron/main/updater.ts b/electron/main/updater.ts index 735f3c108..9d3553918 100644 --- a/electron/main/updater.ts +++ b/electron/main/updater.ts @@ -52,6 +52,12 @@ export class AppUpdater extends EventEmitter { constructor() { super(); + + // EventEmitter treats an unhandled 'error' event as fatal. Keep a default + // listener so updater failures surface in logs/UI without terminating main. + this.on('error', (error: Error) => { + logger.error('[Updater] AppUpdater emitted error:', error); + }); autoUpdater.autoDownload = false; autoUpdater.autoInstallOnAppQuit = true; diff --git a/src/components/channels/ChannelConfigModal.tsx b/src/components/channels/ChannelConfigModal.tsx index c7cba3278..204a99b28 100644 --- a/src/components/channels/ChannelConfigModal.tsx +++ b/src/components/channels/ChannelConfigModal.tsx @@ -85,6 +85,7 @@ export function ChannelConfigModal({ } | null>(null); const meta: ChannelMeta | null = selectedType ? CHANNEL_META[selectedType] : null; + const shouldUseCredentialValidation = selectedType !== 'feishu'; useEffect(() => { setSelectedType(initialSelectedType); @@ -224,7 +225,7 @@ export function ChannelConfigModal({ }, [selectedType, finishSave, onClose, t]); const handleValidate = async () => { - if (!selectedType) return; + if (!selectedType || !shouldUseCredentialValidation) return; setValidating(true); setValidationResult(null); @@ -280,7 +281,7 @@ export function ChannelConfigModal({ return; } - if (meta.connectionType === 'token') { + if (meta.connectionType === 'token' && shouldUseCredentialValidation) { const validationResponse = await hostApiFetch<{ success: boolean; valid?: boolean; @@ -598,7 +599,7 @@ export function ChannelConfigModal({
- {meta?.connectionType === 'token' && ( + {meta?.connectionType === 'token' && shouldUseCredentialValidation && (