Skip to content

Commit

Permalink
(fix): bug where isWorkingFromHome flag in log is incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-george-field committed Aug 20, 2023
1 parent 6f4b4ec commit 3e8efab
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions src/wfh-log-wpf/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 3e8efab

Please sign in to comment.