From a044e6c2eb19d7e08e9a4e6e6b28ac0f182f710e Mon Sep 17 00:00:00 2001 From: mjkerrison <25721638+mjkerrison@users.noreply.github.com> Date: Mon, 12 Jan 2026 12:22:28 +1100 Subject: [PATCH] fix: startup error and settings tab reset issues - Handle missing file explorer during early startup to prevent "Cannot read properties of undefined" error - Use renderSettingsPage instead of display when adding excluded/ whitelisted folders to stay on current settings tab Co-Authored-By: Claude Opus 4.5 --- .../modals/WhitelistedFoldersSettings.ts | 2 +- src/functions/styleFunctions.ts | 6 ++++-- src/functions/utils.ts | 17 ++++++++++------- src/settings/ExcludedFoldersSettings.ts | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/ExcludeFolders/modals/WhitelistedFoldersSettings.ts b/src/ExcludeFolders/modals/WhitelistedFoldersSettings.ts index b00342d..43d5cce 100644 --- a/src/ExcludeFolders/modals/WhitelistedFoldersSettings.ts +++ b/src/ExcludeFolders/modals/WhitelistedFoldersSettings.ts @@ -40,7 +40,7 @@ export default class WhitelistedFoldersSettings extends Modal { this.plugin.settingsTab, contentEl, whitelistedFolder, ); addWhitelistedFolder(this.plugin, whitelistedFolder); - this.settingsTab.display(); + this.settingsTab.renderSettingsPage(this.settingsTab.plugin.settings.settingsTab); }); }); diff --git a/src/functions/styleFunctions.ts b/src/functions/styleFunctions.ts index 7959702..4e99d42 100644 --- a/src/functions/styleFunctions.ts +++ b/src/functions/styleFunctions.ts @@ -14,8 +14,10 @@ import type FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main'; * @description Refreshes the CSS classes for all folder notes in the file explorer. */ export function refreshAllFolderStyles(forceReload = false, plugin: FolderNotesPlugin): void { - if (plugin.activeFileExplorer === getFileExplorer(plugin) && !forceReload) { return; } - plugin.activeFileExplorer = getFileExplorer(plugin); + const fileExplorer = getFileExplorer(plugin); + if (!fileExplorer) { return; } + if (plugin.activeFileExplorer === fileExplorer && !forceReload) { return; } + plugin.activeFileExplorer = fileExplorer; plugin.app.vault.getAllLoadedFiles().forEach(async (file) => { if (file instanceof TFolder) { await updateCSSClassesForFolder(file.path, plugin); diff --git a/src/functions/utils.ts b/src/functions/utils.ts index cca1363..be765f2 100644 --- a/src/functions/utils.ts +++ b/src/functions/utils.ts @@ -42,15 +42,17 @@ export function getParentFolderPath(path: string): string { export function getFileExplorer( plugin: FolderNotesPlugin | FolderOverviewPlugin, -): FileExplorerWorkspaceLeaf { +): FileExplorerWorkspaceLeaf | undefined { // eslint-disable-next-line max-len let leaf = plugin.app.workspace.getLeavesOfType('file-explorer')[0] as unknown as FileExplorerWorkspaceLeaf; + if (!leaf) { return undefined; } + /* make.md plugin integration */ - if (leaf.containerEl.lastChild.dataset.type == 'mk-path-view') { + if ((leaf.containerEl?.lastChild as HTMLElement)?.dataset?.type == 'mk-path-view') { plugin.app.workspace.iterateAllLeaves((x) => { - if (x.tabHeaderEl.dataset.type == 'file-explorer') { - leaf = x; + if ((x as FileExplorerWorkspaceLeaf).tabHeaderEl?.dataset?.type == 'file-explorer') { + leaf = x as FileExplorerWorkspaceLeaf; } }); } @@ -58,12 +60,13 @@ export function getFileExplorer( return leaf; } -export function getFileExplorerView(plugin: FolderNotesPlugin): FileExplorerView { - return getFileExplorer(plugin).view; +export function getFileExplorerView(plugin: FolderNotesPlugin): FileExplorerView | undefined { + return getFileExplorer(plugin)?.view; } export function getFocusedItem(plugin: FolderNotesPlugin): TreeNode | null { - const fileExplorer = getFileExplorer(plugin) as unknown as FileExplorerLeaf; + const fileExplorer = getFileExplorer(plugin) as unknown as FileExplorerLeaf | undefined; + if (!fileExplorer) { return null; } const { focusedItem } = fileExplorer.view.tree; return focusedItem; } diff --git a/src/settings/ExcludedFoldersSettings.ts b/src/settings/ExcludedFoldersSettings.ts index b8b9345..55e5c7e 100644 --- a/src/settings/ExcludedFoldersSettings.ts +++ b/src/settings/ExcludedFoldersSettings.ts @@ -93,7 +93,7 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise