Skip to content

Commit

Permalink
Added a timer until next website check (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Dec 11, 2021
1 parent 5d87c29 commit edae1cb
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
8 changes: 7 additions & 1 deletion InternetTest/InternetTest/Pages/DownDetectorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<CheckBox Margin="0 10 0 2" x:Name="AutoCheckWebsiteDownChk" Style="{DynamicResource CheckBoxStyle1}" Content="{x:Static lang:Resources.AutoCheckEverySecondsWebsiteDown}" BorderThickness="3" Foreground="{Binding Source={StaticResource Foreground1}}" FontSize="14" VerticalContentAlignment="Center" Unchecked="AutoCheckWebsiteDownChk_Checked" Checked="AutoCheckWebsiteDownChk_Checked"/>

<StackPanel Orientation="Horizontal" Grid.Row="1">
<TextBlock Text="{x:Static lang:Resources.CheckEveryXSeconds}" VerticalAlignment="Center" Margin="0,0,10,0" Foreground="{Binding Source={StaticResource Foreground1}}"/>
<TextBox x:Name="SecondsTxt" Style="{DynamicResource TextBoxStyle1}" Padding="3" Margin="0,5,10,5" Width="50" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}" Foreground="{Binding Source={StaticResource Foreground1}}" VerticalAlignment="Center" PreviewTextInput="SecondsTxt_PreviewTextInput"/>
<TextBox x:Name="SecondsTxt" Text="30" Style="{DynamicResource TextBoxStyle1}" Padding="3" Margin="0,5,10,5" Width="50" Background="{x:Null}" BorderBrush="{Binding Source={StaticResource AccentColor}}" SelectionBrush="{Binding Source={StaticResource AccentColor}}" CaretBrush="{Binding Source={StaticResource Foreground1}}" Foreground="{Binding Source={StaticResource Foreground1}}" VerticalAlignment="Center" PreviewTextInput="SecondsTxt_PreviewTextInput"/>
<TextBlock Text="{x:Static lang:Resources.SecondsDotM}" VerticalAlignment="Center" Margin="0,0,0,0" Foreground="{Binding Source={StaticResource Foreground1}}"/>
</StackPanel>

<StackPanel Grid.Row="2" HorizontalAlignment="Center">
<TextBlock Text="&#xF2E2;" FontSize="80" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Foreground="{Binding Source={StaticResource Gray}}" HorizontalAlignment="Center"/>
<TextBlock x:Name="NextCheckTxt" Text="{x:Static lang:Resources.NoNextCheck}" FontWeight="Bold" Foreground="{Binding Source={StaticResource Foreground1}}" HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</StackPanel>
</Grid>
Expand Down
24 changes: 24 additions & 0 deletions InternetTest/InternetTest/Pages/DownDetectorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ namespace InternetTest.Pages
public partial class DownDetectorPage : Page
{
DispatcherTimer dispatcherTimer = new();
DispatcherTimer secondsTimer = new();
int secondsCheckTime = 30;
int updateS = 0;

public DownDetectorPage()
{
InitializeComponent();
InitUI();
}

private void InitUI()
{
HistoryBtn.Visibility = Visibility.Collapsed; // Set visibility
StatusBorder.Visibility = Visibility.Collapsed; // Hide

secondsTimer.Interval = TimeSpan.FromSeconds(1); // Every second

dispatcherTimer.Tick += (o, e) =>
{
if (string.IsNullOrEmpty(WebsiteTxt.Text))
Expand All @@ -59,6 +69,13 @@ public DownDetectorPage()
WebsiteTxt.Text = FormatURL(WebsiteTxt.Text);
Test(WebsiteTxt.Text);
};

secondsTimer.Tick += (o, e) =>
{
updateS--;
if (updateS < 0) updateS = secondsCheckTime - 1;
NextCheckTxt.Text = $"{Properties.Resources.NextCheck} {updateS} {Properties.Resources.SecondsDotM}";
};
}

/// <summary>
Expand Down Expand Up @@ -228,13 +245,20 @@ private void AutoCheckWebsiteDownChk_Checked(object sender, RoutedEventArgs e)
AutoCheckWebsiteDownChk.IsChecked = false;
return;
}
secondsCheckTime = seconds;
updateS = seconds;

dispatcherTimer.Interval = TimeSpan.FromSeconds(seconds);
dispatcherTimer.Start(); // Start the task
secondsTimer.Start(); // Start the task
SecondsTxt.IsEnabled = false;
}
else
{
dispatcherTimer.Stop();
secondsTimer.Stop();
NextCheckTxt.Text = Properties.Resources.NoNextCheck;
SecondsTxt.IsEnabled = true;
}
}
catch (Exception ex)
Expand Down
9 changes: 9 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,7 @@
<data name="PleaseSpecifyWebsiteCheck" xml:space="preserve">
<value>Please specify a website to check.</value>
</data>
<data name="NoNextCheck" xml:space="preserve">
<value>No next check</value>
</data>
</root>
3 changes: 3 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -408,4 +408,7 @@
<data name="PleaseSpecifyWebsiteCheck" xml:space="preserve">
<value>Veuillez spécifier un site web à vérifier.</value>
</data>
<data name="NoNextCheck" xml:space="preserve">
<value>Pas de prochaine vérification</value>
</data>
</root>
3 changes: 3 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -388,4 +388,7 @@
<data name="PleaseSpecifyWebsiteCheck" xml:space="preserve">
<value>Please specify a website to check.</value>
</data>
<data name="NoNextCheck" xml:space="preserve">
<value>No next check</value>
</data>
</root>

0 comments on commit edae1cb

Please sign in to comment.