Skip to content

Commit f04da83

Browse files
committed
feedback fixes
1 parent cc02c33 commit f04da83

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/notifications/NotificationPollingService.kt

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.fasterxml.jackson.module.kotlin.readValue
77
import com.intellij.openapi.Disposable
88
import com.intellij.openapi.application.ApplicationManager
99
import com.intellij.openapi.components.PersistentStateComponent
10-
import com.intellij.openapi.components.RoamingType
1110
import com.intellij.openapi.components.Service
1211
import com.intellij.openapi.components.State
1312
import com.intellij.openapi.components.Storage
@@ -23,6 +22,7 @@ import software.aws.toolkits.core.utils.RemoteResolveParser
2322
import software.aws.toolkits.core.utils.RemoteResource
2423
import software.aws.toolkits.core.utils.error
2524
import software.aws.toolkits.core.utils.getLogger
25+
import software.aws.toolkits.core.utils.warn
2626
import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
2727
import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
2828
import software.aws.toolkits.telemetry.Component
@@ -45,23 +45,34 @@ object NotificationFileValidator : RemoteResolveParser {
4545
}
4646
}
4747

48-
@State(name = "NotificationETagState", storages = [Storage("aws.xml", roamingType = RoamingType.DISABLED)])
49-
object ETagState : PersistentStateComponent<ETagState.State> {
50-
data class State(
51-
var etag: String? = null,
52-
)
48+
@State(name = "notificationEtag", storages = [Storage("aws.xml")])
49+
class NotificationEtagState : PersistentStateComponent<NotificationEtagConfiguration> {
50+
private var state = NotificationEtagConfiguration()
5351

54-
private var myState = State()
52+
override fun getState(): NotificationEtagConfiguration? = state
5553

56-
override fun getState(): State = myState
54+
override fun loadState(state: NotificationEtagConfiguration) {
55+
this.state = state
56+
}
57+
58+
var etag: String?
59+
get() = state.etag
60+
set(value) {
61+
state.etag = value
62+
}
5763

58-
override fun loadState(state: State) {
59-
myState = state
64+
companion object {
65+
fun getInstance(): NotificationEtagState =
66+
ApplicationManager.getApplication().getService(NotificationEtagState::class.java)
6067
}
6168
}
6269

70+
data class NotificationEtagConfiguration(
71+
var etag: String? = null,
72+
)
73+
6374
@Service(Service.Level.APP)
64-
class NotificationPollingService : Disposable {
75+
internal final class NotificationPollingService : Disposable {
6576
private val firstPollDone = AtomicBoolean(false)
6677
private val observers = mutableListOf<() -> Unit>()
6778
private val alarm = AlarmFactory.getInstance().create(Alarm.ThreadToUse.POOLED_THREAD, this)
@@ -96,7 +107,8 @@ class NotificationPollingService : Disposable {
96107
while (retryCount < MAX_RETRIES) {
97108
try {
98109
val newETag = getNotificationETag()
99-
if (newETag == ETagState.getState().etag) {
110+
if (newETag == NotificationEtagState.getInstance().etag) {
111+
// when there are notifications that may need to be shown on startup, but no new file was fetched
100112
if (firstPollDone.compareAndSet(false, true)) {
101113
notifyObservers()
102114
}
@@ -106,7 +118,7 @@ class NotificationPollingService : Disposable {
106118
.resolve(notificationsResource)
107119
.toCompletableFuture()
108120
.get()
109-
ETagState.getState().etag = newETag
121+
NotificationEtagState.getInstance().etag = newETag
110122
return true
111123
} catch (e: Exception) {
112124
lastException = e
@@ -125,11 +137,16 @@ class NotificationPollingService : Disposable {
125137
}
126138

127139
private fun getNotificationETag(): String =
128-
HttpRequests.request(NOTIFICATION_ENDPOINT)
129-
.userAgent("AWS Toolkit for JetBrains")
130-
.connect { request ->
131-
request.connection.headerFields["ETag"]?.firstOrNull().orEmpty()
132-
}
140+
try {
141+
HttpRequests.request(NOTIFICATION_ENDPOINT)
142+
.userAgent("AWS Toolkit for JetBrains")
143+
.connect { request ->
144+
request.connection.headerFields["ETag"]?.firstOrNull().orEmpty()
145+
}
146+
} catch (e: Exception) {
147+
LOG.warn { "Failed to fetch notification ETag: $e.message" }
148+
throw e
149+
}
133150

134151
private fun emitFailureMetric(e: Exception?) {
135152
ToolkitTelemetry.showNotification(

plugins/core/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
<extensions defaultExtensionNs="com.intellij">
2222
<!-- each plugin needs its own instance of these -->
23+
<applicationService serviceImplementation="software.aws.toolkits.jetbrains.core.notifications.NotificationEtagState"/>
2324
<applicationService serviceImplementation="migration.software.aws.toolkits.jetbrains.core.coroutines.PluginCoroutineScopeTracker"/>
2425
<projectService serviceImplementation="migration.software.aws.toolkits.jetbrains.core.coroutines.PluginCoroutineScopeTracker"/>
2526
<postStartupActivity implementation = "software.aws.toolkits.jetbrains.core.notifications.NotificationServiceInitializer"/>

0 commit comments

Comments
 (0)