diff --git a/skate-plugin/src/main/kotlin/com/slack/sgp/intellij/ui/WhatsNewPanelFactory.kt b/skate-plugin/src/main/kotlin/com/slack/sgp/intellij/ui/WhatsNewPanelFactory.kt index 661ff3fcb..1052c535c 100644 --- a/skate-plugin/src/main/kotlin/com/slack/sgp/intellij/ui/WhatsNewPanelFactory.kt +++ b/skate-plugin/src/main/kotlin/com/slack/sgp/intellij/ui/WhatsNewPanelFactory.kt @@ -18,6 +18,7 @@ package com.slack.sgp.intellij.ui import com.intellij.openapi.Disposable import com.intellij.openapi.application.runReadAction import com.intellij.openapi.components.service +import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.DumbAware import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer @@ -26,6 +27,12 @@ import com.intellij.testFramework.LightVirtualFile import com.intellij.ui.content.ContentFactory import com.intellij.ui.content.ContentManagerEvent import com.intellij.ui.content.ContentManagerListener +import com.intellij.ui.dsl.builder.panel +import com.intellij.ui.dsl.gridLayout.HorizontalAlign +import com.intellij.ui.dsl.gridLayout.VerticalAlign +import com.intellij.ui.jcef.JBCefApp +import com.intellij.util.ui.HtmlPanel +import com.intellij.util.ui.JBUI import com.slack.sgp.intellij.ChangelogJournal import com.slack.sgp.intellij.ChangelogParser import java.awt.BorderLayout @@ -71,6 +78,8 @@ class WhatsNewPanelFactory : DumbAware { parentDisposable: Disposable ) { + private val logger = logger() + // Actual panel box for "What's New in Slack!" val contentPanel: JPanel = JPanel().apply { @@ -91,15 +100,49 @@ class WhatsNewPanelFactory : DumbAware { val file = LightVirtualFile("changelog.md", changeLogContent.changeLogString ?: "") - val panel = MarkdownJCEFHtmlPanel(project, file) - Disposer.register(parentDisposable, panel) - val html = runReadAction { MarkdownUtil.generateMarkdownHtml(file, changeLogContent.changeLogString ?: "", project) } - panel.setHtml(html, 0) - return panel.component + // We have to support two different modes here: the modern JCEF-based one and the legacy + // Legacy is because Android Studio ships with a broken markdown plugin that doesn't work with + // JCEF + // https://issuetracker.google.com/issues/159933628#comment19 + val panel = + if (JBCefApp.isSupported()) { + logger.debug("Using JCEFHtmlPanelProvider") + MarkdownJCEFHtmlPanel(project, file) + .apply { + Disposer.register(parentDisposable, this) + setHtml(html, 0) + } + .component + } else { + logger.debug("Using HtmlPanel") + val htmlPanel = + object : HtmlPanel() { + init { + isVisible = true + // Padding + border = JBUI.Borders.empty(16) + update() + } + + override fun getBody(): String { + return html + } + } + panel { + row { + cell(htmlPanel) + .horizontalAlign(HorizontalAlign.FILL) + .verticalAlign(VerticalAlign.FILL) + } + .resizableRow() + } + } + + return panel } } }