Skip to content

Commit

Permalink
#160 - compatibility with Obsidian 1.7.2
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
SebastianMC committed Sep 20, 2024
1 parent 6085be8 commit 1019484
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare module 'obsidian' {

export interface FileExplorerView extends View {
createFolderDom(folder: TFolder): FileExplorerFolder;
getSortedFolderItems(sortedFolder: TFolder): any[];

requestSort(): void;

Expand Down

0 comments on commit 1019484

Please sign in to comment.