From e9858352253753990896d9cfd7c5fd6e2aef12d9 Mon Sep 17 00:00:00 2001 From: Jonathan Lermitage Date: Sun, 31 Dec 2023 18:26:29 +0100 Subject: [PATCH] fix #175 JBUIScale.sysScale may fail at startup --- .../extra/icons/cfg/services/SettingsService.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/lermitage/intellij/extra/icons/cfg/services/SettingsService.java b/src/main/java/lermitage/intellij/extra/icons/cfg/services/SettingsService.java index a757cc0a..5554ab95 100644 --- a/src/main/java/lermitage/intellij/extra/icons/cfg/services/SettingsService.java +++ b/src/main/java/lermitage/intellij/extra/icons/cfg/services/SettingsService.java @@ -4,11 +4,13 @@ import com.intellij.notification.NotificationGroupManager; import com.intellij.notification.NotificationType; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.ui.scale.JBUIScale; import lermitage.intellij.extra.icons.ExtraIconProvider; import lermitage.intellij.extra.icons.Globals; import lermitage.intellij.extra.icons.Model; import lermitage.intellij.extra.icons.utils.I18nUtils; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import java.text.MessageFormat; @@ -33,7 +35,18 @@ public abstract class SettingsService { private static final ResourceBundle i18n = I18nUtils.getResourceBundle(); - public static final double DEFAULT_ADDITIONAL_UI_SCALE = JBUIScale.sysScale(); // TODO see what fits best: JBUIScale.sysScale or JBUI.pixScale. JBUI.pixScale can take a frame, which may be useful with multiple displays + private static final @NonNls Logger LOGGER = Logger.getInstance(SettingsService.class); + + public static final double DEFAULT_ADDITIONAL_UI_SCALE = findSysScale(); // TODO see what fits best: JBUIScale.sysScale or JBUI.pixScale. JBUI.pixScale can take a frame, which may be useful with multiple displays + + private static double findSysScale() { + try { + return JBUIScale.sysScale(); + } catch (Throwable t) { + LOGGER.warn(t); + return 1; + } + } public List getDisabledModelIds() { if (disabledModelIds == null) { // a malformed xml file could make it null