Skip to content

Commit

Permalink
Remove InitializerManager from MainWindowViewModel class
Browse files Browse the repository at this point in the history
  • Loading branch information
Drombeys committed Apr 27, 2024
1 parent ae2868c commit 3afafaa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public class InitializerManager(
private readonly IReleaseComparerService<GitHubRelease> _releaseComparerService = releaseComparerService;
private readonly IUpdaterService _updaterService = updaterService;

public bool IsGameReleaseCurrent { get; private set; } = true;
public bool IsUserAuthorized { get; private set; }

public async Task InitializeAsync(ISplashScreenManager splashScreenManager)
{
try {
Expand Down Expand Up @@ -62,17 +59,17 @@ public async Task InitializeAsync(ISplashScreenManager splashScreenManager)
_launcherStorage.GitHubRelease = await _gitStorageApiService.GetLastReleaseAsync(cancellationToken: splashScreenManager.CancellationToken);
_logger.LogInformation("Check last release time: {Time}", stopwatch.ElapsedMilliseconds);

IsGameReleaseCurrent = await IsGameReleaseCurrentAsync(splashScreenManager.CancellationToken);
IsUserAuthorized = File.Exists(PathStorage.LauncherSetting);
_launcherStorage.IsGameReleaseCurrent = await IsGameReleaseCurrentAsync(splashScreenManager.CancellationToken);
_launcherStorage.IsUserAuthorized = File.Exists(PathStorage.LauncherSetting);

if (IsUserAuthorized) {
if (_launcherStorage.IsUserAuthorized) {
await Task.Factory.StartNew(() => LoadNewsAsync(locale, splashScreenManager.CancellationToken));
} else {
await Task.Factory.StartNew(() => LoadNewsAsync(cancellationToken: splashScreenManager.CancellationToken));
}
await Task.Factory.StartNew(() => LoadWebResourcesAsync(cancellationToken: splashScreenManager.CancellationToken));
} else {
if (IsUserAuthorized) {
if (_launcherStorage.IsUserAuthorized) {
_launcherStorage.NewsContents = new(LoadErrorNews(locale) ?? []);
} else {
_launcherStorage.NewsContents = new(LoadErrorNews() ?? []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ public interface ILauncherStorage
{
GitHubRelease? GitHubRelease { get; set; }
IList<Locale> Locales { get; }
[Reactive]
ObservableCollection<LangNewsContent>? NewsContents { get; set; }
[Reactive]
ObservableCollection<WebResource>? WebResources { get; set; }
[Reactive]
bool IsCheckGitHubConnection { get; set; }
bool IsGameReleaseCurrent { get; set; }
bool IsUserAuthorized { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MemoryLauncherStorage : ReactiveObject, ILauncherStorage
public ObservableCollection<LangNewsContent>? NewsContents { get; set; }
[Reactive]
public ObservableCollection<WebResource>? WebResources { get; set; }
[Reactive]
public bool IsCheckGitHubConnection { get; set; }
[Reactive] public bool IsCheckGitHubConnection { get; set; }
[Reactive] public bool IsGameReleaseCurrent { get; set; } = true;
[Reactive] public bool IsUserAuthorized { get; set; }
}
10 changes: 5 additions & 5 deletions src/ImeSense.Launchers.Belarus/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace ImeSense.Launchers.Belarus.ViewModels;
public class MainWindowViewModel : ReactiveObject
{
private readonly ILogger<MainWindowViewModel>? _logger;
private readonly ILauncherStorage _launcherStorage;
private readonly IUpdaterService _updaterService;
private readonly InitializerManager _initializerManager;
private readonly ViewModelLocator _viewModelLocator;
private readonly IApplicationLocaleManager _localeManager;
private readonly StartGameViewModel _startGameViewModel;
Expand All @@ -28,11 +28,11 @@ public class MainWindowViewModel : ReactiveObject

[Reactive] public ReactiveObject PageViewModel { get; set; } = null!;

public MainWindowViewModel(ILogger<MainWindowViewModel>? logger, InitializerManager initializerManager,
public MainWindowViewModel(ILogger<MainWindowViewModel>? logger, ILauncherStorage launcherStorage,
IUpdaterService updaterService, ViewModelLocator viewModelLocator, IApplicationLocaleManager localeManager)
{
_logger = logger;
_initializerManager = initializerManager;
_launcherStorage = launcherStorage;
_updaterService = updaterService;
_viewModelLocator = viewModelLocator;
_localeManager = localeManager;
Expand All @@ -47,7 +47,7 @@ public MainWindowViewModel()

_startGameViewModel = null!;
_launcherViewModel = null!;
_initializerManager = null!;
_launcherStorage = null!;
_updaterService = null!;
_viewModelLocator = null!;
_localeManager = null!;
Expand All @@ -65,7 +65,7 @@ public async Task InitializeAsync(ISplashScreenManager splashScreenManager)

ProcessHelper.KillAllXrEngine();

var isCurrentRelease = _initializerManager.IsGameReleaseCurrent;
var isCurrentRelease = _launcherStorage.IsGameReleaseCurrent;
if (File.Exists(PathStorage.LauncherSetting)) {
try {
if (!isCurrentRelease) {
Expand Down

0 comments on commit 3afafaa

Please sign in to comment.