add logging

This commit is contained in:
Julian Freeman
2025-12-02 10:44:14 -04:00
parent 068bc1c79e
commit d2cafc328f
6 changed files with 312 additions and 30 deletions

54
src/stores/logs.ts Normal file
View File

@@ -0,0 +1,54 @@
// filepath: src/stores/logs.ts
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { listen } from '@tauri-apps/api/event'
export interface LogEntry {
id: string
taskId: string
message: string
level: 'info' | 'error'
timestamp: number
}
interface LogEvent {
id: string
message: string
level: string
}
export const useLogsStore = defineStore('logs', () => {
const logs = ref<LogEntry[]>([])
const isListening = ref(false)
function addLog(taskId: string, message: string, level: 'info' | 'error') {
logs.value.push({
id: crypto.randomUUID(),
taskId,
message,
level,
timestamp: Date.now()
})
// Optional: Limit log size to avoid memory issues
if (logs.value.length > 5000) {
logs.value = logs.value.slice(-5000)
}
}
async function initListener() {
if (isListening.value) return
isListening.value = true
await listen<LogEvent>('download-log', (event) => {
const { id, message, level } = event.payload
addLog(id, message, level as 'info' | 'error')
})
}
function clearLogs() {
logs.value = []
}
return { logs, addLog, initListener, clearLogs }
})