From c8d98e72d0b199a12496b8a777cc39ed2afabe33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Tue, 30 Sep 2025 19:05:34 +0200 Subject: [PATCH] Fix file not being saved on exit --- src/Repository/JsonRepository.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Repository/JsonRepository.cs b/src/Repository/JsonRepository.cs index 3f4f069..8d2c58f 100644 --- a/src/Repository/JsonRepository.cs +++ b/src/Repository/JsonRepository.cs @@ -6,6 +6,7 @@ namespace Repository; public class JsonRepository : IRepository, IDisposable { private const string _appName = "Keychain"; + private const string fileName = "password_stores.json"; private uint _autoIncrementedId; private readonly string _filePath; @@ -33,6 +34,9 @@ public class JsonRepository : IRepository, IDisposable var lastItem = _cache.OrderBy(item => item.ID).LastOrDefault(); _autoIncrementedId = lastItem != null ? lastItem.ID : 0; + + // Ensure Dispose is called when the process exits + AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); } private void ReadAllFromFile() @@ -91,8 +95,6 @@ public class JsonRepository : IRepository, IDisposable { WriteToStdErr($"Unexpected error: {e.Message}"); } - - ReadAllFromFile(); } }