From 6b11e14928a80c500c566e4d888026bca4851a82 Mon Sep 17 00:00:00 2001 From: Andre <200930841+Andre-Bzk@users.noreply.github.com> Date: Wed, 15 Apr 2026 20:28:23 +0200 Subject: [PATCH] fix: Popup-UX und Fehlerbehandlung verbessern MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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) --- manifest.json | 1 + src/background.js | 20 ++++++++++++++++++++ src/popup/popup.html | 2 +- src/popup/popup.js | 31 ++++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 3b87983..0305a33 100644 --- a/manifest.json +++ b/manifest.json @@ -8,6 +8,7 @@ "storage", "tabs", "menus", + "notifications", "" ], "icons": { diff --git a/src/background.js b/src/background.js index bb6f0db..1400c77 100644 --- a/src/background.js +++ b/src/background.js @@ -56,6 +56,12 @@ browser.menus.onClicked.addListener(async (info, tab) => { } } catch (error) { console.error("Anytype clip failed", error); + browser.notifications.create({ + type: "basic", + iconUrl: browser.runtime.getURL("src/assets/icon.svg"), + title: "AnyClip – Fehler", + message: formatErrorMessage(error) + }); } }); @@ -263,6 +269,20 @@ function truncate(value, maxLength) { return value.length > maxLength ? `${value.slice(0, maxLength - 1)}...` : value; } +function formatErrorMessage(error) { + if (error instanceof TypeError) { + return "Anytype ist nicht erreichbar. Bitte prüfen: Ist Anytype Desktop gestartet? Stimmt die API-URL (Standard: http://localhost:31009)?"; + } + + const msg = error?.message || ""; + + if (msg.includes("(401)")) { + return "Zugriff verweigert. Bitte den API-Key im Addon-Popup prüfen."; + } + + return msg || "Unbekannter Fehler"; +} + function escapeMarkdownInline(value) { return String(value || "").replace(/([\\`*_{}[\]()#+\-.!])/g, "\\$1"); } diff --git a/src/popup/popup.html b/src/popup/popup.html index 264e045..6c5577e 100644 --- a/src/popup/popup.html +++ b/src/popup/popup.html @@ -39,7 +39,7 @@
- +

diff --git a/src/popup/popup.js b/src/popup/popup.js index de02fe1..d5f8d16 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -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) {