mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 09:15:41 +08:00
feat: mac发送完整支持4.1.13以上版本, 完善授权
This commit is contained in:
1 parent
9db08dba1a
commit
8c162969ff
18 files changed
+1841
-238
No files matched your search
@@ -0,0 +1,103 @@
|
||||
import type { MacLicenseStatus } from './personal-wechat-mac-license'
|
||||
import type { MacWechatSendRuntimeAvailabilityResult } from './personal-wechat-mac-runtime'
|
||||
import type { PersonalWechatSenderStatus } from './personal-wechat'
|
||||
|
||||
export type MacSendPrimaryActionKind = 'none' | 'bind' | 'send'
|
||||
|
||||
export interface MacSendPrimaryAction {
|
||||
label: string
|
||||
disabled: boolean
|
||||
loading: boolean
|
||||
action: MacSendPrimaryActionKind
|
||||
reason:
|
||||
| 'runtime_unavailable'
|
||||
| 'runtime_error'
|
||||
| 'license_pending'
|
||||
| 'license_invalid'
|
||||
| 'license_feature_denied'
|
||||
| 'binding'
|
||||
| 'unbound'
|
||||
| 'initializing'
|
||||
| 'ready'
|
||||
}
|
||||
|
||||
export function hasValidWechatLicense(license: MacLicenseStatus | null): boolean {
|
||||
if (
|
||||
!license ||
|
||||
!license.authorized ||
|
||||
(license.state !== 'valid' && license.state !== 'cached') ||
|
||||
!license.features.includes('wechat')
|
||||
) {
|
||||
return false
|
||||
}
|
||||
const tokenExpiresAt = license.tokenExpiresAt ? Date.parse(license.tokenExpiresAt) : Number.NaN
|
||||
return Number.isFinite(tokenExpiresAt) && tokenExpiresAt > Date.now()
|
||||
}
|
||||
|
||||
export function resolveMacSendPrimaryAction(input: {
|
||||
runtime: MacWechatSendRuntimeAvailabilityResult | null
|
||||
license: MacLicenseStatus | null
|
||||
senderStatus: PersonalWechatSenderStatus | null
|
||||
binding: boolean
|
||||
detecting: boolean
|
||||
}): MacSendPrimaryAction {
|
||||
const { runtime, license, senderStatus, binding, detecting } = input
|
||||
const result = (
|
||||
label: string,
|
||||
disabled: boolean,
|
||||
loading: boolean,
|
||||
action: MacSendPrimaryActionKind,
|
||||
reason: MacSendPrimaryAction['reason']
|
||||
): MacSendPrimaryAction => ({ label, disabled, loading, action, reason })
|
||||
|
||||
if (!runtime || (detecting && !senderStatus)) {
|
||||
return result('正在检查发送组件…', true, true, 'none', 'runtime_error')
|
||||
}
|
||||
if (runtime.state === 'unavailable') {
|
||||
return result('当前版本没有微信发送能力', true, false, 'none', 'runtime_unavailable')
|
||||
}
|
||||
if (runtime.state === 'component_error') {
|
||||
return result('发送组件缺失或异常', true, false, 'none', 'runtime_error')
|
||||
}
|
||||
if (license === null) {
|
||||
return result('正在检测授权…', true, true, 'none', 'license_pending')
|
||||
}
|
||||
if (license.state === 'valid' || license.state === 'cached') {
|
||||
if (license.authorized && !license.features.includes('wechat')) {
|
||||
return result('未开通微信发送', true, false, 'none', 'license_feature_denied')
|
||||
}
|
||||
if (hasValidWechatLicense(license)) {
|
||||
if (binding) return result('正在绑定…', true, true, 'none', 'binding')
|
||||
const bound = Boolean(
|
||||
senderStatus &&
|
||||
(senderStatus.state === 'online' ||
|
||||
Boolean(
|
||||
senderStatus.wechatPid &&
|
||||
senderStatus.boundWechatPid === senderStatus.wechatPid &&
|
||||
senderStatus.attachReady &&
|
||||
senderStatus.baseAddressReady
|
||||
))
|
||||
)
|
||||
if (!bound) return result('绑定微信', false, false, 'bind', 'unbound')
|
||||
if (senderStatus?.canSend) return result('开始发送', false, false, 'send', 'ready')
|
||||
return result('正在准备发送能力…', true, detecting, 'none', 'initializing')
|
||||
}
|
||||
}
|
||||
const bound = Boolean(
|
||||
senderStatus &&
|
||||
(senderStatus.state === 'online' ||
|
||||
Boolean(
|
||||
senderStatus.wechatPid &&
|
||||
senderStatus.boundWechatPid === senderStatus.wechatPid &&
|
||||
senderStatus.attachReady &&
|
||||
senderStatus.baseAddressReady
|
||||
))
|
||||
)
|
||||
return result(
|
||||
bound ? '授权后可开始发送' : '授权后可绑定微信',
|
||||
true,
|
||||
false,
|
||||
'none',
|
||||
'license_invalid'
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user