feat: Système de persistance des notes amélioré avec fichier unique par agent

- Un seul fichier notes_{agentId}.json par agent (plus d'accumulation)
- Auto-save après 2 secondes d'inactivité
- Restauration automatique au démarrage depuis fichier ou localStorage
- Historique des 50 dernières versions intégré dans le fichier
- Synchronisation transparente fichier/localStorage
- Notifications visuelles lors de la restauration
This commit is contained in:
Pierre Marx
2025-09-04 16:49:07 -04:00
parent 0aaa3e63f2
commit 06b4e2819d
3 changed files with 199 additions and 8 deletions

60
main.js
View File

@@ -471,25 +471,73 @@ ipcMain.handle('get-simulated-calls', () => {
});
});
// Sauvegarder les notes de l'agent
// Sauvegarder les notes de l'agent (un seul fichier par agent)
ipcMain.handle('save-notes', (event, noteData) => {
const notesDir = path.join(__dirname, 'notes');
if (!fs.existsSync(notesDir)) {
fs.mkdirSync(notesDir);
}
const fileName = `notes_${currentAgent.id}_${Date.now()}.json`;
// Un seul fichier par agent, mis à jour à chaque sauvegarde
const fileName = `notes_${currentAgent.id}.json`;
const filePath = path.join(notesDir, fileName);
fs.writeFileSync(filePath, JSON.stringify({
// Lire l'historique existant si le fichier existe
let notesData = {
agent: currentAgent.id,
timestamp: new Date().toISOString(),
...noteData
}, null, 2));
agentName: currentAgent.name,
currentNote: noteData.content,
lastModified: new Date().toISOString(),
centre: noteData.centre,
history: []
};
// Si le fichier existe, préserver l'historique
if (fs.existsSync(filePath)) {
try {
const existingData = JSON.parse(fs.readFileSync(filePath, 'utf8'));
// Ajouter l'ancienne note à l'historique si elle a changé
if (existingData.currentNote && existingData.currentNote !== noteData.content) {
notesData.history = existingData.history || [];
notesData.history.unshift({
content: existingData.currentNote,
date: existingData.lastModified,
centre: existingData.centre
});
// Limiter l'historique à 50 entrées
notesData.history = notesData.history.slice(0, 50);
}
} catch (error) {
console.error('Erreur lecture notes existantes:', error);
}
}
fs.writeFileSync(filePath, JSON.stringify(notesData, null, 2));
return { success: true, file: fileName };
});
// Récupérer les notes de l'agent
ipcMain.handle('get-notes', () => {
if (!currentAgent) return null;
const notesDir = path.join(__dirname, 'notes');
const fileName = `notes_${currentAgent.id}.json`;
const filePath = path.join(notesDir, fileName);
if (fs.existsSync(filePath)) {
try {
const data = fs.readFileSync(filePath, 'utf8');
return JSON.parse(data);
} catch (error) {
console.error('Erreur lecture notes:', error);
return null;
}
}
return null;
});
// Obtenir l'historique des appels
ipcMain.handle('get-call-history', () => {
const historyFile = path.join(__dirname, 'call_history.json');