The global `app` object becomes deprecated in Obsidian 1.6.0

- switched code to use the DI approach - the handle to `app` is handed over to the Plugin at initializaion. Keep in and supply down the execution chain, as needed
This commit is contained in:
SebastianMC 2024-05-13 14:36:13 +02:00
parent ef10a9ef43
commit 107c32e461
5 changed files with 51 additions and 32 deletions

View File

@ -703,6 +703,9 @@ export const determineBookmarksOrderIfNeeded = (folderItems: Array<FolderItemFor
} }
export const folderSort = function (sortingSpec: CustomSortSpec, ctx: ProcessingContext) { export const folderSort = function (sortingSpec: CustomSortSpec, ctx: ProcessingContext) {
console.log('3')
let fileExplorerView = this.fileExplorer ?? this.view // this.view replaces the former since 1.5.4 insider build let fileExplorerView = this.fileExplorer ?? this.view // this.view replaces the former since 1.5.4 insider build
// shallow copy of groups and expand folder-specific macros on them // shallow copy of groups and expand folder-specific macros on them
@ -735,9 +738,19 @@ export const folderSort = function (sortingSpec: CustomSortSpec, ctx: Processing
const items = folderItems const items = folderItems
.map((item: FolderItemForSorting) => fileExplorerView.fileItems[item.path]) .map((item: FolderItemForSorting) => fileExplorerView.fileItems[item.path])
if (requireApiVersion && requireApiVersion("0.15.0")) { console.log(`4 of length ${items.length}`)
if (requireApiVersion && requireApiVersion("0.16.0")) {
console.log('4.3')
const scrollTop = fileExplorerView.navFileContainerEl.scrollTop
fileExplorerView.tree.infinityScroll.rootEl.vChildren.setChildren([items])
fileExplorerView.navFileContainerEl.scrollTop = scrollTop
fileExplorerView.tree.infinityScroll.compute()
} else if (requireApiVersion && requireApiVersion("0.15.0")) {
console.log('4.1')
this.vChildren.setChildren(items); this.vChildren.setChildren(items);
} else { } else {
console.log('4.2')
this.children = items; this.children = items;
} }
}; };

View File

@ -116,7 +116,7 @@ export default class CustomSortPlugin extends Plugin {
} }
readAndParseSortingSpec() { readAndParseSortingSpec() {
const mCache: MetadataCache = app.metadataCache const mCache: MetadataCache = this.app.metadataCache
let failed: boolean = false let failed: boolean = false
let anySortingSpecFound: boolean = false let anySortingSpecFound: boolean = false
let errorMessage: string | null = null let errorMessage: string | null = null
@ -134,7 +134,7 @@ export default class CustomSortPlugin extends Plugin {
) )
} }
Vault.recurseChildren(app.vault.getRoot(), (file: TAbstractFile) => { Vault.recurseChildren(this.app.vault.getRoot(), (file: TAbstractFile) => {
if (failed) return if (failed) return
if (file instanceof TFile) { if (file instanceof TFile) {
const aFile: TFile = file as TFile const aFile: TFile = file as TFile
@ -249,7 +249,7 @@ export default class CustomSortPlugin extends Plugin {
// Syntax sugar // Syntax sugar
const ForceFlushCache = true const ForceFlushCache = true
if (!this.settings.suspended) { if (!this.settings.suspended) {
getBookmarksPlugin(this.settings.bookmarksGroupToConsumeAsOrderingReference, ForceFlushCache) getBookmarksPlugin(this.app, this.settings.bookmarksGroupToConsumeAsOrderingReference, ForceFlushCache)
} }
if (fileExplorerView) { if (fileExplorerView) {
@ -306,7 +306,7 @@ export default class CustomSortPlugin extends Plugin {
this.ribbonIconStateInaccurate = true this.ribbonIconStateInaccurate = true
} }
this.addSettingTab(new CustomSortSettingTab(app, this)); this.addSettingTab(new CustomSortSettingTab(this.app, this));
this.registerEventHandlers() this.registerEventHandlers()
@ -321,7 +321,7 @@ export default class CustomSortPlugin extends Plugin {
this.registerEvent( this.registerEvent(
// Keep in mind: this event is triggered once after app starts and then after each modification of _any_ metadata // Keep in mind: this event is triggered once after app starts and then after each modification of _any_ metadata
app.metadataCache.on("resolved", () => { plugin.app.metadataCache.on("resolved", () => {
if (!this.settings.suspended) { if (!this.settings.suspended) {
if (!this.initialAutoOrManualSortingTriggered) { if (!this.initialAutoOrManualSortingTriggered) {
this.readAndParseSortingSpec() this.readAndParseSortingSpec()
@ -365,7 +365,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'Bookmark it for custom sorting' : 'Bookmark it for sorting'); item.setTitle(m ? 'Bookmark it for custom sorting' : 'Bookmark it for sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
bookmarksPlugin.bookmarkFolderItem(file) bookmarksPlugin.bookmarkFolderItem(file)
bookmarksPlugin.saveDataAndUpdateBookmarkViews(true) bookmarksPlugin.saveDataAndUpdateBookmarkViews(true)
@ -377,7 +377,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'UNbookmark it from custom sorting' : 'UNbookmark it from sorting'); item.setTitle(m ? 'UNbookmark it from custom sorting' : 'UNbookmark it from sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
bookmarksPlugin.unbookmarkFolderItem(file) bookmarksPlugin.unbookmarkFolderItem(file)
bookmarksPlugin.saveDataAndUpdateBookmarkViews(true) bookmarksPlugin.saveDataAndUpdateBookmarkViews(true)
@ -389,7 +389,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'Bookmark it+siblings for custom sorting' : 'Bookmark it+siblings for sorting'); item.setTitle(m ? 'Bookmark it+siblings for custom sorting' : 'Bookmark it+siblings for sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
const orderedChildren: Array<TAbstractFile> = plugin.orderedFolderItemsForBookmarking(file.parent, bookmarksPlugin) const orderedChildren: Array<TAbstractFile> = plugin.orderedFolderItemsForBookmarking(file.parent, bookmarksPlugin)
bookmarksPlugin.bookmarkSiblings(orderedChildren) bookmarksPlugin.bookmarkSiblings(orderedChildren)
@ -402,7 +402,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'UNbookmark it+siblings from custom sorting' : 'UNbookmark it+siblings from sorting'); item.setTitle(m ? 'UNbookmark it+siblings from custom sorting' : 'UNbookmark it+siblings from sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
const orderedChildren: Array<TAbstractFile> = file.parent.children.map((entry: TFile | TFolder) => entry) const orderedChildren: Array<TAbstractFile> = file.parent.children.map((entry: TFile | TFolder) => entry)
bookmarksPlugin.unbookmarkSiblings(orderedChildren) bookmarksPlugin.unbookmarkSiblings(orderedChildren)
@ -415,7 +415,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'Bookmark selected for custom sorting' : 'Custom sort: bookmark selected for sorting'); item.setTitle(m ? 'Bookmark selected for custom sorting' : 'Custom sort: bookmark selected for sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
files.forEach((file) => { files.forEach((file) => {
bookmarksPlugin.bookmarkFolderItem(file) bookmarksPlugin.bookmarkFolderItem(file)
@ -429,7 +429,7 @@ export default class CustomSortPlugin extends Plugin {
(item: MenuItem) => { (item: MenuItem) => {
item.setTitle(m ? 'UNbookmark selected from custom sorting' : 'Custom sort: UNbookmark selected from sorting'); item.setTitle(m ? 'UNbookmark selected from custom sorting' : 'Custom sort: UNbookmark selected from sorting');
item.onClick(() => { item.onClick(() => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
files.forEach((file) => { files.forEach((file) => {
bookmarksPlugin.unbookmarkFolderItem(file) bookmarksPlugin.unbookmarkFolderItem(file)
@ -440,7 +440,7 @@ export default class CustomSortPlugin extends Plugin {
}; };
this.registerEvent( this.registerEvent(
app.workspace.on("file-menu", (menu: Menu, file: TAbstractFile, source: string, leaf?: WorkspaceLeaf) => { this.app.workspace.on("file-menu", (menu: Menu, file: TAbstractFile, source: string, leaf?: WorkspaceLeaf) => {
if (!this.settings.customSortContextSubmenu) return; // Don't show the context menus at all if (!this.settings.customSortContextSubmenu) return; // Don't show the context menus at all
const customSortMenuItem = (item?: MenuItem) => { const customSortMenuItem = (item?: MenuItem) => {
@ -457,7 +457,7 @@ export default class CustomSortPlugin extends Plugin {
if (submenu) submenu.addSeparator(); if (submenu) submenu.addSeparator();
if (this.settings.bookmarksContextMenus) { if (this.settings.bookmarksContextMenus) {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
const itemAlreadyBookmarkedForSorting: boolean = bookmarksPlugin.isBookmarkedForSorting(file) const itemAlreadyBookmarkedForSorting: boolean = bookmarksPlugin.isBookmarkedForSorting(file)
if (!itemAlreadyBookmarkedForSorting) { if (!itemAlreadyBookmarkedForSorting) {
@ -502,7 +502,7 @@ export default class CustomSortPlugin extends Plugin {
if (submenu) submenu.addSeparator(); if (submenu) submenu.addSeparator();
if (this.settings.bookmarksContextMenus) { if (this.settings.bookmarksContextMenus) {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
(submenu ?? menu).addItem(getBookmarkSelectedMenuItemForFiles(files)); (submenu ?? menu).addItem(getBookmarkSelectedMenuItemForFiles(files));
(submenu ?? menu).addItem(getUnbookmarkSelectedMenuItemForFiles(files)); (submenu ?? menu).addItem(getUnbookmarkSelectedMenuItemForFiles(files));
@ -521,16 +521,17 @@ export default class CustomSortPlugin extends Plugin {
} }
this.registerEvent( this.registerEvent(
app.vault.on("rename", (file: TAbstractFile, oldPath: string) => { this.app.vault.on("rename", (file: TAbstractFile, oldPath: string) => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
bookmarksPlugin.updateSortingBookmarksAfterItemRenamed(file, oldPath) bookmarksPlugin.updateSortingBookmarksAfterItemRenamed(file, oldPath)
bookmarksPlugin.saveDataAndUpdateBookmarkViews(true) bookmarksPlugin.saveDataAndUpdateBookmarkViews(true)
} }
}) })
) )
app.vault.on("delete", (file: TAbstractFile) => {
const bookmarksPlugin = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference) this.app.vault.on("delete", (file: TAbstractFile) => {
const bookmarksPlugin = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference)
if (bookmarksPlugin) { if (bookmarksPlugin) {
bookmarksPlugin.updateSortingBookmarksAfterItemDeleted(file) bookmarksPlugin.updateSortingBookmarksAfterItemDeleted(file)
bookmarksPlugin.saveDataAndUpdateBookmarkViews(true) bookmarksPlugin.saveDataAndUpdateBookmarkViews(true)
@ -557,7 +558,7 @@ export default class CustomSortPlugin extends Plugin {
} }
initialize() { initialize() {
app.workspace.onLayoutReady(() => { this.app.workspace.onLayoutReady(() => {
this.fileExplorerFolderPatched = this.patchFileExplorerFolder(); this.fileExplorerFolderPatched = this.patchFileExplorerFolder();
}) })
} }
@ -576,10 +577,10 @@ export default class CustomSortPlugin extends Plugin {
createProcessingContextForSorting(has: HasSortingOrGrouping): ProcessingContext { createProcessingContextForSorting(has: HasSortingOrGrouping): ProcessingContext {
const ctx: ProcessingContext = { const ctx: ProcessingContext = {
_mCache: app.metadataCache, _mCache: this.app.metadataCache,
starredPluginInstance: has.grouping.byStarred ? getStarredPlugin() : undefined, starredPluginInstance: has.grouping.byStarred ? getStarredPlugin(this.app) : undefined,
bookmarksPluginInstance: has.grouping.byBookmarks || has.sorting.byBookmarks ? getBookmarksPlugin(this.settings.bookmarksGroupToConsumeAsOrderingReference, false, true) : undefined, bookmarksPluginInstance: has.grouping.byBookmarks || has.sorting.byBookmarks ? getBookmarksPlugin(this.app, this.settings.bookmarksGroupToConsumeAsOrderingReference, false, true) : undefined,
iconFolderPluginInstance: has.grouping.byIcon ? getIconFolderPlugin() : undefined, iconFolderPluginInstance: has.grouping.byIcon ? getIconFolderPlugin(this.app) : undefined,
plugin: this plugin: this
} }
return ctx return ctx
@ -598,6 +599,7 @@ export default class CustomSortPlugin extends Plugin {
const uninstallerOfFolderSortFunctionWrapper: MonkeyAroundUninstaller = around(Folder.prototype, { const uninstallerOfFolderSortFunctionWrapper: MonkeyAroundUninstaller = around(Folder.prototype, {
sort(old: any) { sort(old: any) {
return function (...args: any[]) { return function (...args: any[]) {
console.log('1')
// quick check for plugin status // quick check for plugin status
if (plugin.settings.suspended) { if (plugin.settings.suspended) {
return old.call(this, ...args); return old.call(this, ...args);
@ -615,13 +617,14 @@ export default class CustomSortPlugin extends Plugin {
// Primary intention: when the implicit bookmarks integration is enabled, remain on std Obsidian, if no need to involve bookmarks // Primary intention: when the implicit bookmarks integration is enabled, remain on std Obsidian, if no need to involve bookmarks
let has: HasSortingOrGrouping = collectSortingAndGroupingTypes(sortSpec) let has: HasSortingOrGrouping = collectSortingAndGroupingTypes(sortSpec)
if (hasOnlyByBookmarkOrStandardObsidian(has)) { if (hasOnlyByBookmarkOrStandardObsidian(has)) {
const bookmarksPlugin: BookmarksPluginInterface|undefined = getBookmarksPlugin(plugin.settings.bookmarksGroupToConsumeAsOrderingReference, false, true) const bookmarksPlugin: BookmarksPluginInterface|undefined = getBookmarksPlugin(plugin.app, plugin.settings.bookmarksGroupToConsumeAsOrderingReference, false, true)
if ( !bookmarksPlugin?.bookmarksIncludeItemsInFolder(folder.path)) { if ( !bookmarksPlugin?.bookmarksIncludeItemsInFolder(folder.path)) {
sortSpec = null sortSpec = null
} }
} }
if (sortSpec) { if (sortSpec) {
console.log('2')
return folderSort.call(this, sortSpec, plugin.createProcessingContextForSorting(has)); return folderSort.call(this, sortSpec, plugin.createProcessingContextForSorting(has));
} else { } else {
return old.call(this, ...args); return old.call(this, ...args);
@ -656,7 +659,7 @@ export default class CustomSortPlugin extends Plugin {
// Credits go to https://github.com/nothingislost/obsidian-bartender // Credits go to https://github.com/nothingislost/obsidian-bartender
getFileExplorer(): FileExplorerView | undefined { getFileExplorer(): FileExplorerView | undefined {
let fileExplorer: FileExplorerView | undefined = app.workspace.getLeavesOfType("file-explorer")?.first() let fileExplorer: FileExplorerView | undefined = this.app.workspace.getLeavesOfType("file-explorer")?.first()
?.view as unknown as FileExplorerView; ?.view as unknown as FileExplorerView;
return fileExplorer; return fileExplorer;
} }

View File

@ -1,4 +1,5 @@
import { import {
App,
InstalledPlugin, InstalledPlugin,
PluginInstance, PluginInstance,
TAbstractFile, TAbstractFile,
@ -110,6 +111,7 @@ const bookmarkedGroupEmptyOrOnlyTransparentForSortingDescendants = (group: Bookm
class BookmarksPluginWrapper implements BookmarksPluginInterface { class BookmarksPluginWrapper implements BookmarksPluginInterface {
app: App
plugin: Bookmarks_PluginInstance|undefined plugin: Bookmarks_PluginInstance|undefined
groupNameForSorting: string|undefined groupNameForSorting: string|undefined
@ -148,7 +150,7 @@ class BookmarksPluginWrapper implements BookmarksPluginInterface {
saveDataAndUpdateBookmarkViews = (updateBookmarkViews: boolean = true) => { saveDataAndUpdateBookmarkViews = (updateBookmarkViews: boolean = true) => {
this.plugin!.onItemsChanged(true) this.plugin!.onItemsChanged(true)
if (updateBookmarkViews) { if (updateBookmarkViews) {
const bookmarksLeafs = app.workspace.getLeavesOfType('bookmarks') const bookmarksLeafs = this.app!.workspace.getLeavesOfType('bookmarks')
bookmarksLeafs?.forEach((leaf) => { bookmarksLeafs?.forEach((leaf) => {
(leaf.view as any)?.update?.() (leaf.view as any)?.update?.()
}) })
@ -259,7 +261,7 @@ class BookmarksPluginWrapper implements BookmarksPluginInterface {
export const BookmarksCorePluginId: string = 'bookmarks' export const BookmarksCorePluginId: string = 'bookmarks'
export const getBookmarksPlugin = (bookmarksGroupName?: string, forceFlushCache?: boolean, ensureCachePopulated?: boolean): BookmarksPluginInterface | undefined => { export const getBookmarksPlugin = (app: App, bookmarksGroupName?: string, forceFlushCache?: boolean, ensureCachePopulated?: boolean): BookmarksPluginInterface | undefined => {
invalidateExpiredBookmarksCache(forceFlushCache) invalidateExpiredBookmarksCache(forceFlushCache)
const installedBookmarksPlugin: InstalledPlugin | undefined = app?.internalPlugins?.getPluginById(BookmarksCorePluginId) const installedBookmarksPlugin: InstalledPlugin | undefined = app?.internalPlugins?.getPluginById(BookmarksCorePluginId)
if (installedBookmarksPlugin && installedBookmarksPlugin.enabled && installedBookmarksPlugin.instance) { if (installedBookmarksPlugin && installedBookmarksPlugin.enabled && installedBookmarksPlugin.instance) {
@ -267,6 +269,7 @@ export const getBookmarksPlugin = (bookmarksGroupName?: string, forceFlushCache?
// defensive programming, in case Obsidian changes its internal APIs // defensive programming, in case Obsidian changes its internal APIs
if (typeof bookmarksPluginInstance?.[BookmarksPlugin_getBookmarks_methodName] === 'function' && if (typeof bookmarksPluginInstance?.[BookmarksPlugin_getBookmarks_methodName] === 'function' &&
Array.isArray(bookmarksPluginInstance?.[BookmarksPlugin_items_collectionName])) { Array.isArray(bookmarksPluginInstance?.[BookmarksPlugin_items_collectionName])) {
bookmarksPlugin.app = app
bookmarksPlugin.plugin = bookmarksPluginInstance bookmarksPlugin.plugin = bookmarksPluginInstance
bookmarksPlugin.groupNameForSorting = bookmarksGroupName bookmarksPlugin.groupNameForSorting = bookmarksGroupName
if (ensureCachePopulated && !bookmarksCache) { if (ensureCachePopulated && !bookmarksCache) {

View File

@ -1,4 +1,4 @@
import {CommunityPlugin, TAbstractFile} from "obsidian"; import {App, CommunityPlugin, TAbstractFile} from "obsidian";
// For https://github.com/FlorianWoelki/obsidian-icon-folder // For https://github.com/FlorianWoelki/obsidian-icon-folder
@ -18,7 +18,7 @@ export interface ObsidianIconFolder_PluginInstance extends CommunityPlugin {
// https://github.com/FlorianWoelki/obsidian-icon-folder/blob/fd9c7df1486744450cec3d7ee9cee2b34d008e56/manifest.json#L2 // https://github.com/FlorianWoelki/obsidian-icon-folder/blob/fd9c7df1486744450cec3d7ee9cee2b34d008e56/manifest.json#L2
export const ObsidianIconFolderPluginId: string = 'obsidian-icon-folder' export const ObsidianIconFolderPluginId: string = 'obsidian-icon-folder'
export const getIconFolderPlugin = (): ObsidianIconFolder_PluginInstance | undefined => { export const getIconFolderPlugin = (app: App): ObsidianIconFolder_PluginInstance | undefined => {
const iconFolderPlugin: CommunityPlugin | undefined = app?.plugins?.plugins?.[ObsidianIconFolderPluginId] const iconFolderPlugin: CommunityPlugin | undefined = app?.plugins?.plugins?.[ObsidianIconFolderPluginId]
if (iconFolderPlugin && iconFolderPlugin._loaded && app?.plugins?.enabledPlugins?.has(ObsidianIconFolderPluginId)) { if (iconFolderPlugin && iconFolderPlugin._loaded && app?.plugins?.enabledPlugins?.has(ObsidianIconFolderPluginId)) {
const iconFolderPluginInstance: ObsidianIconFolder_PluginInstance = iconFolderPlugin as ObsidianIconFolder_PluginInstance const iconFolderPluginInstance: ObsidianIconFolder_PluginInstance = iconFolderPlugin as ObsidianIconFolder_PluginInstance

View File

@ -1,4 +1,4 @@
import {InstalledPlugin, PluginInstance, TAbstractFile, TFile, TFolder} from "obsidian"; import {App, InstalledPlugin, PluginInstance, TAbstractFile, TFile, TFolder} from "obsidian";
export const StarredPlugin_findStarredFile_methodName = 'findStarredFile' export const StarredPlugin_findStarredFile_methodName = 'findStarredFile'
@ -12,7 +12,7 @@ export interface Starred_PluginInstance extends PluginInstance {
export const StarredCorePluginId: string = 'starred' export const StarredCorePluginId: string = 'starred'
export const getStarredPlugin = (): Starred_PluginInstance | undefined => { export const getStarredPlugin = (app: App): Starred_PluginInstance | undefined => {
const starredPlugin: InstalledPlugin | undefined = app?.internalPlugins?.getPluginById(StarredCorePluginId) const starredPlugin: InstalledPlugin | undefined = app?.internalPlugins?.getPluginById(StarredCorePluginId)
if (starredPlugin && starredPlugin.enabled && starredPlugin.instance) { if (starredPlugin && starredPlugin.enabled && starredPlugin.instance) {
const starredPluginInstance: Starred_PluginInstance = starredPlugin.instance as Starred_PluginInstance const starredPluginInstance: Starred_PluginInstance = starredPlugin.instance as Starred_PluginInstance