()
| 175 | * false and the Grove dialog won't show until the next session. |
| 176 | */ |
| 177 | export async function isQualifiedForGrove(): Promise<boolean> { |
| 178 | const session = getAuthRuntime().getCurrentSession() |
| 179 | if (!canUseGroveForSession(session)) { |
| 180 | return false |
| 181 | } |
| 182 | |
| 183 | const accountId = session.identity.accountUuid |
| 184 | if (!accountId) { |
| 185 | return false |
| 186 | } |
| 187 | |
| 188 | const globalConfig = getGlobalConfig() |
| 189 | const cachedEntry = globalConfig.groveConfigCache?.[accountId] |
| 190 | const now = Date.now() |
| 191 | |
| 192 | // No cache - trigger background fetch and return false (non-blocking) |
| 193 | // The Grove dialog won't show this session, but will next time if eligible |
| 194 | if (!cachedEntry) { |
| 195 | logForDebugging( |
| 196 | 'Grove: No cache, fetching config in background (dialog skipped this session)', |
| 197 | ) |
| 198 | void fetchAndStoreGroveConfig(accountId) |
| 199 | return false |
| 200 | } |
| 201 | |
| 202 | // Cache exists but is stale - return cached value and refresh in background |
| 203 | if (now - cachedEntry.timestamp > GROVE_CACHE_EXPIRATION_MS) { |
| 204 | logForDebugging( |
| 205 | 'Grove: Cache stale, returning cached data and refreshing in background', |
| 206 | ) |
| 207 | void fetchAndStoreGroveConfig(accountId) |
| 208 | return cachedEntry.grove_enabled |
| 209 | } |
| 210 | |
| 211 | // Cache is fresh - return it immediately |
| 212 | logForDebugging('Grove: Using fresh cached config') |
| 213 | return cachedEntry.grove_enabled |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Fetch Grove config from API and store in cache |
no test coverage detected