(win: BrowserWindow, watchPath: string, type: WatchType = 'dir')
| 189 | } |
| 190 | |
| 191 | watch(win: BrowserWindow, watchPath: string, type: WatchType = 'dir'): () => void { |
| 192 | const usePolling = isOsx ? true : this._preferences.getItem('watcherUsePolling') |
| 193 | |
| 194 | const id = getUniqueId() |
| 195 | |
| 196 | const watcher = chokidar.watch(watchPath, { |
| 197 | ignored: (pathname: string, fileInfo?: { isDirectory: () => boolean }) => { |
| 198 | if (!fileInfo) { |
| 199 | return /(?:^|[/\\])(?:node_modules|(?:.+\.asar))/.test(pathname) |
| 200 | } |
| 201 | |
| 202 | if (/(?:^|[/\\])(?:node_modules|(?:.+\.asar))/.test(pathname)) { |
| 203 | return true |
| 204 | } |
| 205 | |
| 206 | if ( |
| 207 | checkPathExcludePattern(pathname, this._preferences.getItem('treePathExcludePatterns')) |
| 208 | ) { |
| 209 | return true |
| 210 | } |
| 211 | if (fileInfo.isDirectory()) { |
| 212 | return false |
| 213 | } |
| 214 | return !hasMarkdownExtension(pathname) |
| 215 | }, |
| 216 | ignoreInitial: type === 'file', |
| 217 | persistent: true, |
| 218 | ignorePermissionErrors: true, |
| 219 | |
| 220 | depth: type === 'file' ? (isOsx ? 1 : 0) : undefined, |
| 221 | |
| 222 | // Please see GH#1043 |
| 223 | awaitWriteFinish: { |
| 224 | stabilityThreshold: WATCHER_STABILITY_THRESHOLD, |
| 225 | pollInterval: WATCHER_STABILITY_POLL_INTERVAL |
| 226 | }, |
| 227 | |
| 228 | usePolling |
| 229 | // eslint-disable-next-line @typescript-eslint/no-explicit-any -- chokidar's `ignored` callback signature varies between versions; this options bag works at runtime but defies the bundled type |
| 230 | } as any) |
| 231 | |
| 232 | let disposed = false |
| 233 | let enospcReached = false |
| 234 | let renameTimer: NodeJS.Timeout | null = null |
| 235 | |
| 236 | watcher |
| 237 | .on('add', async(pathname: string) => { |
| 238 | if (!(await this._shouldIgnoreEvent(win.id, pathname, type, usePolling))) { |
| 239 | const { _preferences } = this |
| 240 | const eol = _preferences.getPreferredEol() as LineEnding |
| 241 | const { autoGuessEncoding, trimTrailingNewline, autoNormalizeLineEndings } = |
| 242 | _preferences.getAll() |
| 243 | add( |
| 244 | win, |
| 245 | pathname, |
| 246 | type, |
| 247 | eol, |
| 248 | autoGuessEncoding, |
no test coverage detected