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