fix: 微信版本不支持发送文件时不再误报为未配置

This commit is contained in:
Wxw-Gu committed 2026-11-20 14:20:33 +08:00
1 parent d436b064c3
commit 9238c6694b
2 files changed
+55 -12

No files matched your search

@@ -83,13 +83,19 @@ function PersonalWechatMacSendDialog({
const displayName = contact.m_nsNickName || contact.m_nsUsrName || '未命名会话' const displayName = contact.m_nsNickName || contact.m_nsUsrName || '未命名会话'
const targetId = contact.m_nsUsrName const targetId = contact.m_nsUsrName
const isBusy = binding || sendBusy const isBusy = binding || sendBusy
const setupReady = Boolean( const capabilityReady = Boolean(
initialFile initialFile
? senderStatus?.canSendFile ? senderStatus?.canSendFile
: initialImage : initialImage
? senderStatus?.canSendImage ? senderStatus?.canSendImage
: senderStatus?.canSendVoice : senderStatus?.canSendVoice
) )
/* 运行时和绑定是否已就绪(任一能力可用)。必须与「当前要发的东西能不能发」
* 分开判:微信版本不支持文件时能力为 false,但配置是好的,再摆一遍首次
* 配置向导只会得出「已配置完成」却发不出去的结论。 */
const runtimeReady = senderStatus?.canSend === true
const capabilityUnsupported = runtimeReady && !capabilityReady
const capabilityNoun = initialFile ? '文件' : initialImage ? '图片' : '语音'
const { postfixText, setPostfixText, persistPostfixText } = useReportImagePostfixSetting( const { postfixText, setPostfixText, persistPostfixText } = useReportImagePostfixSetting(
Boolean(initialImage) Boolean(initialImage)
) )
@@ -300,17 +306,22 @@ function PersonalWechatMacSendDialog({
{initialFile ? '发送文件' : initialImage ? '发送日报图片' : '文字转语音'} {initialFile ? '发送文件' : initialImage ? '发送日报图片' : '文字转语音'}
</DialogTitle> </DialogTitle>
<DialogDescription> <DialogDescription>
发送给 {displayName} · {setupReady ? '微信已连接' : '配置微信发送能力'} 发送给 {displayName} ·{' '}
{capabilityReady
? '微信已连接'
: capabilityUnsupported
? `当前微信版本不支持发送${capabilityNoun}`
: '配置微信发送能力'}
</DialogDescription> </DialogDescription>
</div> </div>
<span <span
className={`personal-wechat-connection-dot ${setupReady ? 'is-online' : ''}`} className={`personal-wechat-connection-dot ${capabilityReady ? 'is-online' : ''}`}
aria-label={setupReady ? '微信已连接' : '微信尚未配置'} aria-label={capabilityReady ? '微信已连接' : '微信尚未配置'}
/> />
</DialogHeader> </DialogHeader>
<div className="personal-wechat-chat-body"> <div className="personal-wechat-chat-body">
{setupReady && !initialImage && !initialFile && ( {capabilityReady && !initialImage && !initialFile && (
<div className="personal-wechat-message-list" aria-label="消息列表"> <div className="personal-wechat-message-list" aria-label="消息列表">
{messages.length === 0 ? ( {messages.length === 0 ? (
<div className="personal-wechat-empty-message">还没有发送消息。</div> <div className="personal-wechat-empty-message">还没有发送消息。</div>
@@ -328,19 +339,33 @@ function PersonalWechatMacSendDialog({
</div> </div>
)} )}
{!setupReady && senderStatus && ( {capabilityUnsupported && (
<section className="personal-wechat-composer" aria-label="能力不支持提示">
<p>
当前微信
{senderStatus?.wechatVersion ? `(${senderStatus.wechatVersion})` : ''}
不支持发送{capabilityNoun}。
</p>
<p>
文字、图片、语音消息仍可正常发送;如需发送{capabilityNoun}
,请升级微信后在设置页重新绑定。
</p>
</section>
)}
{!capabilityReady && !capabilityUnsupported && senderStatus && (
<PersonalWechatSetupGuide <PersonalWechatSetupGuide
senderStatus={senderStatus} senderStatus={senderStatus}
binding={binding} binding={binding}
detecting={detecting} detecting={detecting}
sessionBound={sessionBound} sessionBound={sessionBound}
onBind={() => void handleBind()} onBind={() => void handleBind()}
onStartSending={() => undefined} onStartSending={handleClose}
onOpenTextToSpeechSettings={handleOpenSettings} onOpenTextToSpeechSettings={handleOpenSettings}
/> />
)} )}
{setupReady && initialImage && ( {capabilityReady && initialImage && (
<section className="personal-wechat-composer" aria-label="日报图片发送"> <section className="personal-wechat-composer" aria-label="日报图片发送">
<p>已准备日报图片:{initialImage.name}</p> <p>已准备日报图片:{initialImage.name}</p>
<ReportImagePostfixInput <ReportImagePostfixInput
@@ -359,7 +384,7 @@ function PersonalWechatMacSendDialog({
</section> </section>
)} )}
{setupReady && initialFile && ( {capabilityReady && initialFile && (
<section className="personal-wechat-composer" aria-label="文件发送"> <section className="personal-wechat-composer" aria-label="文件发送">
<p>已选择文件:{initialFile.name}</p> <p>已选择文件:{initialFile.name}</p>
<Button size="sm" onClick={() => void handleSendFile()} disabled={sendBusy}> <Button size="sm" onClick={() => void handleSendFile()} disabled={sendBusy}>
@@ -368,7 +393,7 @@ function PersonalWechatMacSendDialog({
</section> </section>
)} )}
{setupReady && !initialImage && !initialFile && ( {capabilityReady && !initialImage && !initialFile && (
<PersonalWechatChatComposer <PersonalWechatChatComposer
status={senderStatus!} status={senderStatus!}
targetId={targetId} targetId={targetId}
@@ -390,14 +415,14 @@ function PersonalWechatMacSendDialog({
</div> </div>
)} )}
</div> </div>
{setupReady && isMac && !initialImage && !initialFile && ( {capabilityReady && isMac && !initialImage && !initialFile && (
<div className="personal-wechat-chat-footer flex items-center justify-end"> <div className="personal-wechat-chat-footer flex items-center justify-end">
<Button variant="link" size="sm" onClick={() => void handleOpenVoiceDiagnostic()}> <Button variant="link" size="sm" onClick={() => void handleOpenVoiceDiagnostic()}>
语音发送诊断 语音发送诊断
</Button> </Button>
</div> </div>
)} )}
{!setupReady && ( {!capabilityReady && (
<div className="personal-wechat-chat-footer flex items-center justify-end"> <div className="personal-wechat-chat-footer flex items-center justify-end">
<Button variant="outline" onClick={handleClose} disabled={isBusy}> <Button variant="outline" onClick={handleClose} disabled={isBusy}>
关闭 关闭
@@ -165,6 +165,24 @@ describe('PersonalWechatSendDialog', () => {
expect(screen.getByLabelText('消息列表')).toHaveTextContent('你好 TraceMemo') expect(screen.getByLabelText('消息列表')).toHaveTextContent('你好 TraceMemo')
}) })
it('explains an unsupported file capability instead of showing the setup guide', async () => {
/* 微信版本发不了文件时能力为 false,但运行时和绑定都是好的。
* 这里若回落到首次配置向导,用户会看到「微信消息发送已配置完成」,
* 却怎么都发不出文件。 */
getStatus.mockResolvedValue({ ...readyStatus, wechatVersion: '4.1.13.8' })
renderDialog({
initialFile: { path: '/tmp/chatlog.zip', name: 'chatlog_alpha-private-main.zip' }
})
const notice = await screen.findByLabelText('能力不支持提示')
expect(notice).toHaveTextContent('不支持发送文件')
expect(notice).toHaveTextContent('4.1.13.8')
expect(screen.queryByText('首次使用')).not.toBeInTheDocument()
expect(screen.queryByText('微信消息发送已配置完成')).not.toBeInTheDocument()
expect(screen.queryByRole('button', { name: '发送文件' })).not.toBeInTheDocument()
})
it('shows image send success feedback after the host confirms the send', async () => { it('shows image send success feedback after the host confirms the send', async () => {
const user = userEvent.setup() const user = userEvent.setup()
renderDialog({ initialImage: { path: '/tmp/report.png', name: '测试群日报.png' } }) renderDialog({ initialImage: { path: '/tmp/report.png', name: '测试群日报.png' } })