(dir: string, reveal?: boolean, forceOpen = false)
| 30 | * @returns {Promise<void>} |
| 31 | */ |
| 32 | const OpenDir = async (dir: string, reveal?: boolean, forceOpen = false): Promise<void> => { |
| 33 | await stopSearchingProcess(); |
| 34 | if (isLoading() && !forceOpen) { |
| 35 | InfoLog(`Something is still loading, refusing to open dir ${dir}`); |
| 36 | return; |
| 37 | } |
| 38 | console.time(dir); |
| 39 | // Check if the user is just want to reload the current directory |
| 40 | const isReload = (await focusingPath()) === dir && !forceOpen; |
| 41 | if (!isReload) directoryInfo?.unlisten?.(); |
| 42 | startLoading(); |
| 43 | changePosition(dir, forceOpen); |
| 44 | const MAIN_ELEMENT = document.getElementById('workspace'); |
| 45 | MAIN_ELEMENT.innerHTML = ''; |
| 46 | if (MAIN_ELEMENT.classList.contains('empty-dir-notification')) MAIN_ELEMENT.classList.remove('empty-dir-notification'); // Remove class if exist |
| 47 | if (dir === 'xplorer://Home') { |
| 48 | Home(); |
| 49 | UpdateInfo('number-of-files', ''); |
| 50 | OpenLog(dir); |
| 51 | } else if (dir === 'xplorer://Trash') { |
| 52 | if (!platform) platform = await OS(); |
| 53 | if (platform === 'darwin') { |
| 54 | MAIN_ELEMENT.classList.add('empty-dir-notification'); |
| 55 | MAIN_ELEMENT.innerText = 'Xploring trash folder is not supported for macOS yet.'; |
| 56 | stopLoading(); |
| 57 | } else { |
| 58 | getTrashedFiles().then(async (trashedFiles) => { |
| 59 | UpdateInfo('number-of-files', `${trashedFiles.files.length} files`); |
| 60 | if (!trashedFiles.files.length) { |
| 61 | MAIN_ELEMENT.classList.add('empty-dir-notification'); |
| 62 | MAIN_ELEMENT.innerText = 'This folder is empty.'; |
| 63 | stopLoading(); |
| 64 | } else { |
| 65 | await displayFiles(trashedFiles.files, dir, MAIN_ELEMENT); |
| 66 | stopLoading(); |
| 67 | updateTheme('grid'); |
| 68 | LOAD_IMAGE(); |
| 69 | changeWindowTitle(getBasename(dir)); |
| 70 | } |
| 71 | }); |
| 72 | } |
| 73 | OpenLog(dir); |
| 74 | } else if (dir === 'xplorer://Recent') { |
| 75 | Recent(); |
| 76 | UpdateInfo('number-of-files', ''); |
| 77 | OpenLog(dir); |
| 78 | } else if (dir.startsWith('Search')) { |
| 79 | // Search path pattern: Search: [[search-query]] inside [[search-path]] |
| 80 | const splitBySearchKeyword = dir.split('Search: '); |
| 81 | splitBySearchKeyword.shift(); |
| 82 | const query = splitBySearchKeyword.join('Search: '); |
| 83 | const splitByInsideKeyword = query.split(' inside '); |
| 84 | if (splitByInsideKeyword.length === 2) { |
| 85 | const searchQuery = splitByInsideKeyword[0].slice(2, -2); |
| 86 | const searchPath = splitByInsideKeyword[1].slice(2, -2); |
| 87 | processSearch(searchQuery, searchPath); |
| 88 | } else { |
| 89 | for (let i = 0; i < splitByInsideKeyword.length; i++) { |
no test coverage detected