Fix file not being saved on exit
This commit is contained in:
@@ -6,6 +6,7 @@ namespace Repository;
|
|||||||
public class JsonRepository : IRepository, IDisposable
|
public class JsonRepository : IRepository, IDisposable
|
||||||
{
|
{
|
||||||
private const string _appName = "Keychain";
|
private const string _appName = "Keychain";
|
||||||
|
private const string fileName = "password_stores.json";
|
||||||
|
|
||||||
private uint _autoIncrementedId;
|
private uint _autoIncrementedId;
|
||||||
private readonly string _filePath;
|
private readonly string _filePath;
|
||||||
@@ -33,6 +34,9 @@ public class JsonRepository : IRepository, IDisposable
|
|||||||
|
|
||||||
var lastItem = _cache.OrderBy(item => item.ID).LastOrDefault();
|
var lastItem = _cache.OrderBy(item => item.ID).LastOrDefault();
|
||||||
_autoIncrementedId = lastItem != null ? lastItem.ID : 0;
|
_autoIncrementedId = lastItem != null ? lastItem.ID : 0;
|
||||||
|
|
||||||
|
// Ensure Dispose is called when the process exits
|
||||||
|
AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReadAllFromFile()
|
private void ReadAllFromFile()
|
||||||
@@ -91,8 +95,6 @@ public class JsonRepository : IRepository, IDisposable
|
|||||||
{
|
{
|
||||||
WriteToStdErr($"Unexpected error: {e.Message}");
|
WriteToStdErr($"Unexpected error: {e.Message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadAllFromFile();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user