()
| 81 | } |
| 82 | |
| 83 | load(): Preferences { |
| 84 | if (this.cache) return this.cache |
| 85 | |
| 86 | try { |
| 87 | if (fs.existsSync(this.filePath)) { |
| 88 | const raw = fs.readFileSync(this.filePath, 'utf-8') |
| 89 | const parsed = JSON.parse(raw) as Partial<Preferences> |
| 90 | const migrated = this.migrateLegacyDesensitizeRules(parsed, raw) |
| 91 | this.cache = this.mergeDefaults(migrated.preferences) |
| 92 | if (migrated.changed) { |
| 93 | this.writePreferences(this.cache) |
| 94 | } |
| 95 | return this.cache |
| 96 | } |
| 97 | } catch (err) { |
| 98 | console.warn('[Preferences] Failed to load preferences.json:', err) |
| 99 | } |
| 100 | |
| 101 | this.cache = { ...DEFAULTS } |
| 102 | return this.cache |
| 103 | } |
| 104 | |
| 105 | save(partial: Partial<Preferences>): { success: boolean; error?: string } { |
| 106 | try { |
no test coverage detected