优化重启逻辑

This commit is contained in:
2025-07-18 18:27:37 +08:00
parent 6fe479448c
commit f667c26650
42 changed files with 362 additions and 1370 deletions

View File

@@ -5,6 +5,7 @@ import icon from '../../resources/icon.png?asset'
import { isApiDatasetsDocumentsPath, extractIdFromPath } from './utils/difyUtils.js'
import XEUtils from 'xe-utils'
import logger from './utils/logger'
import { checkDefaultClientConnection } from './utils/networkUtils.js'
import { createMenu } from './menu.js'
import { setStoreValue, getStoreValue,deleteStore } from './store.js'
@@ -166,16 +167,38 @@ export async function createWindow() {
// 加载存储的 URL
mainWindow.loadURL(h5_client_url)
// 监听页面加载失败事件
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL) => {
logger.error(`主窗口页面加载失败: code=${errorCode}, desc=${errorDescription}, url=${validatedURL}`)
// 跳转到网络错误页面
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '/#/network_error')
} else {
mainWindow.loadFile(join(__dirname, '../renderer/index.html'), { hash: '/network_error' })
}
})
// 接口超过30分钟不活动则退出登录
await tokenExpireTimer()
setTimeout(()=>{
setTimeout(async ()=>{
try {
// 注册全局快捷键
registerShortcuts(mainWindow)
checkForUpdates({},false)
// 先检测网络连接,如果网络正常再调用版本检测升级
const isNetworkConnected = await checkDefaultClientConnection(5000);
if (isNetworkConnected) {
logger.info('网络连接正常,开始检查版本更新');
checkForUpdates({},false)
} else {
logger.warn('网络连接异常,跳过版本检测升级');
}
}catch (e) {
logger.info(e)
}