2025-11-21 11:51:08 +00:00
|
|
|
import { Plugin, TFile } from "obsidian";
|
|
|
|
|
import { FrontmatterStatusStore } from "./statusStores/frontmatterStatusStore";
|
|
|
|
|
import { NonMarkdownStatusStore } from "./statusStores/nonMarkdownStatusStore";
|
|
|
|
|
import { StatusStore } from "./statusStores/types";
|
|
|
|
|
|
|
|
|
|
class StatusStoreManager {
|
|
|
|
|
private stores: StatusStore[] = [];
|
2026-03-18 11:43:18 +00:00
|
|
|
private nonMarkdownStore: NonMarkdownStatusStore | null = null;
|
2025-11-21 11:51:08 +00:00
|
|
|
|
|
|
|
|
async initialize(plugin: Plugin) {
|
|
|
|
|
const frontmatterStore = new FrontmatterStatusStore(plugin.app);
|
|
|
|
|
this.stores = [frontmatterStore];
|
|
|
|
|
|
2026-03-18 11:43:18 +00:00
|
|
|
this.nonMarkdownStore = new NonMarkdownStatusStore(plugin);
|
|
|
|
|
await this.nonMarkdownStore.initialize();
|
|
|
|
|
this.registerStore(this.nonMarkdownStore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getNonMarkdownStore(): NonMarkdownStatusStore {
|
|
|
|
|
if (!this.nonMarkdownStore) {
|
|
|
|
|
throw new Error("NonMarkdownStatusStore is not initialized");
|
|
|
|
|
}
|
|
|
|
|
return this.nonMarkdownStore;
|
2025-11-21 11:51:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
registerStore(store: StatusStore) {
|
|
|
|
|
this.stores.push(store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getStoreForFile(file: TFile): StatusStore {
|
|
|
|
|
const store = this.stores.find((candidate) =>
|
|
|
|
|
candidate.canHandle(file),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!store) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
`No status store registered for file type: ${file.extension}`,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return store;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new StatusStoreManager();
|