( win: BrowserWindow, pathname: string, type: WatchType, endOfLine: LineEnding, autoGuessEncoding: boolean, trimTrailingNewline: number, autoNormalizeLineEndings: boolean )
| 41 | } |
| 42 | |
| 43 | const add = async( |
| 44 | win: BrowserWindow, |
| 45 | pathname: string, |
| 46 | type: WatchType, |
| 47 | endOfLine: LineEnding, |
| 48 | autoGuessEncoding: boolean, |
| 49 | trimTrailingNewline: number, |
| 50 | autoNormalizeLineEndings: boolean |
| 51 | ): Promise<void> => { |
| 52 | const stats = await fsPromises.stat(pathname) |
| 53 | const birthTime = stats.birthtime |
| 54 | const mtimeMs = stats.mtimeMs |
| 55 | const isMarkdown = hasMarkdownExtension(pathname) |
| 56 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 57 | const file: any = { |
| 58 | pathname, |
| 59 | name: path.basename(pathname), |
| 60 | isFile: true, |
| 61 | isDirectory: false, |
| 62 | birthTime, |
| 63 | mtimeMs, |
| 64 | isMarkdown |
| 65 | } |
| 66 | if (isMarkdown) { |
| 67 | // HACK: But this should be removed completely in #1034/#1035. |
| 68 | try { |
| 69 | const data = await loadMarkdownFile( |
| 70 | pathname, |
| 71 | endOfLine, |
| 72 | autoGuessEncoding, |
| 73 | trimTrailingNewline, |
| 74 | autoNormalizeLineEndings |
| 75 | ) |
| 76 | file.data = data |
| 77 | } catch (err) { |
| 78 | // Only notify user about opened files. |
| 79 | if (type === 'file') { |
| 80 | win.webContents.send('mt::show-notification', { |
| 81 | title: 'Watcher I/O error', |
| 82 | type: 'error', |
| 83 | message: err instanceof Error ? err.message : String(err) |
| 84 | }) |
| 85 | return |
| 86 | } |
| 87 | } |
| 88 | win.webContents.send(EVENT_NAME[type], { |
| 89 | type: 'add', |
| 90 | change: file |
| 91 | }) |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const unlink = (win: BrowserWindow, pathname: string, type: WatchType): void => { |
| 96 | const file = { pathname } |
no test coverage detected