From a1abaf2e460005455082387d1fd01ef5dfbd9d64 Mon Sep 17 00:00:00 2001 From: Tian Jamin <1728827724@qq.com> Date: Wed, 25 Mar 2026 09:04:34 +0800 Subject: [PATCH] Repair: the awkward refreshment to top after edition on tasks and the wrong display of customized view. --- src/dataflow/api/WriteAPI.ts | 8 ++++- src/managers/habit-manager.ts | 4 +-- src/utils/obsidian-daily-notes.ts | 57 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 src/utils/obsidian-daily-notes.ts diff --git a/src/dataflow/api/WriteAPI.ts b/src/dataflow/api/WriteAPI.ts index a22cba3d..e2982ac8 100644 --- a/src/dataflow/api/WriteAPI.ts +++ b/src/dataflow/api/WriteAPI.ts @@ -15,7 +15,7 @@ import { getDailyNote, appHasDailyNotesPluginLoaded, getDailyNoteSettings, -} from "obsidian-daily-notes-interface"; +} from "@/utils/obsidian-daily-notes"; import { saveCapture, processDateTemplates, @@ -1912,6 +1912,12 @@ export class WriteAPI { // Append under optional heading const file = dailyNoteFile; + if (!file) { + return { + success: false, + error: "Failed to resolve daily note file", + }; + } const current = await this.vault.read(file); let newContent = current; diff --git a/src/managers/habit-manager.ts b/src/managers/habit-manager.ts index eacfd96d..ddb1111e 100644 --- a/src/managers/habit-manager.ts +++ b/src/managers/habit-manager.ts @@ -28,7 +28,7 @@ import { getDateFromFile, appHasDailyNotesPluginLoaded, getDailyNoteSettings, -} from "obsidian-daily-notes-interface"; +} from "@/utils/obsidian-daily-notes"; import { Events, on, emit } from "../dataflow/events/Events"; import { DateInheritanceService } from "../services/date-inheritance-service"; @@ -228,7 +228,7 @@ export class HabitManager extends Component { private async getDailyNotes(): Promise { const files = getAllDailyNotes(); - return Object.values(files); + return files.map((entry) => entry.file); } private isDailyNote(file: TFile): boolean { diff --git a/src/utils/obsidian-daily-notes.ts b/src/utils/obsidian-daily-notes.ts new file mode 100644 index 00000000..75621ec2 --- /dev/null +++ b/src/utils/obsidian-daily-notes.ts @@ -0,0 +1,57 @@ +import type { TFile } from "obsidian"; +import { + appHasDailyNotesPluginLoaded as dailyNotesPluginLoadedUnsafe, + createDailyNote as createDailyNoteUnsafe, + getAllDailyNotes as getAllDailyNotesUnsafe, + getDailyNote as getDailyNoteUnsafe, + getDailyNoteSettings as getDailyNoteSettingsUnsafe, + getDateFromFile as getDateFromFileUnsafe, +} from "obsidian-daily-notes-interface"; + +export interface DailyNoteSettings { + folder?: string; + format?: string; + template?: string; +} + +export interface DailyNoteEntry { + file: TFile; + date: unknown; +} + +// The upstream package ships its own obsidian dependency, which produces a +// second TFile type. Centralize the boundary here so the rest of the codebase +// can stay on our local obsidian types. +export function appHasDailyNotesPluginLoaded(): boolean { + return Boolean(dailyNotesPluginLoadedUnsafe()); +} + +export async function createDailyNote(date: unknown): Promise { + return (await createDailyNoteUnsafe(date as never)) as unknown as TFile; +} + +export function getAllDailyNotes(): DailyNoteEntry[] { + return getAllDailyNotesUnsafe() as unknown as DailyNoteEntry[]; +} + +export function getDailyNote( + date: unknown, + dailyNotes: DailyNoteEntry[], +): TFile | null { + const file = getDailyNoteUnsafe( + date as never, + dailyNotes as never, + ) as unknown as TFile | null | undefined; + return file ?? null; +} + +export function getDailyNoteSettings(): DailyNoteSettings { + return getDailyNoteSettingsUnsafe() as unknown as DailyNoteSettings; +} + +export function getDateFromFile(file: TFile, granularity?: string): any { + return getDateFromFileUnsafe( + file as never, + granularity as never, + ) as any; +}