From 7d377dc99dff0dbbb5b783a6aa91e1f36d9cc089 Mon Sep 17 00:00:00 2001 From: Felvesthe <23108389+Felvesthe@users.noreply.github.com> Date: Tue, 2 Dec 2025 00:12:34 +0100 Subject: [PATCH] Add file existence check & fix an issue that allowed notifications to show even if disabled for strict lock Signed-off-by: Felvesthe <23108389+Felvesthe@users.noreply.github.com> --- src/main.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main.ts b/src/main.ts index 09f0779..da37574 100644 --- a/src/main.ts +++ b/src/main.ts @@ -409,15 +409,26 @@ export default class NoteLockerPlugin extends Plugin { async toggleStrictLock(notePath: string) { const isStrictLocked = this.settings.strictLockedNotes.has(notePath); - if (isStrictLocked) { - this.settings.strictLockedNotes.delete(notePath); - } else { - this.settings.strictLockedNotes.add(notePath); - } + isStrictLocked + ? this.settings.strictLockedNotes.delete(notePath) + : this.settings.strictLockedNotes.add(notePath); await this.saveSettings(); - new Notice(`${isStrictLocked ? '🔓 Strictly unlocked' : '🔒 Strictly locked'}: ${notePath}`); + const file = this.app.vault.getAbstractFileByPath(notePath); + + if (!file) { + new Notice("Error: Note not found"); + return; + } + + if (this.settings.showNotifications) { + const fileName = file instanceof TFile ? file.basename : + notePath.split('/').pop()?.replace(/\..+$/, '') || notePath; + const displayName = this.truncateFileName(fileName); + + new Notice(`${isStrictLocked ? '🔓 Strictly unlocked' : '🔒 Strictly locked'}: ${displayName}`); + } this.updateAllNoteInstances(notePath); this.statusBarUI.updateStatusBarButton();