diff --git a/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt b/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt index cd02d330ae..7b71c283aa 100644 --- a/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt +++ b/gradle-plugins/preview-rpc/src/main/kotlin/org/jetbrains/compose/desktop/ui/tooling/preview/rpc/RemotePreviewHost.kt @@ -7,16 +7,12 @@ package org.jetbrains.compose.desktop.ui.tooling.preview.rpc import java.io.File import java.lang.RuntimeException -import java.lang.reflect.Method import java.net.SocketTimeoutException import java.net.URLClassLoader import java.util.concurrent.atomic.AtomicReference import kotlin.concurrent.thread import kotlin.system.exitProcess import kotlin.system.measureTimeMillis -import kotlin.time.DurationUnit -import kotlin.time.ExperimentalTime -import kotlin.time.measureTimedValue val PREVIEW_HOST_CLASS_NAME: String get() = PreviewHost::class.java.canonicalName @@ -111,6 +107,20 @@ internal class PreviewHost(private val log: PreviewLogger, connection: RemoteCon request: FrameRequest ): ByteArray { val classloader = classloaderProvider.getClassloader(classpath) + val thread = Thread.currentThread() + val prevContextClassloader = thread.contextClassLoader + thread.contextClassLoader = classloader + return try { + renderFrame(classloader, request) + } finally { + thread.contextClassLoader = prevContextClassloader + } + } + + private fun renderFrame( + classloader: ClassLoader, + request: FrameRequest + ): ByteArray { val previewFacade = classloader.loadClass(PREVIEW_FACADE_CLASS_NAME) val renderArgsClasses = arrayOf( String::class.java, diff --git a/idea-plugin/examples/simple-preview-example/build.gradle.kts b/idea-plugin/examples/simple-preview-example/build.gradle.kts index 2f642cb193..ab3325fc72 100644 --- a/idea-plugin/examples/simple-preview-example/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/build.gradle.kts @@ -6,9 +6,9 @@ buildscript { } dependencies { // __LATEST_COMPOSE_RELEASE_VERSION__ - classpath("org.jetbrains.compose:compose-gradle-plugin:1.0.0-alpha1") + classpath("org.jetbrains.compose:compose-gradle-plugin:0.0.9-preview-images") // __KOTLIN_COMPOSE_VERSION__ - classpath(kotlin("gradle-plugin", version = "1.5.21")) + classpath(kotlin("gradle-plugin", version = "1.5.31")) } } diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts index 4a21377d49..ca69c9a947 100644 --- a/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts +++ b/idea-plugin/examples/simple-preview-example/pure-jvm/build.gradle.kts @@ -7,4 +7,8 @@ plugins { dependencies { implementation(compose.desktop.currentOs) +} + +compose.desktop.application { + mainClass = "PreviewKt" } \ No newline at end of file diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt index 9c8d883b3e..dcc3252cb9 100644 --- a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt +++ b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/kotlin/preview.kt @@ -1,16 +1,38 @@ -import androidx.compose.material.Text -import androidx.compose.material.Button -import androidx.compose.runtime.* import androidx.compose.desktop.ui.tooling.preview.Preview +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.runtime.* +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.singleWindowApplication @Preview @Composable fun ExamplePreview() { var text by remember { mutableStateOf("Hello, World!") } - - Button(onClick = { - text = "Hello, Desktop!" - }) { - Text(text) + val buttonColors = ButtonDefaults.buttonColors( + backgroundColor = Color.Blue, + contentColor = Color.White + ) + Button( + colors = buttonColors, + modifier = Modifier.padding(5.dp), + onClick = { text = "Hello, Desktop!" } + ) { + Row { + Image( + painterResource("compose-logo-white.png"), + "compose-logo", + modifier = Modifier.height(32.dp).width(32.dp), + ) + Text(text, modifier = Modifier.padding(top = 8.dp, start = 5.dp)) + } } +} + +fun main() = singleWindowApplication { + ExamplePreview() } \ No newline at end of file diff --git a/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png new file mode 100644 index 0000000000..6f97412563 Binary files /dev/null and b/idea-plugin/examples/simple-preview-example/pure-jvm/src/main/resources/compose-logo-white.png differ