Skip to content

Commit 96673d0

Browse files
authored
CMP-8068 Fix crash in getSystemEnvironment on headless desktop (#5471)
Fixes a crash in `getSystemEnvironment` on desktop when running in a headless environment (such as most CI runners) by providing a default density qualifier. In the future that might be something that's nice to make configurable, but since both our use case and the linked issue encountered it when calling `getString` I didn't worry about it too hard. Fixes [CMP-8068](https://youtrack.jetbrains.com/issue/CMP-8068) ## Testing Made a local build and used it to run some tests in another project that were failing on calls to `getString` ## Release Notes ### Fixes - Resources - Fix crash in `getSystemEnvironment` on headless desktop
1 parent 8c50bcb commit 96673d0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/resources/library/src/desktopMain/kotlin/org/jetbrains/compose/resources/ResourceEnvironment.desktop.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ package org.jetbrains.compose.resources
22

33
import org.jetbrains.skiko.SystemTheme
44
import org.jetbrains.skiko.currentSystemTheme
5+
import java.awt.GraphicsEnvironment
56
import java.awt.Toolkit
67
import java.util.*
78

89
internal actual fun getSystemEnvironment(): ResourceEnvironment {
910
val locale = Locale.getDefault()
1011
//FIXME: don't use skiko internals
1112
val isDarkTheme = currentSystemTheme == SystemTheme.DARK
12-
val dpi = Toolkit.getDefaultToolkit().screenResolution
13+
val dpi = if (GraphicsEnvironment.isHeadless()) {
14+
// Default to 1x ("unscaled") resources when DPI info not available
15+
DensityQualifier.MDPI.dpi
16+
} else {
17+
Toolkit.getDefaultToolkit().screenResolution
18+
}
1319
return ResourceEnvironment(
1420
language = LanguageQualifier(locale.language),
1521
region = RegionQualifier(locale.country),

0 commit comments

Comments
 (0)