mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-27 23:15:51 +00:00
修复Windows hello部分情况下设置失败的问题
This commit is contained in:
@@ -103,9 +103,7 @@ function WelcomePage({ standalone = false }: WelcomePageProps) {
|
||||
|
||||
// 检查 Hello 可用性
|
||||
useEffect(() => {
|
||||
if (window.PublicKeyCredential) {
|
||||
void PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable().then(setHelloAvailable)
|
||||
}
|
||||
setHelloAvailable(isWindows)
|
||||
}, [])
|
||||
|
||||
async function sha256(message: string) {
|
||||
@@ -117,35 +115,27 @@ function WelcomePage({ standalone = false }: WelcomePageProps) {
|
||||
}
|
||||
|
||||
const handleSetupHello = async () => {
|
||||
if (!isWindows) {
|
||||
setError('当前系统不支持 Windows Hello')
|
||||
return
|
||||
}
|
||||
if (!authPassword || authPassword !== authConfirmPassword) {
|
||||
setError('请先设置并确认应用密码,再开启 Windows Hello')
|
||||
return
|
||||
}
|
||||
|
||||
setIsSettingHello(true)
|
||||
try {
|
||||
// 注册凭证 (WebAuthn)
|
||||
const challenge = new Uint8Array(32)
|
||||
window.crypto.getRandomValues(challenge)
|
||||
|
||||
const credential = await navigator.credentials.create({
|
||||
publicKey: {
|
||||
challenge,
|
||||
rp: { name: 'WeFlow', id: 'localhost' },
|
||||
user: {
|
||||
id: new Uint8Array([1]),
|
||||
name: 'user',
|
||||
displayName: 'User'
|
||||
},
|
||||
pubKeyCredParams: [{ alg: -7, type: 'public-key' }],
|
||||
authenticatorSelection: { userVerification: 'required' },
|
||||
timeout: 60000
|
||||
}
|
||||
})
|
||||
|
||||
if (credential) {
|
||||
setEnableHello(true)
|
||||
// 成功提示?
|
||||
const result = await window.electronAPI.auth.hello('请验证您的身份以开启 Windows Hello')
|
||||
if (!result.success) {
|
||||
setError(`Windows Hello 设置失败: ${result.error || '验证失败'}`)
|
||||
return
|
||||
}
|
||||
|
||||
setEnableHello(true)
|
||||
setError('')
|
||||
} catch (e: any) {
|
||||
if (e.name !== 'NotAllowedError') {
|
||||
setError('Windows Hello 设置失败: ' + e.message)
|
||||
}
|
||||
setError(`Windows Hello 设置失败: ${e?.message || String(e)}`)
|
||||
} finally {
|
||||
setIsSettingHello(false)
|
||||
}
|
||||
@@ -502,7 +492,17 @@ function WelcomePage({ standalone = false }: WelcomePageProps) {
|
||||
const hash = await sha256(authPassword)
|
||||
await configService.setAuthEnabled(true)
|
||||
await configService.setAuthPassword(hash)
|
||||
await configService.setAuthUseHello(enableHello)
|
||||
if (enableHello) {
|
||||
const helloResult = await window.electronAPI.auth.setHelloSecret(authPassword)
|
||||
if (!helloResult.success) {
|
||||
setError('Windows Hello 配置保存失败')
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
await window.electronAPI.auth.clearHelloSecret()
|
||||
await configService.setAuthUseHello(false)
|
||||
}
|
||||
}
|
||||
|
||||
await configService.setOnboardingDone(true)
|
||||
|
||||
Reference in New Issue
Block a user