fix(usage): keep records refreshing in background

- refresh usage records when the WebView is hidden or occluded
- disable WebView2 background throttling for the main window
- add regression coverage for background refresh behavior
This commit is contained in:
lzt404 committed 2026-09-19 00:36:18 +08:00
1 parent 9ff9a6c317
commit 71c63234f8
1 file changed
+32
+32
View File
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'bun:test';
import { readFileSync } from 'node:fs';
describe('usage records background refresh', () => {
it('keeps refresh triggers active when the document is hidden', () => {
const source = readFileSync(
new URL('../src/pages/UsageRecordsPage.tsx', import.meta.url),
'utf8',
);
const refreshStart = source.indexOf('const refresh = () => {');
const refreshEnd = source.indexOf("listen('usage-records-updated'", refreshStart);
const refreshBlock = source.slice(refreshStart, refreshEnd);
expect(refreshStart).toBeGreaterThanOrEqual(0);
expect(refreshEnd).toBeGreaterThan(refreshStart);
expect(refreshBlock).toContain('if (!disposed) void loadData(true, true);');
expect(refreshBlock).not.toContain('document.hidden');
});
it('disables WebView background suspension for the desktop window', () => {
const config = JSON.parse(
readFileSync(new URL('../src-tauri/tauri.conf.json', import.meta.url), 'utf8'),
);
const mainWindow = config.app.windows.find((window: { label?: string }) => window.label === 'main');
const browserArgs = String(mainWindow?.additionalBrowserArgs ?? '').split(/\s+/);
expect(mainWindow?.backgroundThrottling).toBe('disabled');
expect(browserArgs).toContain('--disable-background-timer-throttling');
expect(browserArgs).toContain('--disable-renderer-backgrounding');
expect(browserArgs).toContain('--disable-backgrounding-occluded-windows');
});
});