From 9b804424951be8db810f352441f7a2fecee33fb9 Mon Sep 17 00:00:00 2001 From: Ivan-Shaml <72102779+Ivan-Shaml@users.noreply.github.com> Date: Mon, 30 Dec 2024 23:14:13 +0200 Subject: [PATCH] Fixed link to be clickable, added it as a button --- .../com/faforever/client/game/GameRunner.java | 5 +++- .../logging/analysis/AnalysisResult.java | 6 +++-- .../logging/analysis/LogAnalyzerService.java | 18 +++++++++---- src/main/resources/i18n/messages.properties | 3 ++- .../analysis/LogAnalyzerServiceTest.java | 26 ++++++++++--------- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/faforever/client/game/GameRunner.java b/src/main/java/com/faforever/client/game/GameRunner.java index 1d43e165ac..7399afdfd7 100644 --- a/src/main/java/com/faforever/client/game/GameRunner.java +++ b/src/main/java/com/faforever/client/game/GameRunner.java @@ -65,6 +65,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -430,11 +431,13 @@ private void runLogAnalysis(String logContent) { final var analysisResult = logAnalyzerService.analyzeLogContents(logContent); if (!analysisResult.isOk()) { final StringBuilder message = new StringBuilder(); + final List actions = new ArrayList<>(analysisResult.actions()); + actions.add(new DismissAction(i18n)); analysisResult.analysisMessages().forEach(msg -> message.append(" - ").append(msg).append(System.lineSeparator())); notificationService.addNotification(new ImmediateNotification(i18n.get("game.log.analysis"), message.toString(), WARN, - List.of(new DismissAction(i18n)))); + actions)); } } diff --git a/src/main/java/com/faforever/client/logging/analysis/AnalysisResult.java b/src/main/java/com/faforever/client/logging/analysis/AnalysisResult.java index 9642aaa841..55f4e7a86f 100644 --- a/src/main/java/com/faforever/client/logging/analysis/AnalysisResult.java +++ b/src/main/java/com/faforever/client/logging/analysis/AnalysisResult.java @@ -1,8 +1,10 @@ package com.faforever.client.logging.analysis; -import java.util.Set; +import com.faforever.client.notification.Action; -public record AnalysisResult(Set analysisMessages) { +import java.util.Collection; + +public record AnalysisResult(Collection analysisMessages, Collection actions) { public boolean isOk() { return null == analysisMessages || analysisMessages.isEmpty(); } diff --git a/src/main/java/com/faforever/client/logging/analysis/LogAnalyzerService.java b/src/main/java/com/faforever/client/logging/analysis/LogAnalyzerService.java index 10991a2f3e..d23c7c00b5 100644 --- a/src/main/java/com/faforever/client/logging/analysis/LogAnalyzerService.java +++ b/src/main/java/com/faforever/client/logging/analysis/LogAnalyzerService.java @@ -1,14 +1,17 @@ package com.faforever.client.logging.analysis; import com.faforever.client.config.ClientProperties; +import com.faforever.client.fx.PlatformService; import com.faforever.client.i18n.I18n; +import com.faforever.client.notification.Action; import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; -import java.util.Set; @Service @RequiredArgsConstructor @@ -19,20 +22,25 @@ public class LogAnalyzerService { private final I18n i18n; private final ClientProperties clientProperties; + private final PlatformService platformService; @NotNull public AnalysisResult analyzeLogContents(final String logContents) { - final Set analysisResult = new HashSet<>(); + final Collection analysisResult = new HashSet<>(); + final Collection actions = new ArrayList<>(); if (StringUtils.contains(logContents, GAME_MINIMIZED_TRACE)) { analysisResult.add(i18n.get("game.log.analysis.minimized")); } if (StringUtils.contains(logContents, SND_WARNING_TRACE) && StringUtils.contains(logContents, SND_XACT_TRACE)) { - analysisResult.add(i18n.get("game.log.analysis.snd", - clientProperties.getLinks().get("linksSoundIssues"))); + final String moreInfoButtonCaption = i18n.get("game.log.analysis.moreInfo"); + analysisResult.add(i18n.get("game.log.analysis.snd", moreInfoButtonCaption)); + actions.add(new Action(moreInfoButtonCaption, + () -> platformService.showDocument(clientProperties.getLinks().get("linksSoundIssues")))); + } - return new AnalysisResult(analysisResult); + return new AnalysisResult(analysisResult, actions); } } diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index 1476d29788..13db4b83e7 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -1032,7 +1032,8 @@ findHelp = If this error continues use the Get Help button to open the help foru game.crash = It looks like Supreme Commander\: Forged Alliance crashed with exit code {0}. Check the game log {1} for more information. game.log.analysis = The logs from your game have been automatically analyzed, revealing the following issue(s): game.log.analysis.minimized = Minimizing the game or using Alt+Tab while it's in fullscreen mode may cause crashes. We recommend playing in windowed mode -game.log.analysis.snd = Certain operating system settings or third-party sound software can cause issues and game crashes. We recommend reviewing these tips: {0} +game.log.analysis.snd = Certain operating system settings or third-party sound software can cause issues and game crashes. For more information, please click the ''{0}'' button +game.log.analysis.moreInfo = More Information replayNotAvailable = Replay {0,number,#} is not yet available from the server. Please try again later. close = Close userMenu.moderationReport = Moderation reports diff --git a/src/test/java/com/faforever/client/logging/analysis/LogAnalyzerServiceTest.java b/src/test/java/com/faforever/client/logging/analysis/LogAnalyzerServiceTest.java index 03ad1f3132..a94f71400a 100644 --- a/src/test/java/com/faforever/client/logging/analysis/LogAnalyzerServiceTest.java +++ b/src/test/java/com/faforever/client/logging/analysis/LogAnalyzerServiceTest.java @@ -7,19 +7,17 @@ import org.mockito.InjectMocks; import org.mockito.Mock; -import java.util.Map; -import java.util.Set; +import java.util.Collection; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; - public class LogAnalyzerServiceTest extends ServiceTest { private static final String SOUND_EXPECTED_TEXT = "Sound issue detected"; private static final String MINIMIZED_EXPECTED_TEXT = "Game was minimized"; + private static final String MORE_INFO_BUTTON = "More Info"; @Mock private I18n i18n; @@ -34,38 +32,41 @@ public class LogAnalyzerServiceTest extends ServiceTest { public void testAnalyzeLogContentsWhenGameMinimizedTrace() { final String logContents = "info: Minimized true"; - when(i18n.get(anyString())).thenReturn(MINIMIZED_EXPECTED_TEXT); + when(i18n.get("game.log.analysis.minimized")).thenReturn(MINIMIZED_EXPECTED_TEXT); AnalysisResult result = logAnalyzerService.analyzeLogContents(logContents); assertTrue(result.analysisMessages().contains(MINIMIZED_EXPECTED_TEXT)); + assertTrue(result.actions().isEmpty()); } @Test public void testAnalyzeLogContentsWhenXactTrace() { final String logContents = "warning: SND\nXACT"; - when(i18n.get(anyString(), any())).thenReturn(SOUND_EXPECTED_TEXT); - when(clientProperties.getLinks()).thenReturn(Map.of()); + when(i18n.get("game.log.analysis.moreInfo")).thenReturn(MORE_INFO_BUTTON); + when(i18n.get("game.log.analysis.snd", MORE_INFO_BUTTON)).thenReturn(SOUND_EXPECTED_TEXT); AnalysisResult result = logAnalyzerService.analyzeLogContents(logContents); assertTrue(result.analysisMessages().contains(SOUND_EXPECTED_TEXT)); + assertEquals(1, result.actions().size()); } @Test public void testAnalyzeLogContentsWhenGameMinimizedAndXactTrace() { final String logContents = "info: Minimized true\nwarning: SND\nXACT"; - when(i18n.get(anyString())).thenReturn(MINIMIZED_EXPECTED_TEXT); - when(i18n.get(anyString(), any())).thenReturn(SOUND_EXPECTED_TEXT); - when(clientProperties.getLinks()).thenReturn(Map.of()); + when(i18n.get("game.log.analysis.minimized")).thenReturn(MINIMIZED_EXPECTED_TEXT); + when(i18n.get("game.log.analysis.moreInfo")).thenReturn(MORE_INFO_BUTTON); + when(i18n.get("game.log.analysis.snd", MORE_INFO_BUTTON)).thenReturn(SOUND_EXPECTED_TEXT); AnalysisResult result = logAnalyzerService.analyzeLogContents(logContents); - Set results = result.analysisMessages(); + Collection results = result.analysisMessages(); assertTrue(results.contains(MINIMIZED_EXPECTED_TEXT)); assertTrue(results.contains(SOUND_EXPECTED_TEXT)); + assertEquals(1, result.actions().size()); } @Test @@ -75,5 +76,6 @@ public void testAnalyzeLogContentsWhenNoRelevantTraces() { AnalysisResult result = logAnalyzerService.analyzeLogContents(logContents); assertTrue(result.analysisMessages().isEmpty()); + assertTrue(result.actions().isEmpty()); } }