Update link list in the background

This commit is contained in:
Lost Paul 2025-07-18 18:10:48 +02:00
parent 9a1e5773a0
commit e46191d137
3 changed files with 24 additions and 6 deletions

View file

@ -1,5 +1,5 @@
import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice, Keymap, WorkspaceLeaf, requireApiVersion, Platform } from 'obsidian';
import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice, Keymap, WorkspaceLeaf, requireApiVersion, Platform, debounce } from 'obsidian';
import { DEFAULT_SETTINGS, FolderNotesSettings, SettingsTab } from './settings/SettingsTab';
import { Commands } from './Commands';
import { FileExplorerWorkspaceLeaf } from './globals';
@ -20,6 +20,8 @@ import { FileExplorerView, InternalPlugin } from 'obsidian-typings';
import { FOLDER_OVERVIEW_VIEW, FolderOverviewView } from './obsidian-folder-overview/src/view';
import { registerOverviewCommands } from './obsidian-folder-overview/src/Commands';
import { updateOverviewView, updateViewDropdown } from './obsidian-folder-overview/src/main';
import { FvIndexDB } from './obsidian-folder-overview/src/utils/IndexDB';
import { updateAllOverviews } from './obsidian-folder-overview/src/utils/functions';
export default class FolderNotesPlugin extends Plugin {
observer: MutationObserver;
@ -34,6 +36,7 @@ export default class FolderNotesPlugin extends Plugin {
tabManager: TabManager;
settingsOpened = false;
askModalCurrentlyOpen = false;
fvIndexDB: FvIndexDB;
private fileExplorerPlugin!: InternalPlugin;
private fileExplorerView!: FileExplorerView;
@ -44,6 +47,7 @@ export default class FolderNotesPlugin extends Plugin {
this.settingsTab = new SettingsTab(this.app, this);
this.addSettingTab(this.settingsTab);
this.saveSettings();
this.fvIndexDB = new FvIndexDB(this);
// Add CSS Classes
document.body.classList.add('folder-notes-plugin');
@ -128,6 +132,7 @@ export default class FolderNotesPlugin extends Plugin {
this.registerEvent(this.app.vault.on('rename', (file: TAbstractFile, oldPath: string) => {
handleRename(file, oldPath, this);
}));
this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => {
@ -230,6 +235,13 @@ export default class FolderNotesPlugin extends Plugin {
};
}
handleVaultChange() {
if (!this.settings.fvGlobalSettings.autoUpdateLinks) return;
debounce(() => {
updateAllOverviews(this);
}, 2000, true)();
}
handleFileExplorerClick(evt: MouseEvent) {
const target = evt.target as HTMLElement;
if (evt.shiftKey) return;

View file

@ -3,7 +3,7 @@ import { createOverviewSettings } from 'src/obsidian-folder-overview/src/setting
export async function renderFolderOverview(settingsTab: SettingsTab) {
const { plugin } = settingsTab;
const overviewSettings = plugin.settings.defaultOverview;
const defaultOverviewSettings = plugin.settings.defaultOverview;
const containerEl = settingsTab.settingsPage;
const pEl = containerEl.createEl('p', {
text: 'Edit the default settings for new folder overviews, ',
@ -14,5 +14,5 @@ export async function renderFolderOverview(settingsTab: SettingsTab) {
span.setAttr('style', `color: ${accentColor};`);
pEl.appendChild(span);
createOverviewSettings(containerEl, overviewSettings, plugin, plugin.settings.defaultOverview, settingsTab.display, undefined, undefined, undefined, settingsTab);
createOverviewSettings(containerEl, defaultOverviewSettings, plugin, plugin.settings.defaultOverview, settingsTab.display, undefined, undefined, undefined, settingsTab);
}

View file

@ -3,7 +3,7 @@ import FolderNotesPlugin from '../main';
import { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
import { extractFolderName, getFolderNote } from '../functions/folderNoteFunctions';
import { overviewSettings } from '../obsidian-folder-overview/src/FolderOverview';
import { defaultOverviewSettings } from '../obsidian-folder-overview/src/FolderOverview';
import { renderGeneral } from './GeneralSettings';
import { renderFileExplorer } from './FileExplorerSettings';
import { renderPath } from './PathSettings';
@ -41,7 +41,7 @@ export interface FolderNotesSettings {
disableFolderHighlighting: boolean;
storageLocation: 'insideFolder' | 'parentFolder' | 'vaultFolder';
syncDelete: boolean;
defaultOverview: overviewSettings;
defaultOverview: defaultOverviewSettings;
useSubmenus: boolean;
syncMove: boolean;
frontMatterTitle: {
@ -76,6 +76,9 @@ export interface FolderNotesSettings {
afterChangingTab: boolean;
},
firstTimeInsertOverview: boolean;
fvGlobalSettings: {
autoUpdateLinks: boolean;
}
}
export const DEFAULT_SETTINGS: FolderNotesSettings = {
@ -194,6 +197,9 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
afterChangingTab: true,
},
firstTimeInsertOverview: true,
fvGlobalSettings: {
autoUpdateLinks: false,
},
};
export class SettingsTab extends PluginSettingTab {
@ -248,7 +254,7 @@ export class SettingsTab extends PluginSettingTab {
}
}
display(contentEl?: HTMLElement, yaml?: overviewSettings, plugin?: FolderNotesPlugin, defaultSettings?: boolean, display?: CallableFunction, el?: HTMLElement, ctx?: MarkdownPostProcessorContext, file?: TFile | null, settingsTab?: this) {
display(contentEl?: HTMLElement, yaml?: defaultOverviewSettings, plugin?: FolderNotesPlugin, defaultSettings?: boolean, display?: CallableFunction, el?: HTMLElement, ctx?: MarkdownPostProcessorContext, file?: TFile | null, settingsTab?: this) {
plugin = this?.plugin ?? plugin;
if (plugin) {
plugin.settingsOpened = true;