35d46f532a
- electron/epic.ts: auto-detect Epic Games from Manifests/*.item (skip DLCs) - electron/favorites.ts: persist favorites + recent (last 20) in userData - electron/steam.ts: replace winreg callbacks with reg query execSync + fallback paths - electron: new IPC handlers — favorites:get/toggle, recent:get; launch tracks recent - UI: star button on cards (favorites), sort A→Z/Z→A toggle, skeleton loading, fade-in card animation, Epic/Favorites/Recent filter tabs, SVG placeholder with initials Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { app } from 'electron'
|
|
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
import { join } from 'path'
|
|
|
|
function readJson<T>(path: string, fallback: T): T {
|
|
if (!existsSync(path)) return fallback
|
|
try {
|
|
return JSON.parse(readFileSync(path, 'utf-8')) as T
|
|
} catch {
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
function favPath(): string {
|
|
return join(app.getPath('userData'), 'favorites.json')
|
|
}
|
|
|
|
function recentPath(): string {
|
|
return join(app.getPath('userData'), 'recent.json')
|
|
}
|
|
|
|
export function getFavorites(): string[] {
|
|
return readJson<string[]>(favPath(), [])
|
|
}
|
|
|
|
export function toggleFavorite(id: string): string[] {
|
|
const favs = getFavorites()
|
|
const updated = favs.includes(id) ? favs.filter((f) => f !== id) : [...favs, id]
|
|
writeFileSync(favPath(), JSON.stringify(updated), 'utf-8')
|
|
return updated
|
|
}
|
|
|
|
export function getRecent(): string[] {
|
|
return readJson<string[]>(recentPath(), [])
|
|
}
|
|
|
|
export function addRecent(id: string): string[] {
|
|
const recent = getRecent().filter((r) => r !== id)
|
|
const updated = [id, ...recent].slice(0, 20)
|
|
writeFileSync(recentPath(), JSON.stringify(updated), 'utf-8')
|
|
return updated
|
|
}
|