• Internal

    Adds entry to backup history and manages retention limit. Prepends new entry and removes oldest entries when history exceeds maximum.

    Parameters

    • entry: BackupHistoryEntry

      Backup history entry to add.

    • OptionalmaxRetention: number

      Optional custom retention limit (default: MAX_BACKUP_HISTORY).

    Returns void

    export function addBackupToHistory(
    entry: BackupHistoryEntry,
    maxRetention?: number,
    ): void {
    try {
    let history = getBackupHistory();

    // Prepend new entry (newest first)
    history = [entry, ...history];

    // Maintain history limit by removing oldest entries
    // Use provided maxRetention if available, otherwise use the constant
    const limit = maxRetention ?? MAX_BACKUP_HISTORY;
    history = history.slice(0, limit);

    // Save to storage
    storage.setItem(STORAGE_KEYS.BACKUP_HISTORY, JSON.stringify(history));
    console.log("[Backup] History updated, total backups:", history.length);
    } catch (error) {
    console.error("[Backup] Failed to add entry to backup history:", error);
    }
    }