I have my plugin listen to the create-event. I noticed, that the create-event is fired on startup for the file, that Obsidian opens automatically, even if the note existed previously!
Let me know if I can help in any way. If this won’t/ can’t be fixed: Why does this behaviour exist in the first place? I’d argue that dispatching the create-event even if nothing is newly created is unintuitive.
I created a plugin that keeps track of all the files I have in my vault, and I want to do changes to my plugin data when files are created/renamed/deleted, and when I do a “create” event - it triggers on every file in my vault every time I open Obsidian, where I expect it to trigger ONLY if I add a new file through drag and drop or creating a new note
It happens because in the startup Obsidian loads the files in the vault, and newly loaded files are treated as “created” at that time. It sounds strange but that’s how it works.
To prevent your create event handler from being invoked at the startup, put it inside Workspace.onLayoutReady, like so:
this.app.workspace.onLayoutReady(() => {
this.registerEvent(
this.app.vault.on('create', (file) => {
// do some stuff
})
)
})