fix(electron): improve error handling during app initialization and updater events (#461)

This commit is contained in:
Haze
2026-03-13 13:24:50 +08:00
committed by GitHub
Unverified
parent abc0c6e7d5
commit e7923d0120
3 changed files with 13 additions and 4 deletions

View File

@@ -365,7 +365,9 @@ app.on('second-instance', () => {
// Application lifecycle // Application lifecycle
app.whenReady().then(() => { app.whenReady().then(() => {
initialize(); void initialize().catch((error) => {
logger.error('Application initialization failed:', error);
});
// Register activate handler AFTER app is ready to prevent // Register activate handler AFTER app is ready to prevent
// "Cannot create BrowserWindow before app is ready" on macOS. // "Cannot create BrowserWindow before app is ready" on macOS.

View File

@@ -53,6 +53,12 @@ export class AppUpdater extends EventEmitter {
constructor() { constructor() {
super(); 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.autoDownload = false;
autoUpdater.autoInstallOnAppQuit = true; autoUpdater.autoInstallOnAppQuit = true;

View File

@@ -85,6 +85,7 @@ export function ChannelConfigModal({
} | null>(null); } | null>(null);
const meta: ChannelMeta | null = selectedType ? CHANNEL_META[selectedType] : null; const meta: ChannelMeta | null = selectedType ? CHANNEL_META[selectedType] : null;
const shouldUseCredentialValidation = selectedType !== 'feishu';
useEffect(() => { useEffect(() => {
setSelectedType(initialSelectedType); setSelectedType(initialSelectedType);
@@ -224,7 +225,7 @@ export function ChannelConfigModal({
}, [selectedType, finishSave, onClose, t]); }, [selectedType, finishSave, onClose, t]);
const handleValidate = async () => { const handleValidate = async () => {
if (!selectedType) return; if (!selectedType || !shouldUseCredentialValidation) return;
setValidating(true); setValidating(true);
setValidationResult(null); setValidationResult(null);
@@ -280,7 +281,7 @@ export function ChannelConfigModal({
return; return;
} }
if (meta.connectionType === 'token') { if (meta.connectionType === 'token' && shouldUseCredentialValidation) {
const validationResponse = await hostApiFetch<{ const validationResponse = await hostApiFetch<{
success: boolean; success: boolean;
valid?: boolean; valid?: boolean;
@@ -598,7 +599,7 @@ export function ChannelConfigModal({
<div className="flex flex-col sm:flex-row sm:justify-end gap-3 pt-2"> <div className="flex flex-col sm:flex-row sm:justify-end gap-3 pt-2">
<div className="flex flex-col sm:flex-row gap-2"> <div className="flex flex-col sm:flex-row gap-2">
{meta?.connectionType === 'token' && ( {meta?.connectionType === 'token' && shouldUseCredentialValidation && (
<Button <Button
variant="outline" variant="outline"
onClick={handleValidate} onClick={handleValidate}