1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-27 08:10:10 +00:00
msfs-popout-panel-manager/Orchestration/AppSettingData.cs
2024-02-27 21:44:21 -05:00

54 lines
1.9 KiB
C#

using MSFSPopoutPanelManager.DomainModel.Setting;
using MSFSPopoutPanelManager.Shared;
using System;
using System.Collections.Specialized;
namespace MSFSPopoutPanelManager.Orchestration
{
public class AppSettingData : ObservableObject
{
public event EventHandler<bool> OnAlwaysOnTopChanged;
public event EventHandler<bool> OnEnablePanelResetWhenLockedChanged;
public ApplicationSetting ApplicationSetting { get; private set; }
public void ReadSettings()
{
ApplicationSetting = AppSettingDataManager.ReadAppSetting();
if (ApplicationSetting == null)
{
ApplicationSetting = new ApplicationSetting();
AppSettingDataManager.WriteAppSetting(ApplicationSetting);
}
// Auto Save data
ApplicationSetting.PropertyChanged += (_, e) =>
{
AppSettingDataManager.WriteAppSetting(ApplicationSetting);
switch (e.PropertyName)
{
case "AlwaysOnTop":
OnAlwaysOnTopChanged?.Invoke(this, ApplicationSetting.GeneralSetting.AlwaysOnTop);
break;
case "EnablePanelResetWhenLocked":
OnEnablePanelResetWhenLockedChanged?.Invoke(this,
ApplicationSetting.PopOutSetting.EnablePanelResetWhenLocked);
break;
}
};
ApplicationSetting.DynamicLodSetting.TlodConfigs.CollectionChanged += (_, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Reset)
AppSettingDataManager.WriteAppSetting(ApplicationSetting);
};
ApplicationSetting.DynamicLodSetting.OlodConfigs.CollectionChanged += (_, _) =>
{
AppSettingDataManager.WriteAppSetting(ApplicationSetting);
};
}
}
}