@@ -7,7 +7,6 @@ import com.fasterxml.jackson.module.kotlin.readValue
77import com.intellij.openapi.Disposable
88import com.intellij.openapi.application.ApplicationManager
99import com.intellij.openapi.components.PersistentStateComponent
10- import com.intellij.openapi.components.RoamingType
1110import com.intellij.openapi.components.Service
1211import com.intellij.openapi.components.State
1312import com.intellij.openapi.components.Storage
@@ -23,6 +22,7 @@ import software.aws.toolkits.core.utils.RemoteResolveParser
2322import software.aws.toolkits.core.utils.RemoteResource
2423import software.aws.toolkits.core.utils.error
2524import software.aws.toolkits.core.utils.getLogger
25+ import software.aws.toolkits.core.utils.warn
2626import software.aws.toolkits.jetbrains.core.DefaultRemoteResourceResolverProvider
2727import software.aws.toolkits.jetbrains.core.RemoteResourceResolverProvider
2828import 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(
0 commit comments