improve vault ergonomics. remember last active vault, keep plugin trust on vault rename.
This commit is contained in:
parent
2418f125f0
commit
f992eda9da
2 changed files with 22 additions and 1 deletions
|
|
@ -72,6 +72,8 @@ export const vaultService = {
|
||||||
body: JSON.stringify({ vault: id, name: newName }),
|
body: JSON.stringify({ vault: id, name: newName }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._migrateLocalStorage(id, newName);
|
||||||
|
|
||||||
if (id === this.getCurrentVaultId()) {
|
if (id === this.getCurrentVaultId()) {
|
||||||
window.__currentVaultId = newName;
|
window.__currentVaultId = newName;
|
||||||
|
|
||||||
|
|
@ -112,8 +114,25 @@ export const vaultService = {
|
||||||
},
|
},
|
||||||
|
|
||||||
openVault(id) {
|
openVault(id) {
|
||||||
|
localStorage.setItem("last-vault", id);
|
||||||
|
|
||||||
const target = window.parent !== window ? window.parent : window;
|
const target = window.parent !== window ? window.parent : window;
|
||||||
|
|
||||||
target.location.href = "/?vault=" + encodeURIComponent(id);
|
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);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -182,7 +182,8 @@ window.addEventListener(
|
||||||
);
|
);
|
||||||
|
|
||||||
const _urlParams = new URLSearchParams(window.location.search);
|
const _urlParams = new URLSearchParams(window.location.search);
|
||||||
window.__currentVaultId = _urlParams.get("vault") || "";
|
window.__currentVaultId =
|
||||||
|
_urlParams.get("vault") || localStorage.getItem("last-vault") || "";
|
||||||
|
|
||||||
(function initVaultConfig() {
|
(function initVaultConfig() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -199,6 +200,7 @@ window.__currentVaultId = _urlParams.get("vault") || "";
|
||||||
const info = JSON.parse(xhr.responseText);
|
const info = JSON.parse(xhr.responseText);
|
||||||
|
|
||||||
window.__currentVaultId = info.id;
|
window.__currentVaultId = info.id;
|
||||||
|
localStorage.setItem("last-vault", info.id);
|
||||||
window.__obsidianVersion = info.version || "0.0.0";
|
window.__obsidianVersion = info.version || "0.0.0";
|
||||||
|
|
||||||
window.__vaultConfig = {
|
window.__vaultConfig = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue