Skip to content

Commit

Permalink
Fixed link to be clickable, added it as a button
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Shaml committed Dec 30, 2024
1 parent 2451f47 commit 9b80442
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/faforever/client/game/GameRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Action> 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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.faforever.client.logging.analysis;

import java.util.Set;
import com.faforever.client.notification.Action;

public record AnalysisResult(Set<String> analysisMessages) {
import java.util.Collection;

public record AnalysisResult(Collection<String> analysisMessages, Collection<Action> actions) {
public boolean isOk() {
return null == analysisMessages || analysisMessages.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<String> analysisResult = new HashSet<>();
final Collection<String> analysisResult = new HashSet<>();
final Collection<Action> 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);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> results = result.analysisMessages();
Collection<String> results = result.analysisMessages();
assertTrue(results.contains(MINIMIZED_EXPECTED_TEXT));
assertTrue(results.contains(SOUND_EXPECTED_TEXT));
assertEquals(1, result.actions().size());
}

@Test
Expand All @@ -75,5 +76,6 @@ public void testAnalyzeLogContentsWhenNoRelevantTraces() {
AnalysisResult result = logAnalyzerService.analyzeLogContents(logContents);

assertTrue(result.analysisMessages().isEmpty());
assertTrue(result.actions().isEmpty());
}
}

0 comments on commit 9b80442

Please sign in to comment.