Skip to content

Commit ef5926c

Browse files
committed
#188 - Group of changes addressing compatibility issued with Obsidian 1.7.2 and newer
1 parent 92c0e0c commit ef5926c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/main.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import {
2+
App,
3+
CommunityPlugin,
24
FileExplorerLeaf,
35
FileExplorerView,
4-
Menu,
5-
MenuItem,
6+
Menu,
7+
MenuItem,
68
MetadataCache,
79
Notice,
810
Platform,
@@ -43,7 +45,7 @@ import {
4345
groupNameForPath
4446
} from "./utils/BookmarksCorePluginSignature";
4547
import {
46-
getIconFolderPlugin
48+
getIconFolderPlugin, ObsidianIconFolder_PluginInstance, ObsidianIconFolderPlugin_getData_methodName
4749
} from "./utils/ObsidianIconFolderPluginSignature";
4850
import {
4951
extractBasename,
@@ -64,6 +66,8 @@ import {
6466
} from "./settings";
6567
import {CustomSortPluginAPI} from "./custom-sort-plugin";
6668

69+
const PLUGIN_ID = 'custom-sort' // same as in manifest.json
70+
6771
const SORTSPEC_FILE_NAME: string = 'sortspec.md'
6872
const SORTINGSPEC_YAML_KEY: string = 'sorting-spec'
6973

@@ -266,13 +270,13 @@ export default class CustomSortPlugin
266270
}
267271

268272
logWarningFileExplorerDeferred() {
269-
const msg = `custom-sort v${this.manifest.version}: failed to get active File Explorer view.\n`
273+
const msg = `${PLUGIN_ID} v${this.manifest.version}: failed to get active File Explorer view.\n`
270274
+ `Until the File Explorer is visible, the custom-sort plugin cannot apply the custom order.\n`
271275
console.warn(msg)
272276
}
273277

274278
logWarningFileExplorerNotAvailable() {
275-
const msg = `custom-sort v${this.manifest.version}: failed to locate File Explorer. The 'Files' core plugin can be disabled.\n`
279+
const msg = `${PLUGIN_ID} v${this.manifest.version}: failed to locate File Explorer. The 'Files' core plugin can be disabled.\n`
276280
+ `Some community plugins can also disable it.\n`
277281
+ `See the example of MAKE.md plugin: https://github.com/Make-md/makemd/issues/25\n`
278282
+ `You can find there instructions on how to re-enable the File Explorer in MAKE.md plugin`
@@ -323,7 +327,7 @@ export default class CustomSortPlugin
323327
}
324328

325329
async onload() {
326-
console.log(`loading custom-sort v${this.manifest.version}`);
330+
console.log(`loading ${PLUGIN_ID} v${this.manifest.version}`);
327331

328332
await this.loadSettings();
329333

@@ -665,9 +669,18 @@ export default class CustomSortPlugin
665669
await this.saveData(this.settings);
666670
}
667671

672+
isThePluginStillInstalledAndEnabled(): boolean {
673+
const thisPlugin: CommunityPlugin | undefined = this?.app?.plugins?.plugins?.[PLUGIN_ID]
674+
if (thisPlugin && thisPlugin._loaded && this?.app?.plugins?.enabledPlugins?.has(PLUGIN_ID)) {
675+
return true
676+
}
677+
return false
678+
}
679+
668680
initialDelayedApplicationOfCustomSorting() {
669-
if (!this) {
670-
return // sanity check - plugin removed from the system?
681+
if (!this?.isThePluginStillInstalledAndEnabled()) {
682+
console.log(`${PLUGIN_ID} v${this.manifest.version} - delayed handler skipped, plugin no longer active.`)
683+
return
671684
}
672685

673686
// should be applied? yes (based on settings)

0 commit comments

Comments
 (0)