()
| 16 | }); |
| 17 | |
| 18 | export default async function checkFiles() { |
| 19 | if (!editorManager) return; |
| 20 | if (checkFileEnabled === false) { |
| 21 | checkFileEnabled = true; |
| 22 | return; |
| 23 | } |
| 24 | const files = editorManager.files; |
| 25 | // @ts-check |
| 26 | /** @type {{ editor: import('@codemirror/view').EditorView }} */ |
| 27 | const { editor } = editorManager; |
| 28 | |
| 29 | recursiveFileCheck([...files]); |
| 30 | |
| 31 | /** |
| 32 | * Checks if the file has been changed |
| 33 | * @param {EditorFile[]} files List of files to check |
| 34 | */ |
| 35 | async function recursiveFileCheck(files) { |
| 36 | const file = files.pop(); |
| 37 | await checkFile(file); |
| 38 | if (files.length) { |
| 39 | recursiveFileCheck(files); |
| 40 | } |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @typedef {import('./editorFile').default} EditorFile |
| 46 | */ |
| 47 | |
| 48 | /** |
| 49 | * Checks a file for changes |
| 50 | * @param {EditorFile} file File to check |
| 51 | * @returns {Promise<void>} |
| 52 | */ |
| 53 | async function checkFile(file) { |
| 54 | if (file === undefined || !file.loaded || file.loading) return; |
| 55 | |
| 56 | if (file.uri) { |
| 57 | const fs = fsOperation(file.uri); |
| 58 | const exists = await fs.exists(); |
| 59 | |
| 60 | if (!exists && !file.readOnly) { |
| 61 | file.isUnsaved = true; |
| 62 | file.uri = null; |
| 63 | editorManager.onupdate("file-changed"); |
| 64 | editorManager.emit("update", "file-changed"); |
| 65 | await new Promise((resolve) => { |
| 66 | alert( |
| 67 | strings.info, |
| 68 | strings["file has been deleted"].replace("{file}", file.filename), |
| 69 | resolve, |
| 70 | ); |
| 71 | }); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | let mtime = null; |
no test coverage detected