fix: proxy check
This commit is contained in:
parent
dedabe320e
commit
4a32976483
@ -102,7 +102,7 @@ app.whenReady().then(() => {
|
||||
})
|
||||
|
||||
ipcMain.handle('set-proxy', (_, proxy: string) => {
|
||||
session.defaultSession.setProxy({ proxyRules: proxy })
|
||||
session.defaultSession.setProxy(proxy ? { proxyRules: proxy } : {})
|
||||
})
|
||||
|
||||
// 触发检查更新(此方法用于被渲染线程调用,例如页面点击检查更新按钮来调用此方法)
|
||||
|
||||
2
src/preload/index.d.ts
vendored
2
src/preload/index.d.ts
vendored
@ -10,7 +10,7 @@ declare global {
|
||||
}>
|
||||
checkForUpdate: () => void
|
||||
openWebsite: (url: string) => void
|
||||
setProxy: (proxy: string) => void
|
||||
setProxy: (proxy: string | undefined) => void
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ const GeneralSettings: FC = () => {
|
||||
}
|
||||
|
||||
const onSetProxyUrl = () => {
|
||||
if (!proxyUrl || !isValidProxyUrl(proxyUrl)) {
|
||||
if (proxyUrl && !isValidProxyUrl(proxyUrl)) {
|
||||
window.message.error({ content: t('message.error.invalid.proxy.url'), key: 'proxy-error' })
|
||||
return
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ import i18n from '@renderer/i18n'
|
||||
import store from '@renderer/store'
|
||||
import { setGenerating } from '@renderer/store/runtime'
|
||||
import { Assistant, Message, Provider, Topic } from '@renderer/types'
|
||||
import { getErrorMessage, uuid } from '@renderer/utils'
|
||||
import { uuid } from '@renderer/utils'
|
||||
import dayjs from 'dayjs'
|
||||
import { getAssistantProvider, getDefaultModel, getProviderByModel, getTopNamingModel } from './assistant'
|
||||
import { EVENT_NAMES, EventEmitter } from './event'
|
||||
@ -92,15 +92,13 @@ export async function checkApi(provider: Provider) {
|
||||
|
||||
const providerSdk = new ProviderSDK(provider)
|
||||
|
||||
const { valid, error } = await providerSdk.check()
|
||||
const { valid } = await providerSdk.check()
|
||||
|
||||
window.message[valid ? 'success' : 'error']({
|
||||
key: 'api-check',
|
||||
style: { marginTop: '3vh' },
|
||||
duration: valid ? 2 : 8,
|
||||
content: valid
|
||||
? i18n.t('message.api.connection.success')
|
||||
: i18n.t('message.api.connection.failed') + ' : ' + getErrorMessage(error)
|
||||
content: valid ? i18n.t('message.api.connection.success') : i18n.t('message.api.connection.failed')
|
||||
})
|
||||
|
||||
return valid
|
||||
|
||||
@ -206,10 +206,5 @@ export const capitalizeFirstLetter = (str: string) => {
|
||||
|
||||
// is valid proxy url
|
||||
export const isValidProxyUrl = (url: string) => {
|
||||
try {
|
||||
new URL(url)
|
||||
return true
|
||||
} catch (error) {
|
||||
return false
|
||||
}
|
||||
return url.includes('://')
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user