From 3e8efabadb9d051663940c01d2b8be52c6f87227 Mon Sep 17 00:00:00 2001 From: Dylan George Field Date: Sun, 20 Aug 2023 19:12:24 +1000 Subject: [PATCH] (fix): bug where isWorkingFromHome flag in log is incorrect --- src/wfh-log-wpf/MainWindow.xaml.cs | 41 ++++++++---------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/src/wfh-log-wpf/MainWindow.xaml.cs b/src/wfh-log-wpf/MainWindow.xaml.cs index cc09a75..aaf07d1 100644 --- a/src/wfh-log-wpf/MainWindow.xaml.cs +++ b/src/wfh-log-wpf/MainWindow.xaml.cs @@ -30,8 +30,6 @@ public MainWindow(LogWriter logger, HourlyTimer timer, WorkNetworkSettings setti InitializeComponent(); - // lvDataBinding.ItemsSource = logReader.GetAggregateLogs(); - Closing += MainWindow_Closing; var appDirectory = AppContext.BaseDirectory + "wfh-log.exe"; @@ -44,18 +42,7 @@ public MainWindow(LogWriter logger, HourlyTimer timer, WorkNetworkSettings setti ConnectedNetworkSsid.Text = currentNetwork; - if (_settings.WorkNetworks.Contains(currentNetwork.ToString())) - { - var message = "You are working from home"; - WorkFromHomeStatus.Text = message; - _logger.Log(isWorkingFromHome: true, currentNetwork); - } - else - { - var message = "You are not working from home"; - WorkFromHomeStatus.Text = message; - _logger.Log(isWorkingFromHome: false, currentNetwork); - } + Dispatch_IsWorkingFromHome_Message(_settings.WorkNetworks.Contains(currentNetwork.ToString())); timer.AddHandler(HandleTimer); } @@ -66,20 +53,7 @@ private void HandleTimer(object? source, ElapsedEventArgs e) Dispatcher.Invoke(() => ConnectedNetworkSsid.Text = currentNetwork.ToString()); - if (_settings.WorkNetworks.Contains(currentNetwork.ToString())) - { - var message = "You are working from home"; - Dispatcher.Invoke(() => WorkFromHomeStatus.Text = message); - _logger.Log(isWorkingFromHome: true, currentNetwork); - } - else - { - var message = "You are not working from home"; - Dispatcher.Invoke(() => WorkFromHomeStatus.Text = message); - _logger.Log(isWorkingFromHome: false, currentNetwork); - } - - + Dispatch_IsWorkingFromHome_Message(_settings.WorkNetworks.Contains(currentNetwork.ToString())); } private void SetWorkNetworkButton_Click(object? source, RoutedEventArgs args) @@ -96,12 +70,19 @@ private void SetWorkNetworkButton_Click(object? source, RoutedEventArgs args) File.WriteAllText(path + "\\" + filename, WorkNetworkTextbox.Text); _settings.SetWorkNetworks(WorkNetworkTextbox.Text); - // re-run + var currentNetwork = NetworkHelper.GetConnectedNetworkSsid(); Dispatcher.Invoke(() => ConnectedNetworkSsid.Text = currentNetwork); - if (_settings.WorkNetworks.Contains(currentNetwork.ToString())) + Dispatch_IsWorkingFromHome_Message(_settings.WorkNetworks.Contains(currentNetwork.ToString())); + } + + private void Dispatch_IsWorkingFromHome_Message(bool isWorkingFromHome) + { + var currentNetwork = NetworkHelper.GetConnectedNetworkSsid(); + + if (isWorkingFromHome) { var message = "You're at the office 🏢"; Dispatcher.Invoke(() => WorkFromHomeStatus.Text = message);