Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

Commit

Permalink
Settings now show latency
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew committed Dec 17, 2019
1 parent d4fe320 commit 96f5cfe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 12 additions & 4 deletions Docdown/ViewModel/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Docdown.Editor.Markdown;
using Docdown.Model;
using Docdown.Model;
using Docdown.Properties;
using Docdown.Util;
using Docdown.ViewModel.Commands;
using Microsoft.WindowsAPICodePack.Dialogs;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -131,6 +129,12 @@ public ConnectionStatus ConnectionStatus
set => Set(ref connectionStatus, value);
}

public int Ping
{
get => ping;
set => Set(ref ping, value);
}

public bool CanCompileOffline { get; }

[ChangeListener(nameof(ConnectionStatus))]
Expand All @@ -147,6 +151,7 @@ public ConnectionStatus ConnectionStatus
private string[] csls;
private string selectedTemplateName;
private ConnectionStatus connectionStatus;
private int ping;

public SettingsViewModel(AppViewModel app)
{
Expand Down Expand Up @@ -184,7 +189,10 @@ public async Task TestConnection()
if (ConnectionStatus != ConnectionStatus.Connecting)
{
ConnectionStatus = ConnectionStatus.Connecting;
Stopwatch sw = Stopwatch.StartNew();
ConnectionStatus = await app.ConverterService.Connect();
sw.Stop();
Ping = (int)sw.ElapsedMilliseconds;
if (IsConnected)
{
await LoadTemplates();
Expand Down
15 changes: 11 additions & 4 deletions Docdown/Windows/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,29 +78,36 @@
<Style BasedOn="{StaticResource DefaultButtonTextBoxStyle}" TargetType="TextBox">
<Setter Property="Metro:TextBoxHelper.ButtonContent">
<Setter.Value>
<Rectangle Height="18" Width="18" Fill="{StaticResource ConnectIcon}"/>
<Rectangle Height="18" Width="18" Fill="{StaticResource ConnectIcon}" ToolTip="Click here to connect"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ConnectionStatus}" Value="Connected">
<Setter Property="Metro:TextBoxHelper.ButtonContent">
<Setter.Value>
<Rectangle Height="18" Width="18" Fill="{StaticResource PassIcon}"/>
<Rectangle Height="18"
Width="18"
Fill="{StaticResource PassIcon}">
<Rectangle.ToolTip>
<ToolTip Content="{Binding Ping}"
ContentStringFormat="Latency {0} ms"/>
</Rectangle.ToolTip>
</Rectangle>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ConnectionStatus}" Value="Disconnected">
<Setter Property="Metro:TextBoxHelper.ButtonContent">
<Setter.Value>
<Rectangle Height="18" Width="18" Fill="{StaticResource FailIcon}"/>
<Rectangle Height="18" Width="18" Fill="{StaticResource FailIcon}" ToolTip="Connection could not be established"/>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ConnectionStatus}" Value="Connecting">
<Setter Property="Metro:TextBoxHelper.ButtonContent">
<Setter.Value>
<Viewbox Height="18" Width="18" Stretch="UniformToFill" StretchDirection="Both">
<Control Style="{StaticResource BusyAnimationStyle}"/>
<Control Style="{StaticResource BusyAnimationStyle}" ToolTip="Connecting..."/>
</Viewbox>
</Setter.Value>
</Setter>
Expand Down

0 comments on commit 96f5cfe

Please sign in to comment.