Fixed missing logger for notificationManagers on deserialization

This commit is contained in:
glax 2023-07-09 21:38:49 +02:00
parent 78023ef0fd
commit 0f8932e712
2 changed files with 10 additions and 1 deletions

View File

@ -7,7 +7,7 @@ namespace Tranga;
public abstract class NotificationManager
{
protected readonly Logger? logger;
protected Logger? logger;
public NotificationManagerType notificationManagerType;
protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null)
@ -19,6 +19,11 @@ public abstract class NotificationManager
public enum NotificationManagerType : byte { Gotify = 0, LunaSea = 1 }
public abstract void SendNotification(string title, string notificationText);
public void AddLogger(Logger pLogger)
{
this.logger = pLogger;
}
public class NotificationManagerJsonConverter : JsonConverter
{

View File

@ -37,8 +37,12 @@ public class TrangaSettings
TrangaSettings settings = JsonConvert.DeserializeObject<TrangaSettings>(toRead,
new JsonSerializerSettings { Converters = { new NotificationManager.NotificationManagerJsonConverter(), new LibraryManager.LibraryManagerJsonConverter() } })!;
if (logger is not null)
{
foreach (LibraryManager lm in settings.libraryManagers)
lm.AddLogger(logger);
foreach(NotificationManager nm in settings.notificationManagers)
nm.AddLogger(logger);
}
return settings;
}