Add app runtime statistics

This commit is contained in:
Sucukdeluxe
2026-03-09 04:59:00 +01:00
parent 971f669bb6
commit 1f9a26e4b0
12 changed files with 194 additions and 8 deletions
+7 -2
View File
@@ -173,7 +173,11 @@ function buildSnapshot(baseDir: string): UiSnapshot {
totalFilesSession: 0,
totalFilesAllTime: 0,
totalPackages: 1,
sessionStartedAt: Date.now() - 30_000
sessionStartedAt: Date.now() - 30_000,
appSessionStartedAt: Date.now() - 60_000,
sessionRuntimeMs: 60_000,
totalRuntimeMs: 3 * 60_000,
runtimeMeasuredAt: Date.now()
},
speedText: "8.0 MB/s",
etaText: "ETA: 00:25",
@@ -209,7 +213,8 @@ async function createFixture() {
debridLinkApiKeys,
debridLinkDisabledKeyIds: debridLinkKeyIds[1] ? [debridLinkKeyIds[1]] : [],
totalDownloadedAllTime: 128 * 1024 * 1024,
totalCompletedFilesAllTime: 12
totalCompletedFilesAllTime: 12,
totalRuntimeAllTimeMs: 5 * 60_000
});
saveHistory(storagePaths, [
{
+30
View File
@@ -6709,6 +6709,36 @@ describe("download manager", () => {
expect(fs.existsSync(originalExtractedPath)).toBe(false);
});
it("tracks app runtime for session and all-time statistics", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
tempDirs.push(root);
const stateDir = path.join(root, "state");
const storagePaths = createStoragePaths(stateDir);
const manager = new DownloadManager(
{
...defaultSettings(),
token: "rd-token",
outputDir: path.join(root, "downloads"),
extractDir: path.join(root, "extract"),
totalRuntimeAllTimeMs: 2 * 60 * 60 * 1000
},
emptySession(),
storagePaths
);
await new Promise((resolve) => setTimeout(resolve, 120));
const stats = manager.getStats();
expect(stats.sessionRuntimeMs).toBeGreaterThanOrEqual(100);
expect(stats.totalRuntimeMs).toBeGreaterThanOrEqual(2 * 60 * 60 * 1000 + 100);
expect(stats.runtimeMeasuredAt).toBeGreaterThan(0);
manager.persistRuntimeStats(true);
const savedSettings = JSON.parse(fs.readFileSync(storagePaths.configFile, "utf8")) as { totalRuntimeAllTimeMs?: number };
expect(savedSettings.totalRuntimeAllTimeMs || 0).toBeGreaterThanOrEqual(2 * 60 * 60 * 1000 + 100);
}, 10000);
it("writes auto-rename details into rename and item logs", async () => {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "rd-dm-"));
tempDirs.push(root);
+5 -1
View File
@@ -115,7 +115,11 @@ function buildSnapshot(): UiSnapshot {
totalFilesSession: 0,
totalFilesAllTime: 0,
totalPackages: 2,
sessionStartedAt: 0
sessionStartedAt: 0,
appSessionStartedAt: 0,
sessionRuntimeMs: 0,
totalRuntimeMs: 0,
runtimeMeasuredAt: 0
},
speedText: "",
etaText: "",