()
| 81 | * This runs in the background and doesn't block the UI |
| 82 | */ |
| 83 | export async function fetchAndStoreChangelog(): Promise<void> { |
| 84 | // Skip in noninteractive mode |
| 85 | if (getIsNonInteractiveSession()) { |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | // Skip network requests if nonessential traffic is disabled |
| 90 | if (isEssentialTrafficOnly()) { |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | const response = await axios.get(RAW_CHANGELOG_URL) |
| 95 | if (response.status === 200) { |
| 96 | const changelogContent = response.data |
| 97 | |
| 98 | // Skip write if content unchanged — writing Date.now() defeats the |
| 99 | // dirty-check in saveGlobalConfig since the timestamp always differs. |
| 100 | if (changelogContent === changelogMemoryCache) { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | const cachePath = getChangelogCachePath() |
| 105 | |
| 106 | // Ensure cache directory exists |
| 107 | await mkdir(dirname(cachePath), { recursive: true }) |
| 108 | |
| 109 | // Write changelog to cache file |
| 110 | await writeFile(cachePath, changelogContent, { encoding: 'utf-8' }) |
| 111 | changelogMemoryCache = changelogContent |
| 112 | |
| 113 | // Update timestamp in config |
| 114 | const changelogLastFetched = Date.now() |
| 115 | saveGlobalConfig(current => ({ |
| 116 | ...current, |
| 117 | changelogLastFetched, |
| 118 | })) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get the stored changelog from cache file if available. |
no test coverage detected