mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-10-05 21:05:39 +08:00
fix: 日报截图窗口隐藏化、搜索缓存兼容读取与定时日报单测等待窗口
This commit is contained in:
@@ -906,6 +906,8 @@ const captureFullPage = async (
|
||||
const reportSessionPartition = `report-template-${crypto.randomUUID()}`
|
||||
const reportWindow = new BrowserWindow({
|
||||
show: false,
|
||||
opacity: 0,
|
||||
skipTaskbar: true,
|
||||
width: captureWidth,
|
||||
height: 800,
|
||||
frame: false,
|
||||
@@ -948,7 +950,9 @@ const captureFullPage = async (
|
||||
reportWindow.webContents.on('will-navigate', (event) => event.preventDefault())
|
||||
|
||||
try {
|
||||
const readyToShow = new Promise<void>((resolve) => reportWindow.once('ready-to-show', resolve))
|
||||
await reportWindow.loadFile(htmlPath)
|
||||
await readyToShow
|
||||
console.log('[GroupReport] capture loaded html')
|
||||
await reportWindow.webContents.executeJavaScript(`Promise.all([
|
||||
document.fonts.ready,
|
||||
@@ -964,10 +968,21 @@ const captureFullPage = async (
|
||||
})`)) as { width: number; height: number }
|
||||
const width = Math.max(captureWidth, Math.min(maxCaptureWidth, Math.ceil(metrics.width)))
|
||||
const height = Math.max(800, Math.min(maxCaptureHeight, Math.ceil(metrics.height)))
|
||||
reportWindow.setContentSize(width, height)
|
||||
const [currentWidth, currentHeight] = reportWindow.getContentSize()
|
||||
if (currentWidth !== width || currentHeight !== height) {
|
||||
const resized = new Promise<void>((resolve) => reportWindow.once('resize', resolve))
|
||||
reportWindow.setContentSize(width, height)
|
||||
await resized
|
||||
}
|
||||
await reportWindow.webContents.executeJavaScript(
|
||||
'new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))'
|
||||
)
|
||||
await new Promise((resolve) => setTimeout(resolve, 100))
|
||||
console.log(`[GroupReport] capture native page width=${width} height=${height}`)
|
||||
const image = await reportWindow.webContents.capturePage({ x: 0, y: 0, width, height })
|
||||
const image = await reportWindow.webContents.capturePage(
|
||||
{ x: 0, y: 0, width, height },
|
||||
{ stayHidden: true }
|
||||
)
|
||||
const png = image.toPNG()
|
||||
if (png.length < 1000) throw new Error('生成的日报图片为空')
|
||||
await fs.writeFile(pngPath, png)
|
||||
|
||||
@@ -217,6 +217,33 @@ export function useSearchHistory({
|
||||
onNotice('已恢复这条历史问题的最近结果')
|
||||
}
|
||||
|
||||
const readCachedResult = (cacheKey: string): AISearchCacheRecord | null => {
|
||||
const exact = readSearchCache(cacheKey)
|
||||
if (exact) return exact
|
||||
try {
|
||||
const requested = parseSearchCacheKey(cacheKey)
|
||||
if (!requested) return null
|
||||
const records = JSON.parse(localStorage.getItem(SEARCH_CACHE_KEY) || '[]') as AISearchCacheRecord[]
|
||||
return records
|
||||
.filter((record) => {
|
||||
try {
|
||||
const raw = JSON.parse(record.key) as unknown[]
|
||||
const location = parseSearchCacheKey(record.key)
|
||||
// Only legacy four-part keys may use compatibility lookup, and
|
||||
// all base dimensions must still match the active request.
|
||||
return raw.length === 4 && location?.scope === requested.scope &&
|
||||
location.contactMd5 === requested.contactMd5 && location.range === requested.range &&
|
||||
location.query === requested.query
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
})
|
||||
.sort((a, b) => b.createdAt - a.createdAt)[0] || null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const persistSearchResult = (input: PersistSearchResultInput): AISearchCacheRecord => {
|
||||
const record = createSearchCacheRecord({
|
||||
...input,
|
||||
@@ -288,7 +315,7 @@ export function useSearchHistory({
|
||||
removeHistoryQuery,
|
||||
restoreHistoryQuery,
|
||||
applyCachedResult,
|
||||
readCachedResult: readSearchCache,
|
||||
readCachedResult,
|
||||
persistSearchResult,
|
||||
clearActiveResult,
|
||||
skipNextCache,
|
||||
|
||||
Reference in New Issue
Block a user