From f992eda9daaebea0e458ef490277b3704d037cb7 Mon Sep 17 00:00:00 2001 From: Nystik <236107-Nystik@users.noreply.gitlab.com> Date: Wed, 18 Mar 2026 19:30:02 +0100 Subject: [PATCH] improve vault ergonomics. remember last active vault, keep plugin trust on vault rename. --- services/vault-service.js | 19 +++++++++++++++++++ shims/loader.js | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/services/vault-service.js b/services/vault-service.js index 2fbfee6..64a0d85 100644 --- a/services/vault-service.js +++ b/services/vault-service.js @@ -72,6 +72,8 @@ export const vaultService = { body: JSON.stringify({ vault: id, name: newName }), }); + this._migrateLocalStorage(id, newName); + if (id === this.getCurrentVaultId()) { window.__currentVaultId = newName; @@ -112,8 +114,25 @@ export const vaultService = { }, openVault(id) { + localStorage.setItem("last-vault", id); + const target = window.parent !== window ? window.parent : window; target.location.href = "/?vault=" + encodeURIComponent(id); }, + + _migrateLocalStorage(oldId, newId) { + const pluginKey = "enable-plugin-"; + + const oldVal = localStorage.getItem(pluginKey + oldId); + + if (oldVal !== null) { + localStorage.setItem(pluginKey + newId, oldVal); + localStorage.removeItem(pluginKey + oldId); + } + + if (localStorage.getItem("last-vault") === oldId) { + localStorage.setItem("last-vault", newId); + } + }, }; diff --git a/shims/loader.js b/shims/loader.js index 32a41fc..d517d61 100644 --- a/shims/loader.js +++ b/shims/loader.js @@ -182,7 +182,8 @@ window.addEventListener( ); const _urlParams = new URLSearchParams(window.location.search); -window.__currentVaultId = _urlParams.get("vault") || ""; +window.__currentVaultId = + _urlParams.get("vault") || localStorage.getItem("last-vault") || ""; (function initVaultConfig() { try { @@ -199,6 +200,7 @@ window.__currentVaultId = _urlParams.get("vault") || ""; const info = JSON.parse(xhr.responseText); window.__currentVaultId = info.id; + localStorage.setItem("last-vault", info.id); window.__obsidianVersion = info.version || "0.0.0"; window.__vaultConfig = {