Skip to content

Commit 9a33ba6

Browse files
authored
856 recent logs list shows incorrect time (#873)
* manually save last opened time * Revert "manually save last opened time" This reverts commit 9613526. * changed format of recentLogs.json to include timestamp * formatting * applying copilots suggestions
1 parent 4d5b110 commit 9a33ba6

4 files changed

Lines changed: 59 additions & 21 deletions

File tree

gcs/electron/fla.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {
2626
MessageObject,
2727
Messages,
2828
ParseResult,
29+
RecentLog,
2930
} from "./types/flaTypes"
3031

3132
import {
@@ -408,7 +409,7 @@ async function determineLogFileType(filePath: string): Promise<LogType> {
408409
}
409410

410411
// New function to get recent files
411-
export function getRecentFiles(): string[] {
412+
export function getRecentFiles(): RecentLog[] {
412413
return recentLogsManager.getRecentLogs()
413414
}
414415

gcs/electron/main.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,16 +501,22 @@ app.whenReady().then(() => {
501501
`Expected recentLogs to be an array, but got ${typeof recentLogs}`,
502502
)
503503
}
504-
return recentLogs.map((logPath) => {
505-
const logName = path.basename(logPath)
506-
const fileStats = fs.statSync(logPath)
507-
return {
508-
name: logName,
509-
path: logPath,
510-
size: fileStats.size,
511-
timestamp: fileStats.mtime,
512-
}
513-
})
504+
return recentLogs
505+
.map((log) => {
506+
try {
507+
const logName = path.basename(log.path)
508+
const fileStats = fs.statSync(log.path)
509+
return {
510+
name: logName,
511+
path: log.path,
512+
size: fileStats.size,
513+
timestamp: new Date(log.timestamp),
514+
}
515+
} catch {
516+
return null
517+
}
518+
})
519+
.filter((log) => log !== null)
514520
} catch (error) {
515521
return []
516522
}

gcs/electron/types/flaTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,8 @@ export type LogType =
107107
| "fgcs_telemetry"
108108
| "mp_telemetry"
109109
| null
110+
111+
export interface RecentLog {
112+
path: string
113+
timestamp: number
114+
}

gcs/electron/utils/recentLogManager.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { app } from "electron"
22
import * as fs from "fs"
33
import * as path from "path"
4+
import type { RecentLog } from "../types/flaTypes"
45

56
export default function createRecentLogsManager(maxRecentLogs: number = 10) {
67
// JSON file to hold paths to recently opened logs
@@ -9,13 +10,38 @@ export default function createRecentLogsManager(maxRecentLogs: number = 10) {
910
"recentLogs.json",
1011
)
1112

12-
function loadRecentLogs(): string[] {
13+
function loadRecentLogs(): RecentLog[] {
1314
try {
1415
if (fs.existsSync(recentLogsPath)) {
1516
const data = fs.readFileSync(recentLogsPath, "utf8")
1617
const parsed = JSON.parse(data)
17-
// Ensure we return an array of strings
18-
return Array.isArray(parsed) ? parsed : []
18+
19+
// Backward compatibility: convert array of strings to array of objects
20+
if (Array.isArray(parsed)) {
21+
return parsed.map((item) => {
22+
if (typeof item === "string") {
23+
// Old format: use mtime as fallback
24+
try {
25+
const stats = fs.statSync(item)
26+
return { path: item, timestamp: stats.mtime.getTime() }
27+
} catch {
28+
return { path: item, timestamp: Date.now() }
29+
}
30+
}
31+
// New format: validate and return
32+
if (
33+
typeof item === "object" &&
34+
item !== null &&
35+
"path" in item &&
36+
"timestamp" in item
37+
) {
38+
return item as RecentLog
39+
}
40+
// Invalid format: treat as current time
41+
return { path: String(item), timestamp: Date.now() }
42+
})
43+
}
44+
return []
1945
}
2046
return []
2147
} catch (error) {
@@ -24,7 +50,7 @@ export default function createRecentLogsManager(maxRecentLogs: number = 10) {
2450
}
2551
}
2652

27-
let recentLogs: string[] = loadRecentLogs()
53+
let recentLogs: RecentLog[] = loadRecentLogs()
2854

2955
function saveRecentLogs(): void {
3056
try {
@@ -37,10 +63,10 @@ export default function createRecentLogsManager(maxRecentLogs: number = 10) {
3763
return {
3864
addRecentLog(filePath: string): void {
3965
// Remove the file if it already exists in the list
40-
recentLogs = recentLogs.filter((file: string) => file !== filePath)
66+
recentLogs = recentLogs.filter((log: RecentLog) => log.path !== filePath)
4167

42-
// Add the file to the beginning of the list
43-
recentLogs.unshift(filePath)
68+
// Add the file to the beginning of the list with current timestamp
69+
recentLogs.unshift({ path: filePath, timestamp: Date.now() })
4470

4571
// Trim the list if it exceeds the maximum allowed
4672
if (recentLogs.length > maxRecentLogs) {
@@ -49,10 +75,10 @@ export default function createRecentLogsManager(maxRecentLogs: number = 10) {
4975
saveRecentLogs()
5076
},
5177

52-
getRecentLogs(): string[] {
78+
getRecentLogs(): RecentLog[] {
5379
// Filter out files that no longer exist
54-
const existingFiles: string[] = recentLogs.filter((file: string) =>
55-
fs.existsSync(file),
80+
const existingFiles: RecentLog[] = recentLogs.filter((log: RecentLog) =>
81+
fs.existsSync(log.path),
5682
)
5783

5884
// Update the list if files were removed

0 commit comments

Comments
 (0)