Skip to content

Commit

Permalink
Fixed SplashView opening infinite number of windows
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicPredator committed Mar 21, 2024
1 parent 0ec0d32 commit 20fc425
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/AniMoe.App/ViewModels/AnimeListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public async Task InitView(bool isReload = false)
}
if ( Model == null || isReload)
{
Model = await Initialize.FetchData();
//Model = await Initialize.FetchData();
Model = App.Current.Services.GetRequiredService<SplashViewModel>().AnimeListModelObj;
}
LoadStatusBar = true;
if( Model.Data.MediaListCollection.Lists.Count > 0 )
Expand Down
4 changes: 3 additions & 1 deletion src/AniMoe.App/ViewModels/MangaListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using AniMoe.App.Models;
using Microsoft.UI.Xaml.Media;
using Windows.UI;
using Microsoft.Extensions.DependencyInjection;

namespace AniMoe.App.ViewModels
{
Expand Down Expand Up @@ -151,7 +152,8 @@ public async Task InitView(bool isReload = false)
}
if( Model == null || isReload )
{
Model = await Initialize.FetchData();
// Model = await Initialize.FetchData();
Model = App.Current.Services.GetRequiredService<SplashViewModel>().MangaListModelObj;
}
LoadStatusBar = true;
if( Model.Data.MediaListCollection.Lists.Count > 0 )
Expand Down
2 changes: 1 addition & 1 deletion src/AniMoe.App/ViewModels/ReviewViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class ReviewViewModel : ObservableObject
private IMdToHtmlParser MdToHtmlParser = App.Current.Services.GetRequiredService<IMdToHtmlParser>();
private DispatcherQueue dispatcherQueue;
private string createdTime;
private MasterViewModel masterViewModel = App.Current.Services.GetRequiredService<MasterViewModel>();
private SplashViewModel masterViewModel = App.Current.Services.GetRequiredService<SplashViewModel>();

[ObservableProperty]
private bool isLoading = true;
Expand Down
27 changes: 19 additions & 8 deletions src/AniMoe.App/ViewModels/SplashViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AnimeList = AniMoe.App.Models.AnimeListModels;
using MangaList = AniMoe.App.Models.MangaListModel;

namespace AniMoe.App.ViewModels
{
public partial class SplashViewModel : ObservableObject
{
public MediaListStatusModel mediaListStatusModel;
private readonly ILocalSettings _localSettings;
private RootWindow rootWindow = null;

[ObservableProperty] private MasterModel model;

[ObservableProperty] string _statusText;

[ObservableProperty] AnimeList.AnimeListModel animeListModelObj;

[ObservableProperty] MangaList.MangaListModel mangaListModelObj;

public SplashViewModel(MasterModel model, ILocalSettings settings)
{
_localSettings = settings;
Expand All @@ -34,13 +40,12 @@ public SplashViewModel(MasterModel model, ILocalSettings settings)
public async void Window_Activated(object sender, WindowActivatedEventArgs args)
{
var ins = Application.Current as App;
var window = ins.m_window;
if (window is SplashView splashView) return;
if (window is RootWindow roowindow) return;
if (_localSettings.IsSettingExists("accessToken"))
await LoadFromApi();
if (rootWindow == null)
if (args.WindowActivationState == WindowActivationState.CodeActivated)
{
if (_localSettings.IsSettingExists("accessToken"))
await LoadFromApi();
else
await Task.Delay(1000);
var mwindow = new RootWindow();
mwindow.ExtendsContentIntoTitleBar = true;
((Window)sender).Close();
Expand All @@ -54,14 +59,20 @@ public async Task LoadFromApi()
StatusText = "Fetching user data...";
Model = await Models.MasterModel.Initialize.FetchData();

StatusText = "Fetching Anime & Manga lists...";
StatusText = "Fetching user status...";
mediaListStatusModel
= await Models.MediaListStatusModel.Initialize.FetchData(Model.Data.User.Id);
EnumValue defaultValue = new EnumValue { Name = "Select One" };
Model.Data.MediaSourceList.EnumValues.Insert(0, defaultValue);
Model.Data.MediaSeasonList.EnumValues.Insert(0, defaultValue);
Model.Data.MediaFormatList.EnumValues.Insert(0, defaultValue);

StatusText = "Fetching user anime list...";
AnimeListModelObj = await AnimeList.Initialize.FetchData();

StatusText = "Fetching user manga list...";
MangaListModelObj = await MangaList.Initialize.FetchData();

StatusText = "Launching AniMoe...";
}
}
Expand Down

0 comments on commit 20fc425

Please sign in to comment.