diff --git a/manifest.json b/manifest.json index 0962bca..0c53bd4 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "calendar", "name": "Calendar", "description": "Calendar view of your daily notes", - "version": "1.4.16", + "version": "1.4.17", "author": "Liam Cain", "authorUrl": "https://github.com/liamcain/", "isDesktopOnly": false, diff --git a/package.json b/package.json index a200576..5f78a97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "calendar", - "version": "1.4.16", + "version": "1.4.17", "description": "Calendar view of your daily notes", "author": "liamcain", "main": "main.js", diff --git a/src/settings.ts b/src/settings.ts index b4988a1..4625f1e 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -68,6 +68,16 @@ export class CalendarSettingsTab extends PluginSettingTab { display(): void { this.containerEl.empty(); + if (!appHasDailyNotesPluginLoaded()) { + this.containerEl.createEl("h3", { + text: "⚠️ Daily Notes plugin not enabled", + }); + this.containerEl.createEl("p", { + text: + "The calendar is best used in conjunction with the Daily Notes plugin. Enable it in your plugin settings for a more optimal experience.", + }); + } + this.containerEl.createEl("h3", { text: "General Settings", }); @@ -85,16 +95,6 @@ export class CalendarSettingsTab extends PluginSettingTab { this.addWeeklyNoteFolderSetting(); } - if (!appHasDailyNotesPluginLoaded()) { - this.containerEl.createEl("h3", { - text: "⚠️ Daily Notes plugin not enabled", - }); - this.containerEl.createEl("p", { - text: - "The calendar is best used in conjunction with the Daily Notes plugin. Enable it in your plugin settings for a more optimal experience.", - }); - } - this.containerEl.createEl("h3", { text: "Advanced Settings", }); diff --git a/src/ui/stores.ts b/src/ui/stores.ts index ed7e73d..17f705b 100644 --- a/src/ui/stores.ts +++ b/src/ui/stores.ts @@ -1,15 +1,30 @@ -import type { TFile } from "obsidian"; -import { get, writable } from "svelte/store"; +import { Notice, TFile } from "obsidian"; import { getAllDailyNotes } from "obsidian-daily-notes-interface"; +import { get, writable } from "svelte/store"; import { defaultSettings, ISettings } from "src/settings"; import { getDateUIDFromFile } from "./utils"; function createDailyNotesStore() { + let hasError = false; const store = writable>(null); return { - reindex: () => store.set(getAllDailyNotes()), + reindex: () => { + try { + const dailyNotes = getAllDailyNotes(); + store.set(dailyNotes); + hasError = false; + } catch (err) { + if (!hasError) { + // Avoid error being shown multiple times + new Notice("Failed to find your Daily Note folder"); + console.log("[Calendar] Failed to find daily notes folder", err); + } + store.set({}); + hasError = true; + } + }, ...store, }; } diff --git a/src/view.ts b/src/view.ts index 799b4fd..fd53141 100644 --- a/src/view.ts +++ b/src/view.ts @@ -178,7 +178,7 @@ export default class CalendarView extends ItemView { private async onFileModified(file: TFile): Promise { const date = getDateFromFile(file); - if (date) { + if (date && this.calendar) { this.calendar.tick(); } } @@ -186,7 +186,7 @@ export default class CalendarView extends ItemView { private onFileCreated(file: TFile): void { if (this.app.workspace.layoutReady) { const date = getDateFromFile(file); - if (date) { + if (date && this.calendar) { dailyNotes.reindex(); this.calendar.tick(); } @@ -207,7 +207,10 @@ export default class CalendarView extends ItemView { file = view.file; } activeFile.setFile(file); - this.calendar.tick(); + + if (this.calendar) { + this.calendar.tick(); + } } public revealActiveNote(): void {