Skip to content

Commit

Permalink
🐛 修复某些情况导入SDA令牌出错
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Jan 4, 2024
1 parent 83ae310 commit 9805ad4
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 17 deletions.
11 changes: 2 additions & 9 deletions src/BD.WTTS.Client.Avalonia/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ namespace BD.WTTS.UI;

public static class ControlExtensions
{
public static void SetViewModel<T>(this Control c, bool useCache = true) where T : ViewModelBase
public static void SetViewModel<T>(this Control c) where T : ViewModelBase, new()
{
if (c.DataContext == null || c.DataContext.GetType() != typeof(T))
{
T cx;

if (useCache)
cx = IViewModelManager.Instance.Get<T>();
else
cx = Activator.CreateInstance<T>();

c.DataContext = cx;
c.DataContext = new T();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public partial class AboutPage : ReactiveUserControl<AboutPageViewModel>
public AboutPage()
{
InitializeComponent();
this.SetViewModel<AboutPageViewModel>(false);
DataContext = new AboutPageViewModel();
this.SetViewModel<AboutPageViewModel>();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class DebugPage : PageBase<DebugPageViewModel>
public DebugPage()
{
InitializeComponent();
this.SetViewModel<DebugPageViewModel>(false);
this.SetViewModel<DebugPageViewModel>();

CommandTextBox.KeyUp += (s, e) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class HomePage : ReactiveUserControl<HomePageViewModel>
public HomePage()
{
InitializeComponent();
this.SetViewModel<HomePageViewModel>(true);
this.SetViewModel<HomePageViewModel>();

//ShopsScrollViewer.PointerWheelChanged += ShopsScrollViewer_PointerWheelChanged;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class SettingsPage : PageBase<SettingsPageViewModel>
public SettingsPage()
{
InitializeComponent();
this.SetViewModel<SettingsPageViewModel>(false);
this.SetViewModel<SettingsPageViewModel>();

//SettingsScrollTab.SelectionChanged += SettingsScrollTab_SelectionChanged;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LoginOrRegisterPage()
protected override void OnLoaded(RoutedEventArgs e)
{
base.OnLoaded(e);
this.SetViewModel<LoginOrRegisterWindowViewModel>(false);
this.SetViewModel<LoginOrRegisterWindowViewModel>();

if (this.ViewModel != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public partial class AcceleratorPage : PageBase<AcceleratorPageViewModel>
public AcceleratorPage()
{
InitializeComponent();
this.SetViewModel<AcceleratorPageViewModel>(false);
this.SetViewModel<AcceleratorPageViewModel>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class ScriptPage : PageBase<ScriptPageViewModel>
public ScriptPage()
{
InitializeComponent();
this.SetViewModel<ScriptPageViewModel>(false);
this.SetViewModel<ScriptPageViewModel>();

//StoreButton.Click += StoreButton_Click;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class SdaFileModel
[JsonPropertyName("secret_1")]
public string Secret1 { get; set; } = string.Empty;

[JsonConverter(typeof(SteamDataIntConverter))]
[JsonPropertyName("status")]
public int Status { get; set; }

Expand Down Expand Up @@ -110,6 +111,7 @@ public class Session
[JsonPropertyName("OAuthToken")]
public string OAuthToken { get; set; } = string.Empty;

[JsonConverter(typeof(SteamDataLongConverter))]
[JsonPropertyName("SteamID")]
public long SteamId { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class GameAccountPage : PageBase<GameAccountPageViewModel>
public GameAccountPage()
{
InitializeComponent();
this.SetViewModel<GameAccountPageViewModel>(true);
this.SetViewModel<GameAccountPageViewModel>();
//DataContext ??= new GameAccountPageViewModel();

//this.WhenActivated(disposable =>
Expand Down

0 comments on commit 9805ad4

Please sign in to comment.