diff --git a/src/Commands.ts b/src/Commands.ts index b0f9e2a..f11101a 100644 --- a/src/Commands.ts +++ b/src/Commands.ts @@ -328,7 +328,7 @@ export class Commands { }); } if (!(file instanceof TFolder)) return; - const excludedFolder = await getExcludedFolder(this.plugin, file.path, false); + const excludedFolder = getExcludedFolder(this.plugin, file.path, false); const detachedExcludedFolder = getDetachedFolder(this.plugin, file.path); if (excludedFolder && !excludedFolder.hideNote) { // I'm not sure if I'm ever going to add this because of the possibility that a folder got more than one excluded diff --git a/src/events/MutationObserver.ts b/src/events/MutationObserver.ts index 9efce2e..2af215e 100644 --- a/src/events/MutationObserver.ts +++ b/src/events/MutationObserver.ts @@ -24,7 +24,7 @@ export function registerFileExplorerObserver(plugin: FolderNotesPlugin) { plugin.registerEvent( plugin.app.workspace.on('file-open', (file) => { if (file instanceof TFile) { - scheduleIdle(() => updateBreadcrumbs(file, plugin), { timeout: 1000 }); + scheduleIdle(() => updateBreadcrumbs(plugin), { timeout: 1000 }); } }) ); @@ -44,7 +44,6 @@ function initializeFolderNoteFeatures(plugin: FolderNotesPlugin) { initializeAllFolderTitles(explorer, plugin); observeFolderTitleMutations(explorer, plugin); - // Add breadcrumb click listener explorer.addEventListener('click', (e) => handleBreadcrumbClick((e as MouseEvent), plugin), true); } @@ -148,7 +147,7 @@ async function setupFolderTitle(folderTitle: HTMLElement, plugin: FolderNotesPlu }); } -async function updateBreadcrumbs(file: TFile, plugin: FolderNotesPlugin) { +async function updateBreadcrumbs(plugin: FolderNotesPlugin) { const headers = document.querySelectorAll('span.view-header-breadcrumb'); headers.forEach(async (breadcrumb: HTMLElement) => { let path = ''; @@ -164,7 +163,7 @@ async function updateBreadcrumbs(file: TFile, plugin: FolderNotesPlugin) { crumb.setAttribute('old-name', folder.name || ''); (crumb as HTMLElement).innerText = folder.newName || ''; } - const excludedFolder = await getExcludedFolder(plugin, folderPath, true); + const excludedFolder = getExcludedFolder(plugin, folderPath, true); if (excludedFolder?.disableFolderNote) return; const folderNote = getFolderNote(plugin, folderPath); if (folderNote) crumb.classList.add('has-folder-note'); @@ -184,6 +183,9 @@ function handleBreadcrumbClick(event: MouseEvent, plugin: FolderNotesPlugin) { }, { capture: true }); } +// Schedules a callback to run when the browser is idle, or after a timeout as a fallback. +// - callback: The function to execute when idle or after the timeout. +// - options: Optional object with a 'timeout' property (in milliseconds). function scheduleIdle(callback: () => void, options?: { timeout: number }) { if ('requestIdleCallback' in window) { (window as any).requestIdleCallback(callback, options); diff --git a/src/events/handleClick.ts b/src/events/handleClick.ts index 5022812..3cb9d1f 100644 --- a/src/events/handleClick.ts +++ b/src/events/handleClick.ts @@ -13,7 +13,7 @@ export async function handleViewHeaderClick(event: MouseEvent, plugin: FolderNot const folderPath = event.target.getAttribute('data-path'); if (!folderPath) { return; } - const excludedFolder = await getExcludedFolder(plugin, folderPath, true); + const excludedFolder = getExcludedFolder(plugin, folderPath, true); if (excludedFolder?.disableFolderNote) { event.target.onclick = null; event.target.click(); @@ -61,7 +61,7 @@ export async function handleFolderClick(event: MouseEvent, plugin: FolderNotesPl const folderPath = event.target.parentElement?.getAttribute('data-path'); if (!folderPath) { return; } - const excludedFolder = await getExcludedFolder(plugin, folderPath, true); + const excludedFolder = getExcludedFolder(plugin, folderPath, true); if (excludedFolder?.disableFolderNote) { event.target.onclick = null; event.target.click(); diff --git a/src/events/handleCreate.ts b/src/events/handleCreate.ts index 072ff85..72dbb09 100644 --- a/src/events/handleCreate.ts +++ b/src/events/handleCreate.ts @@ -31,7 +31,7 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin) { const newFolder = await plugin.app.fileManager.createNewFolder(file.parent); turnIntoFolderNote(plugin, file, newFolder); } else if (folder instanceof TFolder) { - const detachedFolder = await getExcludedFolder(plugin, folder.path, true); + const detachedFolder = getExcludedFolder(plugin, folder.path, true); if (detachedFolder) { return; } const folderNote = getFolderNote(plugin, folder.path); @@ -59,7 +59,7 @@ async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin) openFile = false; } - const excludedFolder = await getExcludedFolder(plugin, folder.path, true); + const excludedFolder = getExcludedFolder(plugin, folder.path, true); if (excludedFolder?.disableAutoCreate) return; const folderNote = getFolderNote(plugin, folder.path); diff --git a/src/events/handleRename.ts b/src/events/handleRename.ts index 5e4c19c..ba9e1b1 100644 --- a/src/events/handleRename.ts +++ b/src/events/handleRename.ts @@ -55,7 +55,7 @@ export async function handleFileMove(file: TFile, oldPath: string, plugin: Folde const oldFileName = removeExtension(getFileNameFromPathString(oldPath)); const newFolder = getFolderNoteFolder(plugin, file, file.basename); const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file); - let excludedFolder = await getExcludedFolder(plugin, newFolder?.path || '', true); + let excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true); const oldFolder = getFolderNoteFolder(plugin, oldPath, oldFileName); // file has been moved into position where it can be a folder note! @@ -101,7 +101,7 @@ export async function handleFolderRename(file: TFolder, oldPath: string, plugin: if (!(folderNote instanceof TFile)) return; - const excludedFolder = await getExcludedFolder(plugin, file.path, true); + const excludedFolder = getExcludedFolder(plugin, file.path, true); if (excludedFolder?.disableSync && !folderNote) { return removeCSSClassFromEL(file.path, 'has-folder-note', plugin); } @@ -138,7 +138,7 @@ export async function handleFileRename(file: TFile, oldPath: string, plugin: Fol const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename) || file.basename; const oldFolderName = extractFolderName(plugin.settings.folderNoteName, oldFileName) || oldFileName; const newFolder = getFolderNoteFolder(plugin, file, file.basename); - const excludedFolder = await getExcludedFolder(plugin, newFolder?.path || '', true); + const excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true); const detachedExcludedFolder = getDetachedFolder(plugin, newFolder?.path || ''); const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file); diff --git a/src/functions/folderNoteFunctions.ts b/src/functions/folderNoteFunctions.ts index a507577..85fe9eb 100644 --- a/src/functions/folderNoteFunctions.ts +++ b/src/functions/folderNoteFunctions.ts @@ -203,7 +203,7 @@ export async function turnIntoFolderNote(plugin: FolderNotesPlugin, file: TFile, } export async function tempDisableSync(plugin: FolderNotesPlugin, folder: TFolder): Promise<[excludedFolder: ExcludedFolder | undefined, excludedFolderExisted: boolean, disabledSync: boolean]> { - let excludedFolder = await getExcludedFolder(plugin, folder.path, false); + let excludedFolder = getExcludedFolder(plugin, folder.path, false); let excludedFolderExisted = true; let disabledSync = false; diff --git a/src/functions/styleFunctions.ts b/src/functions/styleFunctions.ts index a9a8cb7..d5a27f2 100644 --- a/src/functions/styleFunctions.ts +++ b/src/functions/styleFunctions.ts @@ -18,7 +18,7 @@ export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin) return; } - const excludedFolder = await getExcludedFolder(plugin, file.path, true); + const excludedFolder = getExcludedFolder(plugin, file.path, true); // cleanup after ourselves // Incase settings have changed if (excludedFolder?.disableFolderNote) { @@ -48,7 +48,7 @@ export async function applyCSSClassesToFolder(folderPath: string, plugin: Folder return; } - const excludedFolder = await getExcludedFolder(plugin, folder.path, true); + const excludedFolder = getExcludedFolder(plugin, folder.path, true); if (excludedFolder?.disableFolderNote) { removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin); diff --git a/src/main.ts b/src/main.ts index 39c604b..f01c02a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -119,7 +119,7 @@ export default class FolderNotesPlugin extends Plugin { const folder = getFolder(this, openFile); if (!folder) { return; } - const excludedFolder = await getExcludedFolder(this, folder.path, true); + const excludedFolder = getExcludedFolder(this, folder.path, true); if (excludedFolder?.disableFolderNote) return; const folderNote = getFolderNote(this, folder.path); if (!folderNote) { return; } diff --git a/src/settings/modals/CreateFnForEveryFolder.ts b/src/settings/modals/CreateFnForEveryFolder.ts index 86583c8..c3e719a 100644 --- a/src/settings/modals/CreateFnForEveryFolder.ts +++ b/src/settings/modals/CreateFnForEveryFolder.ts @@ -65,7 +65,7 @@ export default class ConfirmationModal extends Modal { const folders = this.app.vault.getAllLoadedFiles().filter((file) => file.parent instanceof TFolder); for (const folder of folders) { if (folder instanceof TFolder) { - const excludedFolder = await getExcludedFolder(this.plugin, folder.path, true); + const excludedFolder = getExcludedFolder(this.plugin, folder.path, true); if (excludedFolder) continue; if (folder.path === templateFolderPath) continue; const folderNote = getFolderNote(this.plugin, folder.path);