()
| 1172 | * Watches parent directories which reliably catches all file modifications |
| 1173 | */ |
| 1174 | export const setupFileWatchers = () => { |
| 1175 | const watchTargets: string[] = [] |
| 1176 | const watchedDirs = new Set<string>() |
| 1177 | |
| 1178 | // macOS system preferences |
| 1179 | if (process.platform === 'darwin') { |
| 1180 | watchTargets.push( |
| 1181 | join(homedir(), 'Library/Preferences/.GlobalPreferences.plist'), |
| 1182 | join(homedir(), 'Library/Preferences/com.apple.Terminal.plist'), |
| 1183 | ) |
| 1184 | } |
| 1185 | |
| 1186 | // IDE config files - only watch for the active IDE terminal |
| 1187 | if (isVSCodeFamilyTerminal()) { |
| 1188 | watchTargets.push(...resolveVSCodeSettingsPaths()) |
| 1189 | } |
| 1190 | if (isJetBrainsTerminal()) { |
| 1191 | watchTargets.push(...resolveJetBrainsLafPaths()) |
| 1192 | } |
| 1193 | if (isZedTerminal()) { |
| 1194 | watchTargets.push(...resolveZedSettingsPaths()) |
| 1195 | } |
| 1196 | |
| 1197 | // Watch parent directories instead of individual files |
| 1198 | // Directory watches are more reliable for catching all modifications including plist key deletions |
| 1199 | for (const target of watchTargets) { |
| 1200 | if (existsSync(target)) { |
| 1201 | const parentDir = dirname(target) |
| 1202 | |
| 1203 | // Only watch each directory once |
| 1204 | if (watchedDirs.has(parentDir)) continue |
| 1205 | watchedDirs.add(parentDir) |
| 1206 | |
| 1207 | try { |
| 1208 | // Watch the directory - catches all file modifications |
| 1209 | const watcher = watch( |
| 1210 | parentDir, |
| 1211 | { persistent: false }, |
| 1212 | (eventType, filename) => { |
| 1213 | // Only respond to changes affecting our target files |
| 1214 | if (filename && watchTargets.some((t) => t.endsWith(filename))) { |
| 1215 | debouncedRecomputeSystemTheme() |
| 1216 | } |
| 1217 | }, |
| 1218 | ) |
| 1219 | |
| 1220 | watcher.on('error', () => { |
| 1221 | // Silently ignore watcher errors |
| 1222 | }) |
| 1223 | } catch { |
| 1224 | // Silently ignore if we can't watch |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | /** |
| 1231 | * SIGUSR2 signal handler for manual theme refresh |
no test coverage detected