diff --git a/main.ts b/main.ts index 3a0d521..553a553 100644 --- a/main.ts +++ b/main.ts @@ -14,7 +14,7 @@ import { ObsidianPluginMtgSettings } from "src/settings"; import { parseCodeBlockOptions, applyShowOverrides } from "src/code-block-options"; import { CollectionModal } from "src/collection-modal"; import { renderCollection } from "src/collection-renderer"; -import { loadCache, getCache, clearCache } from "src/cache"; +import { loadCache, getCache, clearCache, CachedCardData } from "src/cache"; const DEFAULT_SETTINGS: ObsidianPluginMtgSettings = { collection: { @@ -33,6 +33,16 @@ const DEFAULT_SETTINGS: ObsidianPluginMtgSettings = { }, }; +interface PluginData { + settings?: Partial; + collectionHash?: string; + cardDataCache?: Record; +} + +const loadPluginData = async (plugin: Plugin): Promise => { + return (await plugin.loadData() as PluginData) ?? {}; +}; + export default class ObsidianPluginMtg extends Plugin { settings: ObsidianPluginMtgSettings; @@ -65,8 +75,8 @@ export default class ObsidianPluginMtg extends Plugin { const hash = hashCollectionContents(this.collections); - const savedData = await this.loadData(); - if (savedData?.collectionHash === hash && savedData?.cardDataCache) { + const savedData = await loadPluginData(this); + if (savedData.collectionHash === hash && savedData.cardDataCache) { loadCache(savedData.cardDataCache); } }); @@ -114,7 +124,7 @@ export default class ObsidianPluginMtg extends Plugin { onunload() { void (async () => { const hash = hashCollectionContents(this.collections); - const data = await this.loadData() ?? {}; + const data = await loadPluginData(this); await this.saveData({ ...data, @@ -126,16 +136,16 @@ export default class ObsidianPluginMtg extends Plugin { } async loadSettings() { - const data = await this.loadData(); + const data = await loadPluginData(this); this.settings = Object.assign( {}, DEFAULT_SETTINGS, - data?.settings as Partial + data.settings ); } async saveSettings() { - const data = await this.loadData() ?? {}; + const data = await loadPluginData(this); await this.saveData({ ...data, settings: this.settings, diff --git a/manifest.json b/manifest.json index c1d8394..381cc75 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "mtg-deck", "name": "MTG Deck", - "version": "1.14.128", + "version": "1.14.129", "minAppVersion": "1.5.7", "description": "Display your MTG decks and card lists in your notes.", "author": "Samir Boulema", diff --git a/package.json b/package.json index c0a9473..b93f3ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mtg-deck", - "version": "1.14.128", + "version": "1.14.129", "description": "Display your MTG decks and card lists in your notes.", "main": "main.js", "scripts": { diff --git a/src/cache.ts b/src/cache.ts index 249c187..1e38c3c 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,6 +1,6 @@ import { CardData } from "./scryfall"; -interface CachedCardData { +export interface CachedCardData { data: CardData; } diff --git a/src/collection-modal.ts b/src/collection-modal.ts index a03ece1..4b59a10 100644 --- a/src/collection-modal.ts +++ b/src/collection-modal.ts @@ -1,5 +1,5 @@ import { App, Modal } from "obsidian"; -import { CardCollection, CardCounts } from "./collection"; +import { CardCollection } from "./collection"; import { renderCollection } from "./collection-renderer"; export class CollectionModal extends Modal { diff --git a/versions.json b/versions.json index e10ce11..21a17ee 100644 --- a/versions.json +++ b/versions.json @@ -28,5 +28,6 @@ "1.12.88": "1.1.0", "1.13.105": "1.5.7", "1.13.106": "1.5.7", - "1.14.128": "1.5.7" + "1.14.128": "1.5.7", + "1.14.129": "1.5.7" } \ No newline at end of file