* For macOS screenshot paths with AM/PM, the space before AM/PM may be a * regular space or a thin space depending on the macOS version. Returns * the alternate path to try if the original doesn't exist, or undefined.
(filePath: string)
| 145 | * the alternate path to try if the original doesn't exist, or undefined. |
| 146 | */ |
| 147 | function getAlternateScreenshotPath(filePath: string): string | undefined { |
| 148 | const filename = path.basename(filePath) |
| 149 | const amPmPattern = /^(.+)([ \u202F])(AM|PM)(\.png)$/ |
| 150 | const match = filename.match(amPmPattern) |
| 151 | if (!match) return undefined |
| 152 | |
| 153 | const currentSpace = match[2] |
| 154 | const alternateSpace = currentSpace === ' ' ? THIN_SPACE : ' ' |
| 155 | return filePath.replace( |
| 156 | `${currentSpace}${match[3]}${match[4]}`, |
| 157 | `${alternateSpace}${match[3]}${match[4]}`, |
| 158 | ) |
| 159 | } |
| 160 | |
| 161 | // File read listeners - allows other services to be notified when files are read |
| 162 | type FileReadListener = (filePath: string, content: string) => void |