From 57b36c7e53e408fe0cad4868aa41b12de22a8d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Fri, 2 Dec 2022 11:03:28 +0100 Subject: [PATCH] Data sharing is part of Manager --- SteamController/Controller.cs | 20 ++----------- SteamController/Managers/SharedDataManager.cs | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 SteamController/Managers/SharedDataManager.cs diff --git a/SteamController/Controller.cs b/SteamController/Controller.cs index c5dd295..e990829 100644 --- a/SteamController/Controller.cs +++ b/SteamController/Controller.cs @@ -27,12 +27,11 @@ namespace SteamController Managers = { new Managers.ProcessManager(), new Managers.SteamManager(), - new Managers.ProfileSwitcher() + new Managers.ProfileSwitcher(), + new Managers.SharedDataManager() } }; - SharedData sharedData = SharedData.CreateNew(); - public Controller() { Instance.RunOnce(TitleWithVersion, "Global\\SteamController"); @@ -130,24 +129,9 @@ namespace SteamController context.Start(); } - private void SharedData_Update() - { - if (sharedData.GetValue(out var value) && value.DesiredProfile != "") - { - context.SelectProfile(value.DesiredProfile); - } - - sharedData.SetValue(new SteamControllerSetting() - { - CurrentProfile = context.CurrentProfile?.Name ?? "", - SelectableProfiles = context.Profiles.Where((profile) => profile.Selected(context) || profile.Visible).JoinWithN((profile) => profile.Name), - }); - } - private void ContextStateUpdate_Tick(object? sender, EventArgs e) { context.Tick(); - SharedData_Update(); var isDesktop = context.CurrentProfile?.IsDesktop ?? false; diff --git a/SteamController/Managers/SharedDataManager.cs b/SteamController/Managers/SharedDataManager.cs new file mode 100644 index 0000000..28380e8 --- /dev/null +++ b/SteamController/Managers/SharedDataManager.cs @@ -0,0 +1,30 @@ +using CommonHelpers; + +namespace SteamController.Managers +{ + public sealed class SharedDataManager : Manager + { + SharedData sharedData = SharedData.CreateNew(); + + public override void Tick(Context context) + { + if (sharedData.GetValue(out var value) && value.DesiredProfile != "") + { + context.SelectProfile(value.DesiredProfile); + } + + sharedData.SetValue(new SteamControllerSetting() + { + CurrentProfile = context.CurrentProfile?.Name ?? "", + SelectableProfiles = SelectableProfiles(context).JoinWith0(), + }); + } + + private IEnumerable SelectableProfiles(Context context) + { + return context.Profiles. + Where((profile) => profile.Selected(context) || profile.Visible). + Select((profile) => profile.Name); + } + } +}