Skip to content

Commit 1410f64

Browse files
committed
Fix nebula tab not displaying all mods sometimes
1 parent f4ba39b commit 1410f64

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

Knossos.NET/ViewModels/NebulaModListViewModel.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,33 @@ public NebulaModListViewModel()
8484
/// </summary>
8585
public async void OpenTab()
8686
{
87-
if (!IsLoading && !IsTabOpen)
87+
if (IsLoading)
8888
{
89-
await Dispatcher.UIThread.InvokeAsync(async () =>
89+
IsTabOpen = true;
90+
return;
91+
}
92+
93+
if (!IsTabOpen)
94+
{
95+
IsTabOpen = true;
96+
await Dispatcher.UIThread.InvokeAsync(async () =>
9097
{
9198
try
9299
{
93100
await Task.Delay(100);
94101
IsLoading = false;
95-
foreach (var m in Mods)
102+
foreach (NebulaModCardViewModel m in Mods.ToList())
96103
{
97104
m.Visible = true;
98-
await Task.Delay(3);
105+
await Task.Delay(1);
99106
}
100107
}
101-
catch { }
108+
catch (Exception ex)
109+
{
110+
Log.Add(Log.LogSeverity.Error, "NebulaModListViewModel.OpenTab", ex);
111+
}
102112
});
103113
}
104-
IsTabOpen = true;
105114
}
106115

107116
/// <summary>
@@ -140,7 +149,10 @@ public void AddMod(Mod modJson)
140149
}
141150
}
142151
}
143-
Mods.Insert(i, new NebulaModCardViewModel(modJson));
152+
var card = new NebulaModCardViewModel(modJson);
153+
if (IsLoading)
154+
card.Visible = false;
155+
Mods.Insert(i, card);
144156
}
145157
else
146158
{
@@ -155,6 +167,8 @@ public void AddMod(Mod modJson)
155167
/// <param name="modList"></param>
156168
public async void AddMods(List<Mod> modList)
157169
{
170+
IsLoading = true;
171+
await Task.Delay(20);
158172
var newModCardList = new ObservableCollection<NebulaModCardViewModel>();
159173
foreach (Mod? mod in modList)
160174
{
@@ -172,30 +186,22 @@ public async void AddMods(List<Mod> modList)
172186
}
173187
}
174188
}
175-
newModCardList.Insert(i, new NebulaModCardViewModel(mod));
189+
var card = new NebulaModCardViewModel(mod);
190+
card.Visible = false;
191+
newModCardList.Insert(i, card);
176192
}
177193
else
178194
{
179195
//Update? Should NOT be needed for Nebula mods
180196
}
181197
}
182-
newModCardList.ForEach(m=>m.Visible = false);
183198
Mods = newModCardList;
199+
IsLoading = false;
184200
if (IsTabOpen)
185201
{
186-
try
187-
{
188-
await Task.Delay(100);
189-
IsLoading = false;
190-
foreach (var m in Mods)
191-
{
192-
m.Visible = true;
193-
await Task.Delay(3);
194-
}
195-
}
196-
catch { }
202+
IsTabOpen = false;
203+
OpenTab();
197204
}
198-
IsLoading = false;
199205
}
200206

201207
/// <summary>

0 commit comments

Comments
 (0)