()
| 20 | type Stored = { distinctId: string; firstRunNoticeShown?: boolean }; |
| 21 | |
| 22 | function loadOrCreateState() { |
| 23 | const file = path.join(configDir(), "telemetry.json"); |
| 24 | try { |
| 25 | const raw = JSON.parse(fs.readFileSync(file, "utf8")) as Stored; |
| 26 | return { |
| 27 | distinctId: raw.distinctId, |
| 28 | isFirstRun: !raw.firstRunNoticeShown, |
| 29 | persist: () => writeState(file, { ...raw, firstRunNoticeShown: true }), |
| 30 | }; |
| 31 | } catch { |
| 32 | /* missing/corrupt → create */ |
| 33 | } |
| 34 | const fresh: Stored = { distinctId: crypto.randomUUID(), firstRunNoticeShown: false }; |
| 35 | return { |
| 36 | distinctId: fresh.distinctId, |
| 37 | isFirstRun: true, |
| 38 | persist: () => writeState(file, { ...fresh, firstRunNoticeShown: true }), |
| 39 | }; |
| 40 | } |
| 41 | function writeState(file: string, s: Stored) { |
| 42 | try { |
| 43 | fs.mkdirSync(path.dirname(file), { recursive: true }); |
no test coverage detected