Skip to content

Commit

Permalink
add notification if jcef didn't start
Browse files Browse the repository at this point in the history
  • Loading branch information
reymondzzzz committed Oct 27, 2024
1 parent 06b492f commit 11cf255
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/main/kotlin/com/smallcloud/refactai/Initializer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import com.intellij.openapi.startup.StartupActivity
import com.smallcloud.refactai.io.CloudMessageService
import com.smallcloud.refactai.listeners.UninstallListener
import com.smallcloud.refactai.lsp.LSPActiveDocNotifierService
import com.smallcloud.refactai.notifications.emitInfo
import com.smallcloud.refactai.notifications.notificationStartup
import com.smallcloud.refactai.panes.sharedchat.ChatPaneInvokeAction
import com.smallcloud.refactai.privacy.PrivacyService
import com.smallcloud.refactai.settings.AppSettingsState
import com.smallcloud.refactai.settings.settingsStartup
import com.smallcloud.refactai.utils.isJcefCanStart
import java.util.concurrent.atomic.AtomicBoolean
import com.smallcloud.refactai.lsp.LSPProcessHolder.Companion.getInstance as getLSPProcessHolder

Expand All @@ -32,6 +34,9 @@ class Initializer : StartupActivity, Disposable {
PluginInstaller.addStateListener(UninstallListener())
UpdateChecker.instance
ApplicationManager.getApplication().getService(CloudMessageService::class.java)
if (!isJcefCanStart()) {
emitInfo(RefactAIBundle.message("notifications.chatCanNotStartWarning"), false)
}
}
getLSPProcessHolder(project)
project.getService(LSPActiveDocNotifierService::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ fun emitInfo(msg: String, needToDeleteLast: Boolean = true) {
if (needToDeleteLast) removeLastNotification()
val project = getLastUsedProject()
val notification = NotificationGroupManager.getInstance().getNotificationGroup("Refact AI Notification Group")
.createNotification(Resources.titleStr, msg, NotificationType.INFORMATION)
.createNotification(Resources.titleStr, msg, NotificationType.INFORMATION).setListener(object : Adapter() {
override fun hyperlinkActivated(notification: Notification, event: HyperlinkEvent) {
val url: URL = event.url
BrowserUtil.browse(url)
notification.expire()
}
})
notification.icon = Resources.Icons.LOGO_RED_16x16

notification.addAction(NotificationAction.createSimple(RefactAIBundle.message("notifications.settingsAndPrivacy")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import com.intellij.openapi.wm.ToolWindowFactory
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.ui.content.Content
import com.intellij.ui.content.ContentFactory
import com.intellij.ui.jcef.JBCefApp
import com.smallcloud.refactai.Resources
import com.smallcloud.refactai.panes.sharedchat.ChatPanes
import com.smallcloud.refactai.utils.getLastUsedProject
import com.smallcloud.refactai.utils.isJcefCanStart


class RefactAIToolboxPaneFactory : ToolWindowFactory {
Expand All @@ -20,15 +20,7 @@ class RefactAIToolboxPaneFactory : ToolWindowFactory {
super.init(toolWindow)
}

override fun isApplicable(project: Project): Boolean {
return try {
JBCefApp.isSupported() && JBCefApp.isStarted()
JBCefApp.isSupported()
} catch (_: Exception) {
false
}
}

override fun isApplicable(project: Project): Boolean = isJcefCanStart()

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
val contentFactory = ContentFactory.getInstance()
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/com/smallcloud/refactai/utils/JCefUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.smallcloud.refactai.utils

import com.intellij.ui.jcef.JBCefApp

fun isJcefCanStart(): Boolean {
return try {
JBCefApp.isSupported() && JBCefApp.isStarted()
JBCefApp.isSupported()
} catch (_: Exception) {
false
}
}
1 change: 1 addition & 0 deletions src/main/resources/bundles/RefactAI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ statusBar.notificationAstVecdbLimitMsg=AST or VecDB file number limit reached, y

errorReport.actionText=Open GitHub Issue
notifications.embeddedWarning=You may have noticed Refact.ai is slower in version 2024.2. We're sorry! The fix is in 2024.3, so please upgrade when it's available!
notifications.chatCanNotStartWarning=<html>The chat feature could not start in your JetBrains IDE. Please refer to the <a href="https://docs.refact.ai/guides/plugins/jetbrains/troubleshooting/">documentation</a> for setup and troubleshooting steps.</html>

0 comments on commit 11cf255

Please sign in to comment.