Skip to content

Commit

Permalink
Fixes #2158
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Feb 22, 2021
1 parent 22b0a81 commit 912afca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/faforever/client/game/GameService.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ private void onGameInfo(GameInfoMessage gameInfoMessage) {
private Game createOrUpdateGame(GameInfoMessage gameInfoMessage) {
JavaFxUtil.assertApplicationThread();
Integer gameId = gameInfoMessage.getUid();
log.debug("Updating Game {}", gameId);
final Game game;
synchronized (uidToGameInfoBean) {
if (!uidToGameInfoBean.containsKey(gameId)) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/faforever/client/main/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ public Pane getRoot() {
}

public void onNavigateButtonClicked(ActionEvent event) {
eventBus.post(new NavigateEvent((NavigationItem) ((Node) event.getSource()).getUserData()));
NavigateEvent navigateEvent = new NavigateEvent((NavigationItem) ((Node) event.getSource()).getUserData());
log.debug("Navigating to {}", navigateEvent.getItem().toString());
eventBus.post(navigateEvent);
}

@Subscribe
Expand Down
36 changes: 21 additions & 15 deletions src/main/java/com/faforever/client/theme/UiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.cache.CacheManager;
Expand All @@ -44,7 +43,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.URL;
Expand Down Expand Up @@ -78,6 +76,7 @@

@Lazy
@Service
@Slf4j
public class UiService implements InitializingBean, DisposableBean {

public static final String UNKNOWN_MAP_IMAGE = "theme/images/unknown_map.png";
Expand Down Expand Up @@ -116,7 +115,6 @@ public class UiService implements InitializingBean, DisposableBean {

public static Theme DEFAULT_THEME = new Theme("Default", "Downlord", 1, "1");

private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
/**
* This value needs to be updated whenever theme-breaking changes were made to the client.
*/
Expand Down Expand Up @@ -178,7 +176,7 @@ public void afterPropertiesSet() throws IOException {
if (themesByFolderName.containsKey(storedTheme)) {
setTheme(themesByFolderName.get(storedTheme));
} else {
logger.warn("Selected theme was not found in folder {}, falling back to default.", storedTheme);
log.warn("Selected theme was not found in folder {}, falling back to default.", storedTheme);
setTheme(DEFAULT_THEME);
}

Expand All @@ -191,7 +189,7 @@ private void deleteStylesheetsCacheDirectory() {
try {
deleteRecursively(cacheStylesheetsDirectory);
} catch (IOException e) {
logger.warn("Missing permission to delete style sheets cache directory '{}'", cacheStylesheetsDirectory);
log.warn("Missing permission to delete style sheets cache directory '{}'", cacheStylesheetsDirectory);
}
}
}
Expand All @@ -206,7 +204,7 @@ private void startWatchService(Path themesDirectory) throws IOException {
key.reset();
}
} catch (InterruptedException | ClosedWatchServiceException e) {
logger.debug("Watcher service terminated");
log.debug("Watcher service terminated");
}
});
}
Expand All @@ -221,7 +219,7 @@ private void addThemeDirectory(Path path) {
String folderName = path.getFileName().toString();
themesByFolderName.put(folderName, readTheme(reader));
} catch (IOException e) {
logger.warn("Theme could not be read: " + metadataFile.toAbsolutePath(), e);
log.warn("Theme could not be read: " + metadataFile.toAbsolutePath(), e);
}
}

Expand All @@ -247,7 +245,7 @@ private void stopWatchingOldThemes() {
*/
private void watchTheme(Theme theme) {
Path themePath = getThemeDirectory(theme);
logger.debug("Watching theme directory for changes: {}", themePath.toAbsolutePath());
log.debug("Watching theme directory for changes: {}", themePath.toAbsolutePath());
noCatch(() -> Files.walkFileTree(themePath, new DirectoryVisitor(path -> watchDirectory(themePath, watchService))));
}

Expand All @@ -264,7 +262,7 @@ private void onWatchEvent(WatchKey key) {
//When replacing a theme file sometimes it is deleted and added again a few milli seconds later.
Thread.sleep(1000);
} catch (InterruptedException e) {
logger.info("Watch thread was interrupted");
log.info("Watch thread was interrupted");
}
reloadStylesheet();
}
Expand All @@ -273,14 +271,14 @@ private void watchDirectory(Path directory, WatchService watchService) {
if (watchKeys.containsKey(directory)) {
return;
}
logger.debug("Watching directory: {}", directory.toAbsolutePath());
log.debug("Watching directory: {}", directory.toAbsolutePath());
noCatch(() -> watchKeys.put(directory, directory.register(watchService, ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE)));
}

private void reloadStylesheet() {
String[] styleSheets = getStylesheets();

logger.debug("Changes detected, reloading stylesheets: {}", styleSheets);
log.debug("Changes detected, reloading stylesheets: {}", styleSheets);
scenes.forEach(scene -> setSceneStyleSheet(scene, styleSheets));
loadWebViewsStyleSheet(getWebViewStyleSheet());
}
Expand Down Expand Up @@ -414,25 +412,33 @@ public ReadOnlyObjectProperty<Theme> currentThemeProperty() {
* context, so its scope (which should always be "prototype") depends on the bean definition.
*/
public <T extends Controller<?>> T loadFxml(String relativePath) {
log.debug("Loading fxml {}", relativePath);
FXMLLoader loader = new FXMLLoader();
loader.setControllerFactory(applicationContext::getBean);
loader.setLocation(getThemeFileUrl(relativePath));
loader.setResources(resources);
noCatch((NoCatchRunnable) loader::load);
return loader.getController();
T controller = loader.getController();
log.debug("fxml {} loaded successfully controller class is {}", relativePath, controller.getClass().getSimpleName());
return controller;
}

public <T extends Controller<?>> T loadFxml(String relativePath, Class<?> controllerClass) {
log.debug("Loading Fxml {} with class {}", relativePath, controllerClass.getSimpleName());
FXMLLoader loader = new FXMLLoader();
loader.setControllerFactory(applicationContext::getBean);
loader.setController(applicationContext.getBean(controllerClass));
loader.setLocation(getThemeFileUrl(relativePath));
loader.setResources(resources);
noCatch((NoCatchRunnable) loader::load);
return loader.getController();
T controller = loader.getController();
log.debug("Fxml {} with class {} loaded successfully controller class is {}", relativePath, controllerClass.getSimpleName(),
controller.getClass().getSimpleName());
return controller;
}

private Path getThemeDirectory(Theme theme) {
log.debug("Retrieving Theme {}", theme.getDisplayName());
return preferencesService.getThemesDirectory().resolve(folderNamesByTheme.get(theme));
}

Expand Down Expand Up @@ -463,7 +469,7 @@ private void loadWebViewsStyleSheet(String styleSheetUrl) {
.filter(Objects::nonNull)
.forEach(webView -> JavaFxUtil.runLater(
() -> webView.getEngine().setUserStyleSheetLocation(noCatch(() -> currentTempStyleSheet.toUri().toURL()).toString())));
logger.debug("{} created and applied to all web views", newTempStyleSheet.getFileName());
log.debug("{} created and applied to all web views", newTempStyleSheet.getFileName());
}

public Scene createScene(Parent root) {
Expand Down

0 comments on commit 912afca

Please sign in to comment.