功能优化

This commit is contained in:
2025-07-25 14:47:06 +08:00
parent 9b69c232a3
commit d31dc9003d
2 changed files with 178 additions and 9 deletions

View File

@@ -199,9 +199,31 @@ export function setupIPC() {
newWindow.loadURL(url);
// 可选:添加错误处理
// 添加重试机制的错误处理
let failLoadCount = 0;
const maxRetries = 2;
const retryDelay = 1000;
newWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
console.error('页面加载失败:', errorDescription);
failLoadCount++;
if (failLoadCount <= maxRetries) {
console.log(`页面加载失败,${retryDelay}ms后进行第${failLoadCount}次重试...`);
setTimeout(() => {
newWindow.reload();
}, retryDelay);
} else {
console.error('页面加载失败次数超过最大重试次数');
}
});
// 页面加载成功时重置失败计数
newWindow.webContents.on('did-finish-load', () => {
if (failLoadCount > 0) {
console.log('页面加载成功,重置失败计数');
failLoadCount = 0;
}
});
return 'success';
@@ -222,9 +244,31 @@ export function setupIPC() {
newWindow.loadURL(url);
// 可选:添加错误处理
// 添加重试机制的错误处理
let failLoadCount2 = 0;
const maxRetries2 = 2;
const retryDelay2 = 1000;
newWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
console.error('页面加载失败:', errorDescription);
failLoadCount2++;
if (failLoadCount2 <= maxRetries2) {
console.log(`页面加载失败,${retryDelay2}ms后进行第${failLoadCount2}次重试...`);
setTimeout(() => {
newWindow.reload();
}, retryDelay2);
} else {
console.error('页面加载失败次数超过最大重试次数');
}
});
// 页面加载成功时重置失败计数
newWindow.webContents.on('did-finish-load', () => {
if (failLoadCount2 > 0) {
console.log('页面加载成功,重置失败计数');
failLoadCount2 = 0;
}
});
return 'success';