Skip to content

Commit

Permalink
feat: add first custom api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Jul 7, 2024
1 parent 4513d68 commit db06926
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/@types/obsidian.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import IconizeAPI from '@app/lib/api';
import {
Editor,
TAbstractFile,
Expand Down Expand Up @@ -67,6 +68,14 @@ declare module 'obsidian' {
}

interface App {
plugins: {
enabledPlugins: Set<string>;
plugins: {
['obsidian-icon-folder']?: {
api: IconizeAPI;
};
};
};
internalPlugins: {
plugins: InternalPlugins;
getPluginById<T extends keyof InternalPlugins>(id: T): InternalPlugins[T];
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import IconizeAPI from './lib/api';
import IconizePlugin from './main';

export function getApi(plugin: IconizePlugin): IconizeAPI | undefined {
return plugin.app.plugins.plugins['obsidian-icon-folder']?.api;
}
19 changes: 19 additions & 0 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import IconizePlugin from '@app/main';

export { AllIconsLoadedEvent } from '@lib/event/events';

export default interface IconizeAPI {
version: {
current: string;
};
}

export function getApi(plugin: IconizePlugin): IconizeAPI {
return {
version: {
get current() {
return plugin.manifest.version;
},
},
};
}
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import {
import ChangeColorModal from './ui/change-color-modal';
import { logger } from './lib/logger';
import { EventEmitter } from './lib/event/event';
import { getApi } from './lib/api';

export interface FolderIconObject {
iconName: string | null;
Expand All @@ -80,9 +81,10 @@ export default class IconizePlugin extends Plugin {
public positionField: PositionField = buildPositionField(this);

private frontmatterCache = new Set<string>();

private eventEmitter = new EventEmitter();

public readonly api = getApi(this);

async onload() {
console.log(`loading ${config.PLUGIN_NAME}`);

Expand Down

0 comments on commit db06926

Please sign in to comment.