Skip to content

Commit

Permalink
show message also in ui thread
Browse files Browse the repository at this point in the history
  • Loading branch information
frosch95 committed Aug 14, 2023
1 parent 6d03c88 commit 7f7471d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion K8sFileBrowser/K8sFileBrowser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
<ApplicationIcon>Assets/app.ico</ApplicationIcon>
<Version>0.0.9</Version>
<Version>0.1.1</Version>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
73 changes: 40 additions & 33 deletions K8sFileBrowser/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ namespace K8sFileBrowser.ViewModels;

public class MainWindowViewModel : ViewModelBase
{

#region Properties

[Reactive]
public string? Version { get; set; } = null!;

[Reactive]
public IEnumerable<ClusterContext> ClusterContexts { get; set; } = null!;

Expand Down Expand Up @@ -58,11 +58,11 @@ public class MainWindowViewModel : ViewModelBase

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

#endregion Properties

#region Commands

public ReactiveCommand<Unit, Unit> DownloadCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> DownloadLogCommand { get; private set; } = null!;
public ReactiveCommand<Unit, Unit> ParentCommand { get; private set; } = null!;
Expand Down Expand Up @@ -96,7 +96,7 @@ public MainWindowViewModel()
}

#region Property Subscriptions

private void InitiallyLoadContexts(IKubernetesService kubernetesService)
{
// load the cluster contexts when the view model is created
Expand All @@ -115,7 +115,7 @@ private void InitiallyLoadContexts(IKubernetesService kubernetesService)
.FirstOrDefault(c => c.Name == kubernetesService.GetCurrentContext());
});
}

private void RegisterReadNamespaces(IKubernetesService kubernetesService)
{
// read the cluster contexts
Expand All @@ -130,7 +130,7 @@ private void RegisterReadNamespaces(IKubernetesService kubernetesService)
Namespaces = ns;
});
}

private void RegisterReadPods()
{
// read the pods when the namespace changes
Expand All @@ -146,7 +146,7 @@ private void RegisterReadPods()
Pods = x;
});
}

private void RegisterReadContainers()
{
// read the file information when the path changes
Expand Down Expand Up @@ -290,11 +290,11 @@ private void ConfigureOpenDirectoryCommand()
OpenCommand.ThrownExceptions.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(ShowErrorMessage);
}

#endregion Configure Commands

#region Get Data

private static async Task<IEnumerable<Pod>> PodsAsync(Namespace? ns, IKubernetesService kubernetesService)
{
if (ns == null)
Expand Down Expand Up @@ -346,67 +346,74 @@ private IList<FileInformation> GetFileInformation(IKubernetesService kubernetesS
Parent = parent
}).ToList();
}

#endregion Get Data

#region Reset Data

private void ResetPath()
{
FileInformation = new List<FileInformation>();
SelectedPath = null;
SelectedContainer = null;
}
}

private void ResetContainers()
{
ResetPath();
Containers = new List<Container>();
SelectedPod = null;

}
}

private void ResetPods()
{
ResetContainers();
SelectedNamespace = null;
Pods = new List<Pod>();

}
}

private void ResetNamespaces()
{
ResetPods();
Namespaces = new List<Namespace>();
SelectedClusterContext = null;
}
}

#endregion Reset Data

#region show messages

private void ShowWorkingMessage(string message)
{
Message = new Message
RxApp.MainThreadScheduler.Schedule(Action);
return;

void Action()
{
IsVisible = true,
Text = message,
IsError = false
};
Message = new Message
{
IsVisible = true,
Text = message,
IsError = false
};
}
}

private void ShowErrorMessage(string message)
{
RxApp.MainThreadScheduler.Schedule(Action);
return;

async void Action()
{
Message = new Message { IsVisible = true, Text = message, IsError = true };
await Task.Delay(7000);
HideWorkingMessage();
}

RxApp.MainThreadScheduler.Schedule(Action);
}

private void ShowErrorMessage(Exception exception)
{
// ReSharper disable once TemplateIsNotCompileTimeConstantProblem
Expand All @@ -423,6 +430,6 @@ private void HideWorkingMessage()
IsError = false
});
}

#endregion show messages
}

0 comments on commit 7f7471d

Please sign in to comment.