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 public abstract class NotificationManager
{ {
protected readonly Logger? logger; protected Logger? logger;
public NotificationManagerType notificationManagerType; public NotificationManagerType notificationManagerType;
protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null) protected NotificationManager(NotificationManagerType notificationManagerType, Logger? logger = null)
@ -20,6 +20,11 @@ public abstract class NotificationManager
public abstract void SendNotification(string title, string notificationText); public abstract void SendNotification(string title, string notificationText);
public void AddLogger(Logger pLogger)
{
this.logger = pLogger;
}
public class NotificationManagerJsonConverter : JsonConverter public class NotificationManagerJsonConverter : JsonConverter
{ {
public override bool CanConvert(Type objectType) public override bool CanConvert(Type objectType)

View File

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