Skip to content

Commit

Permalink
Updated logic for refreshing games when games added/taken away
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyeao committed Nov 27, 2023
1 parent fe84ef6 commit 814e9c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions HA-Game-SPy/GameAddWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ private async void AddGame_Click(object sender, RoutedEventArgs e)
games.Add(newGame); // Add the new game to the list

await SaveGamesAsync(games); // Save the updated games list
// After adding a game



}

// Event handler for the BrowseExecutable button click event
Expand Down Expand Up @@ -74,6 +78,9 @@ private async Task SaveGamesAsync(List<GameInfo> games)

string json = JsonConvert.SerializeObject(games, Formatting.Indented); // Using Formatting.Indented for readability
await File.WriteAllTextAsync(gamesFilePath, json);
// After adding a game


this.Close(); // Close the window after saving
}

Expand Down
1 change: 1 addition & 0 deletions HA-Game-SPy/GameListWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private void AddNewGame_Click(object sender, RoutedEventArgs e)
GameAddWindow addWindow = new GameAddWindow(); // Create a new instance of the GameAddWindow
addWindow.ShowDialog(); // Show the window as a dialog
LoadGames(); // Reload the games after adding a new game

}

// This method is called when the "Save Changes" button is clicked
Expand Down
4 changes: 2 additions & 2 deletions HA-Game-SPy/HA-Game-SPy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<RootNamespace>HA_Game_SPy</RootNamespace>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<AssemblyVersion>1.0.0.106</AssemblyVersion>
<FileVersion>1.0.0.106</FileVersion>
<AssemblyVersion>1.0.0.107</AssemblyVersion>
<FileVersion>1.0.0.107</FileVersion>
<ApplicationIcon>trans.ico</ApplicationIcon>
<PackageIcon>download.png</PackageIcon>
</PropertyGroup>
Expand Down
7 changes: 7 additions & 0 deletions HA-Game-SPy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ private void InitializeMqttPublishTimer()
mqttPublishTimer.AutoReset = true; // Reset the timer after it elapses
mqttPublishTimer.Enabled = true; // Enable the timer
}
public async Task RefreshGamesListAsync()
{
games = await LoadGamesAsync();
}

private void OnMqttPublishTimerElapsed(object sender, ElapsedEventArgs e)
{
if (mqttClientWrapper != null && mqttClientWrapper.IsConnected)
Expand All @@ -227,6 +232,7 @@ private void AddGame_Click(object sender, RoutedEventArgs e)

// Show the gameAddWindow as a modal dialog
gameAddWindow.ShowDialog();
_ = RefreshGamesListAsync();
}

//Event handler for the button click event to connect to MQTT server
Expand Down Expand Up @@ -340,6 +346,7 @@ private void ListGame_Click(object sender, RoutedEventArgs e)

// Show the game list window as a modal dialog
gameListWindow.ShowDialog();
_ = RefreshGamesListAsync();
}

private async Task<List<GameInfo>> LoadGamesAsync()
Expand Down

0 comments on commit 814e9c5

Please sign in to comment.