fix: Popup-UX und Fehlerbehandlung verbessern

- Space-Verlust behoben: refreshSpaces() speichert vor dem API-Call nur noch apiBase/apiKey, nicht die leere spaceId
- Button "Auswahl sichern" → "Einstellungen sichern": speichert jetzt nur die Einstellungen, kein Web-Clip mehr
- Kontextmenü-Fehler werden per Browser-Notification angezeigt (notifications-Permission ergänzt)
- Verständliche Fehlermeldungen bei nicht erreichbarem Anytype (TypeError) und falschem API-Key (401)
This commit is contained in:
Andre
2026-04-15 20:28:23 +02:00
parent 247bd31f20
commit 6b11e14928
4 changed files with 50 additions and 4 deletions
+28 -3
View File
@@ -9,7 +9,7 @@ const status = document.getElementById("status");
document.getElementById("refreshSpaces").addEventListener("click", refreshSpaces);
document.getElementById("savePage").addEventListener("click", () => saveClip("full"));
document.getElementById("saveSelection").addEventListener("click", () => saveClip("selection"));
document.getElementById("saveSelection").addEventListener("click", saveSettingsOnly);
bootstrap().catch(showError);
@@ -25,9 +25,20 @@ function populateForm(settings) {
form.objectType.value = settings.objectType || "page";
}
async function saveSettingsOnly() {
await persistForm();
setStatus("Einstellungen gespeichert.");
}
async function refreshSpaces(selectedSpaceId = form.spaceId.value) {
setStatus("Lade Spaces ...");
await persistForm();
await browser.runtime.sendMessage({
type: "save-settings",
payload: {
apiBase: form.apiBase.value.trim(),
apiKey: form.apiKey.value.trim()
}
});
try {
const response = await browser.runtime.sendMessage({ type: "list-spaces" });
@@ -101,7 +112,21 @@ function readForm() {
}
function showError(error) {
setStatus(error?.message || String(error));
setStatus(formatErrorMessage(error));
}
function formatErrorMessage(error) {
if (error instanceof TypeError) {
return "Anytype ist nicht erreichbar. Ist Anytype Desktop gestartet? Stimmt die API-URL?";
}
const msg = error?.message || "";
if (msg.includes("(401)")) {
return "Zugriff verweigert. Bitte den API-Key prüfen.";
}
return msg || String(error);
}
function setStatus(message) {