[tips] IDEA-334349 Do not show Tips of the Day if there are suggestion type notifications on screen

GitOrigin-RevId: f4cc01edb1b3dde3502f420b3d36848c6116702d
This commit is contained in:
Yuriy Artamonov
2023-10-08 12:43:36 +02:00
committed by intellij-monorepo-bot
parent 44d2761c6c
commit 2d09ac3f5c
3 changed files with 44 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ import com.intellij.ui.scale.JBUIScale
import com.intellij.util.Alarm
import com.intellij.util.text.DateFormatUtil
import com.intellij.util.ui.*
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.Nls
import java.awt.*
import java.awt.event.*
@@ -105,6 +106,18 @@ internal class NotificationsToolWindowFactory : ToolWindowFactory, DumbAware {
}
}
@ApiStatus.Internal
object NotificationsStateWatcher {
fun hasNotifications(project: Project): Boolean {
return !NotificationsToolWindowFactory.myModel.getNotifications(project).isEmpty()
}
fun hasSuggestionNotifications(project: Project): Boolean {
val notifications = NotificationsToolWindowFactory.myModel.getNotifications(project)
return notifications.any { it.isSuggestionType }
}
}
@JvmRecord
data class StatusMessage(val notification: Notification, val text: @NlsContexts.StatusBarText String, val stamp: Long)
@@ -319,6 +332,10 @@ internal class NotificationContent(val project: Project,
}
}
fun hasSuggestions(): Boolean {
return !suggestions.isEmpty()
}
private fun remove(notification: Notification) {
if (notification.isSuggestionType) {
suggestions.remove(notification)

View File

@@ -4,7 +4,9 @@
</extensionPoints>
<extensions defaultExtensionNs="com.intellij">
<backgroundPostStartupActivity id="TipOfTheDayActivity" implementation="com.intellij.ide.TipOfTheDayStartupActivity"/>
<backgroundPostStartupActivity id="TipOfTheDayActivity"
implementation="com.intellij.ide.TipOfTheDayStartupActivity"
order="last"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.ide.TipsOfTheDayUsagesCollector"/>
<statistics.validation.customValidationRule implementation="com.intellij.ide.TipsOfTheDayUsagesCollector$TipInfoValidationRule"/>

View File

@@ -2,18 +2,23 @@
package com.intellij.ide
import com.intellij.ide.util.TipAndTrickManager
import com.intellij.notification.impl.NotificationsStateWatcher
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.serviceAsync
import com.intellij.openapi.diagnostic.thisLogger
import com.intellij.openapi.extensions.ExtensionNotApplicableException
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.ProjectActivity
import com.intellij.openapi.wm.IdeFrame
import com.intellij.openapi.wm.ToolWindowManager
import com.intellij.openapi.wm.WindowManager
import com.intellij.util.PlatformUtils
import kotlinx.coroutines.suspendCancellableCoroutine
private class TipOfTheDayStartupActivity : ProjectActivity {
init {
if (ApplicationManager.getApplication().isHeadlessEnvironment ||
ApplicationManager.getApplication().isUnitTestMode ||
PlatformUtils.isRider() ||
!GeneralSettings.getInstance().isShowTipsOnStartup) {
throw ExtensionNotApplicableException.create()
@@ -21,12 +26,31 @@ private class TipOfTheDayStartupActivity : ProjectActivity {
}
override suspend fun execute(project: Project) {
awaitToolwindowManager(project)
val tipManager = serviceAsync<TipAndTrickManager>()
if (tipManager.canShowDialogAutomaticallyNow(project)
&& !hasSuggestionNotifications(project)
// prevent tip dialog showing when any popup already open
&& WindowManager.getInstance().mostRecentFocusedWindow is IdeFrame) {
TipsOfTheDayUsagesCollector.triggerDialogShown(TipsOfTheDayUsagesCollector.DialogType.automatically)
tipManager.showTipDialog(project)
}
}
private suspend fun awaitToolwindowManager(project: Project) {
return suspendCancellableCoroutine { continuation ->
ToolWindowManager.getInstance(project).invokeLater(Runnable {
continuation.resumeWith(Result.success(Unit))
})
}
}
private fun hasSuggestionNotifications(project: Project): Boolean {
val hasSuggestions = NotificationsStateWatcher.hasSuggestionNotifications(project)
if (hasSuggestions) {
thisLogger().info("Skipping Tip-Of-The-Day because there are suggestion notifications shown")
}
return hasSuggestions
}
}