Skip to content

Commit

Permalink
hang onto event handlers in service helper for re-use
Browse files Browse the repository at this point in the history
added method to coreservice to reload settings and coresservices
  • Loading branch information
mattpannella committed May 29, 2024
1 parent 8097c36 commit 4e0bc1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/helpers/ServiceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static class ServiceHelper
public static FirmwareService FirmwareService { get; private set; }
public static ArchiveService ArchiveService { get; private set; }
public static AssetsService AssetsService { get; private set; }
public static EventHandler<StatusUpdatedEventArgs> StatusUpdated { get; private set; }
public static EventHandler<UpdateProcessCompleteEventArgs> UpdateProcessComplete { get; private set; }

private static bool isInitialized;

Expand Down Expand Up @@ -40,11 +42,13 @@ public static void Initialize(string path, EventHandler<StatusUpdatedEventArgs>
FirmwareService.StatusUpdated += statusUpdated;
CoresService.StatusUpdated += statusUpdated;
ArchiveService.StatusUpdated += statusUpdated;
StatusUpdated = statusUpdated;
}

if (updateProcessComplete != null)
{
CoresService.UpdateProcessComplete += updateProcessComplete;
UpdateProcessComplete = updateProcessComplete;
}
}
}
Expand All @@ -56,5 +60,6 @@ public static void ReloadSettings()
ArchiveService = new ArchiveService(SettingsService.GetConfig().archives,
SettingsService.GetConfig().crc_check, SettingsService.GetConfig().use_custom_archive);
CoresService = new CoresService(UpdateDirectory, SettingsService, ArchiveService, AssetsService);
CoresService.StatusUpdated += StatusUpdated;
}
}
1 change: 1 addition & 0 deletions src/partials/Program.Menus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ private static void DisplayMenu(CoreUpdaterService coreUpdaterService)
SettingsMenu();
// Is reloading the settings file necessary?
ServiceHelper.ReloadSettings();
coreUpdaterService.ReloadSettings();
})
.Add("Exit", ConsoleMenu.Close);

Expand Down
10 changes: 8 additions & 2 deletions src/services/CoreUpdaterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class CoreUpdaterService : BaseProcess
private readonly string installPath;
private readonly List<Core> cores;
private readonly FirmwareService firmwareService;
private readonly SettingsService settingsService;
private readonly CoresService coresService;
private SettingsService settingsService;
private CoresService coresService;

public CoreUpdaterService(
string path,
Expand Down Expand Up @@ -356,4 +356,10 @@ public void DeleteCore(Core core, bool force = false, bool nuke = false)
this.coresService.Uninstall(core.identifier, core.platform_id, nuke);
}
}

public void ReloadSettings()
{
this.settingsService = ServiceHelper.SettingsService;;
this.coresService = ServiceHelper.CoresService;
}
}

0 comments on commit 4e0bc1c

Please sign in to comment.