From 10194849352be3f1cfbda5af58f3440e79c83492 Mon Sep 17 00:00:00 2001 From: SebastianMC <23032356+SebastianMC@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:53:50 +0200 Subject: [PATCH] #160 - compatibility with Obsidian 1.7.2 - the fileExplorer patchability check made smarter and version-dependent - the plugin-integration-point support required by Obsidian 1.7.2 has been already incorporated in the plugin earlier on, for 1.6.0 Obsidian release --- src/main.ts | 24 +++++++++++++++--------- src/types/types.d.ts | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main.ts b/src/main.ts index 62564c1e6..47e584c21 100644 --- a/src/main.ts +++ b/src/main.ts @@ -178,17 +178,23 @@ export default class CustomSortPlugin checkFileExplorerIsAvailableAndPatchable(logWarning: boolean = true): FileExplorerView | undefined { let fileExplorerView: FileExplorerView | undefined = this.getFileExplorer() - if (fileExplorerView - && typeof fileExplorerView.createFolderDom === 'function' - && typeof fileExplorerView.requestSort === 'function') { - return fileExplorerView - } else { - // Various scenarios when File Explorer was turned off (e.g. by some other plugin) - if (logWarning) { - this.logWarningFileExplorerNotAvailable() + if (fileExplorerView && typeof fileExplorerView.requestSort === 'function') { + // The plugin integration points changed with Obsidian 1.6.0 hence the patchability-check should also be Obsidian version aware + if (requireApiVersion && requireApiVersion("1.6.0")) { + if (typeof fileExplorerView.getSortedFolderItems === 'function') { + return fileExplorerView + } + } else { // Obsidian versions prior to 1.6.0 + if (typeof fileExplorerView.createFolderDom === 'function') { + return fileExplorerView + } } - return undefined } + // Various scenarios when File Explorer was turned off (e.g. by some other plugin) + if (logWarning) { + this.logWarningFileExplorerNotAvailable() + } + return undefined } logWarningFileExplorerNotAvailable() { diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 1e96a5c2c..d6a52b011 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -51,6 +51,7 @@ declare module 'obsidian' { export interface FileExplorerView extends View { createFolderDom(folder: TFolder): FileExplorerFolder; + getSortedFolderItems(sortedFolder: TFolder): any[]; requestSort(): void;