Skip to content

Commit

Permalink
Enable source maps in Obsidian 0.14+
Browse files Browse the repository at this point in the history
In Obsidian 14 and above, sourcemaps are stripped from plugins
at load time unless the "debug plugin startup" setting is on.
Hot Reload now automatically switches that option on when
reloading a plugin, so you get sourcemaps while developing,
without needing to keep the debug setting on all the time
(or sourcemaps in memory all the time).
  • Loading branch information
pjeby committed Mar 16, 2022
1 parent 2ef3d5e commit 92dd77d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ module.exports = class HotReload extends Plugin {
await previous;
await plugins.disablePlugin(plugin);
console.debug("disabled", plugin);
await plugins.enablePlugin(plugin);
// Ensure sourcemaps are loaded (Obsidian 14+)
const oldDebug = localStorage.getItem("debug-plugin");
localStorage.setItem("debug-plugin", "1");
try {
await plugins.enablePlugin(plugin);
} finally {
// Restore previous setting
if (oldDebug === null) localStorage.removeItem("debug-plugin"); else localStorage.setItem("debug-plugin", oldDebug);
}
console.debug("enabled", plugin);
new Notice(`Plugin "${plugin}" has been reloaded`);
} catch(e) {}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "hot-reload",
"name": "Hot Reload",
"version": "0.1.8",
"version": "0.1.9",
"minAppVersion": "0.11.13",
"description": "Automatically reload in-development plugins when their files are changed",
"isDesktopOnly": true
Expand Down

0 comments on commit 92dd77d

Please sign in to comment.