Search in sources :

Example 6 with Action

use of com.faforever.client.notification.Action in project downlords-faf-client by FAForever.

the class SettingsController method onLanguageSelected.

public void onLanguageSelected() {
    LocalizationPrefs localizationPrefs = preferencesService.getPreferences().getLocalization();
    if (Objects.equals(languageComboBox.getValue(), localizationPrefs.getLanguage())) {
        return;
    }
    log.debug("A new language was selected: {}", languageComboBox.getValue());
    localizationPrefs.setLanguage(languageComboBox.getValue());
    preferencesService.storeInBackground();
    notificationService.addNotification(new PersistentNotification(i18n.get("settings.languages.restart.message"), Severity.WARN, Collections.singletonList(new Action(i18n.get("settings.languages.restart"), event -> {
        Platform.exit();
    // FIXME reload application (stage & application context)
    }))));
}
Also used : UiService(com.faforever.client.theme.UiService) ChatColorMode(com.faforever.client.chat.ChatColorMode) ComboBox(javafx.scene.control.ComboBox) TextField(javafx.scene.control.TextField) UnitDataBaseType(com.faforever.client.preferences.Preferences.UnitDataBaseType) Theme(com.faforever.client.theme.Theme) Screen(javafx.stage.Screen) Platform(javafx.application.Platform) Objects(java.util.Objects) NumberStringConverter(javafx.util.converter.NumberStringConverter) Slf4j(lombok.extern.slf4j.Slf4j) Region(javafx.scene.layout.Region) ToggleButton(javafx.scene.control.ToggleButton) GameDirectoryChooseEvent(com.faforever.client.ui.preferences.event.GameDirectoryChooseEvent) Toggle(javafx.scene.control.Toggle) ToastPosition(com.faforever.client.preferences.ToastPosition) TimeInfo(com.faforever.client.preferences.TimeInfo) PreferencesService(com.faforever.client.preferences.PreferencesService) WeakChangeListener(javafx.beans.value.WeakChangeListener) FXCollections(javafx.collections.FXCollections) UserService(com.faforever.client.user.UserService) Bindings(javafx.beans.binding.Bindings) Scope(org.springframework.context.annotation.Scope) NumberFormat(java.text.NumberFormat) EventBus(com.google.common.eventbus.EventBus) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Preferences(com.faforever.client.preferences.Preferences) DEFAULT_THEME(com.faforever.client.theme.UiService.DEFAULT_THEME) StringListCell(com.faforever.client.fx.StringListCell) PasswordField(javafx.scene.control.PasswordField) Label(javafx.scene.control.Label) Controller(com.faforever.client.fx.Controller) Node(javafx.scene.Node) CheckBox(javafx.scene.control.CheckBox) Action(com.faforever.client.notification.Action) NotificationsPrefs(com.faforever.client.preferences.NotificationsPrefs) PersistentNotification(com.faforever.client.notification.PersistentNotification) PATH_STRING_CONVERTER(com.faforever.client.fx.JavaFxUtil.PATH_STRING_CONVERTER) ActionEvent(javafx.event.ActionEvent) ToggleGroup(javafx.scene.control.ToggleGroup) Component(org.springframework.stereotype.Component) LanguageInfo(com.faforever.client.preferences.LanguageInfo) Severity(com.faforever.client.notification.Severity) I18n(com.faforever.client.i18n.I18n) LocalizationPrefs(com.faforever.client.preferences.LocalizationPrefs) ChangeListener(javafx.beans.value.ChangeListener) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Collections(java.util.Collections) Action(com.faforever.client.notification.Action) LocalizationPrefs(com.faforever.client.preferences.LocalizationPrefs) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Example 7 with Action

use of com.faforever.client.notification.Action in project downlords-faf-client by FAForever.

the class ReplayServerImpl method start.

@Override
public CompletableFuture<Void> start(int gameId) {
    stoppedGracefully = false;
    CompletableFuture<Void> future = new CompletableFuture<>();
    new Thread(() -> {
        Integer localReplayServerPort = clientProperties.getReplay().getLocalServerPort();
        String remoteReplayServerHost = clientProperties.getReplay().getRemoteHost();
        Integer remoteReplayServerPort = clientProperties.getReplay().getRemotePort();
        log.debug("Opening local replay server on port {}", localReplayServerPort);
        log.debug("Connecting to replay server at '{}:{}'", remoteReplayServerHost, remoteReplayServerPort);
        try (ServerSocket localSocket = new ServerSocket(localReplayServerPort);
            Socket remoteReplayServerSocket = new Socket(remoteReplayServerHost, remoteReplayServerPort)) {
            this.serverSocket = localSocket;
            future.complete(null);
            recordAndRelay(gameId, localSocket, new BufferedOutputStream(remoteReplayServerSocket.getOutputStream()));
        } catch (ConnectException e) {
            // TODO record locally even though remote is down.
            log.warn("Could not connect to remote replay server", e);
            notificationService.addNotification(new PersistentNotification(i18n.get("replayServer.unreachable"), Severity.WARN));
            future.complete(null);
        } catch (IOException e) {
            if (stoppedGracefully) {
                return;
            }
            future.completeExceptionally(e);
            log.warn("Error in replay server", e);
            notificationService.addNotification(new PersistentNotification(i18n.get("replayServer.listeningFailed", localReplayServerPort), Severity.WARN, Collections.singletonList(new Action(i18n.get("replayServer.retry"), event -> start(gameId)))));
        }
    }).start();
    return future;
}
Also used : Socket(java.net.Socket) GameService(com.faforever.client.game.GameService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) UserService(com.faforever.client.user.UserService) BufferedOutputStream(java.io.BufferedOutputStream) Inject(javax.inject.Inject) ServerSocket(java.net.ServerSocket) NotificationService(com.faforever.client.notification.NotificationService) ClientUpdateService(com.faforever.client.update.ClientUpdateService) SocketException(java.net.SocketException) GameStatus(com.faforever.client.remote.domain.GameStatus) ConnectException(java.net.ConnectException) ClientProperties(com.faforever.client.config.ClientProperties) OutputStream(java.io.OutputStream) Action(com.faforever.client.notification.Action) IOException(java.io.IOException) PersistentNotification(com.faforever.client.notification.PersistentNotification) Bytes(com.google.common.primitives.Bytes) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) Severity(com.faforever.client.notification.Severity) Lazy(org.springframework.context.annotation.Lazy) I18n(com.faforever.client.i18n.I18n) Collections(java.util.Collections) NoCatch.noCatch(com.github.nocatch.NoCatch.noCatch) Game(com.faforever.client.game.Game) InputStream(java.io.InputStream) Action(com.faforever.client.notification.Action) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ConnectException(java.net.ConnectException) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Example 8 with Action

use of com.faforever.client.notification.Action in project downlords-faf-client by FAForever.

the class ClientUpdateServiceImpl method downloadAndInstallInBackground.

private void downloadAndInstallInBackground(UpdateInfo updateInfo) {
    DownloadUpdateTask task = applicationContext.getBean(DownloadUpdateTask.class);
    task.setUpdateInfo(updateInfo);
    taskService.submitTask(task).getFuture().thenAccept(this::install).exceptionally(throwable -> {
        logger.warn("Error while downloading client update", throwable);
        notificationService.addNotification(new PersistentNotification(i18n.get("clientUpdateDownloadFailed.notification"), WARN, singletonList(new Action(i18n.get("clientUpdateDownloadFailed.retry"), event -> downloadAndInstallInBackground(updateInfo)))));
        return null;
    });
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Collections.singletonList(java.util.Collections.singletonList) PlatformService(com.faforever.client.fx.PlatformService) Inject(javax.inject.Inject) NotificationService(com.faforever.client.notification.NotificationService) Service(org.springframework.stereotype.Service) WARN(com.faforever.client.notification.Severity.WARN) Arrays.asList(java.util.Arrays.asList) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) Path(java.nio.file.Path) FafClientApplication(com.faforever.client.FafClientApplication) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) INFO(com.faforever.client.notification.Severity.INFO) Action(com.faforever.client.notification.Action) IOException(java.io.IOException) ApplicationContext(org.springframework.context.ApplicationContext) Profile(org.springframework.context.annotation.Profile) PersistentNotification(com.faforever.client.notification.PersistentNotification) Bytes.formatSize(com.faforever.commons.io.Bytes.formatSize) StringUtils.defaultString(org.apache.commons.lang3.StringUtils.defaultString) Lazy(org.springframework.context.annotation.Lazy) VisibleForTesting(com.google.common.annotations.VisibleForTesting) I18n(com.faforever.client.i18n.I18n) TaskService(com.faforever.client.task.TaskService) Action(com.faforever.client.notification.Action) PersistentNotification(com.faforever.client.notification.PersistentNotification)

Aggregations

Action (com.faforever.client.notification.Action)8 I18n (com.faforever.client.i18n.I18n)7 NotificationService (com.faforever.client.notification.NotificationService)7 PersistentNotification (com.faforever.client.notification.PersistentNotification)7 Inject (javax.inject.Inject)7 Severity (com.faforever.client.notification.Severity)6 Collections (java.util.Collections)5 Lazy (org.springframework.context.annotation.Lazy)5 ImmediateNotification (com.faforever.client.notification.ImmediateNotification)4 EventBus (com.google.common.eventbus.EventBus)4 IOException (java.io.IOException)4 MethodHandles (java.lang.invoke.MethodHandles)4 Collections.singletonList (java.util.Collections.singletonList)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 ClientProperties (com.faforever.client.config.ClientProperties)3 PlatformService (com.faforever.client.fx.PlatformService)3 DismissAction (com.faforever.client.notification.DismissAction)3 ReportAction (com.faforever.client.notification.ReportAction)3