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>
This commit is contained in:
Felvesthe 2025-12-02 00:12:34 +01:00
parent cd4ecd7821
commit 7d377dc99d

View file

@ -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();