pjeby / hot-reload

Automatically reload Obsidian plugins in development when their files are changed
ISC License
496 stars 23 forks source link

add logging to hot-reload.md for mobile hot reload #1

Closed shabegom closed 2 years ago

shabegom commented 2 years ago

This is a change to support the Hot Reload Mobile plugin I've developed. Hot Reload mobile looks for changes to a hot-reload.md file in the mobile vault. When it sees a change in that file, it reloads the specified plugin.

This code change is to log the latest plugin reloaded on the Desktop to hot-reload.md. It looks for the TFile and if that file exists in the vault it writes the plugin id to it.

Maybe there are better ways to do this? probably, but this seems to work.

pjeby commented 2 years ago

I'd be happy with adding an event to allow you to do this from another plugin, but writing a log file as a note file is not something I want to support in this plugin.

My suggestion, though, would be to simply change Hot Reload Mobile to use something like this as the else branch of the if this.app.isMobile in onload():

this.register(around(this.app.plugins, {enablePlugin(old) { return async function(...args) {
    const result = await old.apply(this, args);
    // code here to write log file
    return result;
}}}));

If you don't want your plugin to need a build step, just copy the around and around1 functions from this file into your module.

Anyway, once you have the above code in your plugin, people just need to install it on both the mobile and desktop they're using, and you're all good.

shabegom commented 2 years ago

Ah cool, I knew you'd have a better way :)

I'll go ahead and implement your suggestion