Skip to content

Commit 7f7471d

Browse files
committed
show message also in ui thread
1 parent 6d03c88 commit 7f7471d

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

K8sFileBrowser/K8sFileBrowser.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Configurations>Debug;Release</Configurations>
1010
<Platforms>AnyCPU</Platforms>
1111
<ApplicationIcon>Assets/app.ico</ApplicationIcon>
12-
<Version>0.0.9</Version>
12+
<Version>0.1.1</Version>
1313
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
1414
</PropertyGroup>
1515
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">

K8sFileBrowser/ViewModels/MainWindowViewModel.cs

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace K8sFileBrowser.ViewModels;
1717

1818
public class MainWindowViewModel : ViewModelBase
1919
{
20-
20+
2121
#region Properties
22-
22+
2323
[Reactive]
2424
public string? Version { get; set; } = null!;
25-
25+
2626
[Reactive]
2727
public IEnumerable<ClusterContext> ClusterContexts { get; set; } = null!;
2828

@@ -58,11 +58,11 @@ public class MainWindowViewModel : ViewModelBase
5858

5959
[Reactive]
6060
public Message Message { get; set; } = null!;
61-
61+
6262
#endregion Properties
6363

6464
#region Commands
65-
65+
6666
public ReactiveCommand<Unit, Unit> DownloadCommand { get; private set; } = null!;
6767
public ReactiveCommand<Unit, Unit> DownloadLogCommand { get; private set; } = null!;
6868
public ReactiveCommand<Unit, Unit> ParentCommand { get; private set; } = null!;
@@ -96,7 +96,7 @@ public MainWindowViewModel()
9696
}
9797

9898
#region Property Subscriptions
99-
99+
100100
private void InitiallyLoadContexts(IKubernetesService kubernetesService)
101101
{
102102
// load the cluster contexts when the view model is created
@@ -115,7 +115,7 @@ private void InitiallyLoadContexts(IKubernetesService kubernetesService)
115115
.FirstOrDefault(c => c.Name == kubernetesService.GetCurrentContext());
116116
});
117117
}
118-
118+
119119
private void RegisterReadNamespaces(IKubernetesService kubernetesService)
120120
{
121121
// read the cluster contexts
@@ -130,7 +130,7 @@ private void RegisterReadNamespaces(IKubernetesService kubernetesService)
130130
Namespaces = ns;
131131
});
132132
}
133-
133+
134134
private void RegisterReadPods()
135135
{
136136
// read the pods when the namespace changes
@@ -146,7 +146,7 @@ private void RegisterReadPods()
146146
Pods = x;
147147
});
148148
}
149-
149+
150150
private void RegisterReadContainers()
151151
{
152152
// read the file information when the path changes
@@ -290,11 +290,11 @@ private void ConfigureOpenDirectoryCommand()
290290
OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
291291
.Subscribe(ShowErrorMessage);
292292
}
293-
293+
294294
#endregion Configure Commands
295295

296296
#region Get Data
297-
297+
298298
private static async Task<IEnumerable<Pod>> PodsAsync(Namespace? ns, IKubernetesService kubernetesService)
299299
{
300300
if (ns == null)
@@ -346,67 +346,74 @@ private IList<FileInformation> GetFileInformation(IKubernetesService kubernetesS
346346
Parent = parent
347347
}).ToList();
348348
}
349-
349+
350350
#endregion Get Data
351-
351+
352352
#region Reset Data
353-
353+
354354
private void ResetPath()
355355
{
356356
FileInformation = new List<FileInformation>();
357357
SelectedPath = null;
358358
SelectedContainer = null;
359-
}
360-
359+
}
360+
361361
private void ResetContainers()
362362
{
363363
ResetPath();
364364
Containers = new List<Container>();
365365
SelectedPod = null;
366366

367-
}
368-
367+
}
368+
369369
private void ResetPods()
370370
{
371371
ResetContainers();
372372
SelectedNamespace = null;
373373
Pods = new List<Pod>();
374374

375-
}
376-
375+
}
376+
377377
private void ResetNamespaces()
378378
{
379379
ResetPods();
380380
Namespaces = new List<Namespace>();
381381
SelectedClusterContext = null;
382-
}
383-
382+
}
383+
384384
#endregion Reset Data
385-
385+
386386
#region show messages
387-
387+
388388
private void ShowWorkingMessage(string message)
389389
{
390-
Message = new Message
390+
RxApp.MainThreadScheduler.Schedule(Action);
391+
return;
392+
393+
void Action()
391394
{
392-
IsVisible = true,
393-
Text = message,
394-
IsError = false
395-
};
395+
Message = new Message
396+
{
397+
IsVisible = true,
398+
Text = message,
399+
IsError = false
400+
};
401+
}
396402
}
397403

398404
private void ShowErrorMessage(string message)
399405
{
406+
RxApp.MainThreadScheduler.Schedule(Action);
407+
return;
408+
400409
async void Action()
401410
{
402411
Message = new Message { IsVisible = true, Text = message, IsError = true };
403412
await Task.Delay(7000);
404413
HideWorkingMessage();
405414
}
406-
407-
RxApp.MainThreadScheduler.Schedule(Action);
408415
}
409-
416+
410417
private void ShowErrorMessage(Exception exception)
411418
{
412419
// ReSharper disable once TemplateIsNotCompileTimeConstantProblem
@@ -423,6 +430,6 @@ private void HideWorkingMessage()
423430
IsError = false
424431
});
425432
}
426-
433+
427434
#endregion show messages
428435
}

0 commit comments

Comments
 (0)