GUI 日志落盘,修复同一奖品重复兑换与监控结束竞态

- 日志落盘:新增 internal/gui/logfile.go,写到 <用户配置目录>/huya-go/logs/huya-go.log,单文件 5MB 后滚动保留 5 个备份;「日志」页签顶部显示路径并支持打开目录/复制路径;写盘失败自动降级为仅界面输出
- 修复重复兑换:界面选品会同时提交 pid、名称与 targetText 里的同一 pid,normalizeTargets 现按 pid/名称去重;runState 再按「账号+奖品」记账,多个 target 命中同一奖品时只兑换一次(新增 skip_duplicate 结果)
- 修复 use of closed network connection:成功后的异步刷新改为 runState.refresh 等待,RunTargets 返回前不再提前关闭连接
- queryHttpDns 增加 single-flight 与失败冷却,多账号并发建连只解析一次
- 新增 internal/gui/logfile_test.go 与 sniper/huya 回归测试;README 补日志说明
This commit is contained in:
yml2213
2026-10-13 20:34:43 +08:00
parent 36aadae90a
commit 41565566c5
13 changed files with 769 additions and 18 deletions
+42 -5
View File
@@ -21,6 +21,8 @@ import type { ColumnsType } from 'antd/es/table'
import {
ClipboardList,
ClipboardPaste,
Copy,
FolderOpen,
ListChecks,
Pencil,
Play,
@@ -36,16 +38,18 @@ import {
import {
DefaultConfig,
Exchange,
GetLogFilePath,
GetLogs,
GetRecords,
IsRunning,
ListPrizes,
OpenLogDir,
PreviewAccounts,
QueryScores,
StartMonitor,
StopMonitor,
} from '../wailsjs/go/gui/App'
import { ClipboardGetText, EventsOn } from '../wailsjs/runtime/runtime'
import { ClipboardGetText, ClipboardSetText, EventsOn } from '../wailsjs/runtime/runtime'
const storageKey = 'huya-go.gui.config.v2'
const cookieStorageKey = 'huya-go.gui.cookies.v1'
@@ -482,6 +486,7 @@ export default function Dashboard() {
const [cookieEntries, setCookieEntries] = useState<CookieEntry[]>([])
const [prizeCacheUpdatedAt, setPrizeCacheUpdatedAt] = useState(0)
const [configLoaded, setConfigLoaded] = useState(false)
const [logPath, setLogPath] = useState('')
const applyCookieEntries = async (entries: CookieEntry[], persist = true, refreshLatest = false) => {
const normalizedEntries = entries
@@ -526,8 +531,8 @@ export default function Dashboard() {
useEffect(() => {
let mounted = true
Promise.all([DefaultConfig(), GetLogs(), IsRunning()])
.then(([defaults, logItems, isRunning]) => {
Promise.all([DefaultConfig(), GetLogs(), IsRunning(), GetLogFilePath()])
.then(([defaults, logItems, isRunning, savedLogPath]) => {
if (!mounted) return
const savedCookies = readSavedCookies()
const savedPrizeCache = readSavedPrizeCache()
@@ -540,6 +545,7 @@ export default function Dashboard() {
setPrizes(savedPrizeCache.prizes)
setPrizeCacheUpdatedAt(savedPrizeCache.updatedAt)
setLogs((logItems || []) as LogEntry[])
setLogPath(String(savedLogPath || ''))
setRunning(Boolean(isRunning))
setConfigLoaded(true)
if (savedCookies.length > 0) {
@@ -882,7 +888,8 @@ export default function Dashboard() {
form.setFieldsValue({
pid: selected[0].id,
name: selected[0].name,
targetText: selected.map((item) => String(item.id)).join('\n'),
// pid/名称已经代表第一个奖品,这里只补其余奖品,避免同一奖品被提交两次。
targetText: selected.slice(1).map((item) => String(item.id)).join('\n'),
autoSelect: false,
})
}
@@ -932,6 +939,14 @@ export default function Dashboard() {
)
}
const openLogDir = () => runAction('logdir', () => OpenLogDir())
const copyLogPath = async () => {
if (!logPath) return
await ClipboardSetText(logPath)
message.success('已复制日志路径')
}
const selectAllAccounts = () => {
setSelectedAccountLines(validAccounts.map((item) => item.line))
}
@@ -1107,7 +1122,29 @@ export default function Dashboard() {
{
key: 'logs',
label: '日志',
children: <LogView logs={logs} />,
children: (
<div className="log-pane">
<div className="log-tools">
<span className="log-path" title={logPath || '日志文件不可用'}>
{logPath || '日志文件不可用'}
</span>
<Space size={6}>
<Tooltip title="打开日志目录">
<Button
size="small"
icon={<FolderOpen size={14} />}
disabled={!logPath}
onClick={openLogDir}
/>
</Tooltip>
<Tooltip title="复制日志路径">
<Button size="small" icon={<Copy size={14} />} disabled={!logPath} onClick={copyLogPath} />
</Tooltip>
</Space>
</div>
<LogView logs={logs} />
</div>
),
},
{
key: 'results',
+27 -1
View File
@@ -386,8 +386,34 @@ body {
margin-bottom: 8px;
}
.log-pane {
display: flex;
flex-direction: column;
gap: 8px;
height: 100%;
min-height: 0;
}
.log-tools {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.log-path {
flex: 1;
min-width: 0;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: #6b7280;
font-size: 12px;
}
.log-view {
height: calc(100% - 2px);
flex: 1;
height: auto;
min-height: 300px;
overflow: auto;
border: 1px solid #e6edf3;