mirror of
https://github.com/lostpaul/obsidian-folder-notes.git
synced 2026-07-22 07:40:24 +00:00
Remove unnecessary awaits
This commit is contained in:
parent
fe64c66b60
commit
84d8c608fd
9 changed files with 19 additions and 17 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue