mirror of
https://github.com/Andre-Bzk/AnyClip.git
synced 2026-11-15 09:33:08 +01:00
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:
@@ -8,6 +8,7 @@
|
||||
"storage",
|
||||
"tabs",
|
||||
"menus",
|
||||
"notifications",
|
||||
"<all_urls>"
|
||||
],
|
||||
"icons": {
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
<div class="actions">
|
||||
<button id="savePage" type="button">Ganze Seite sichern</button>
|
||||
<button id="saveSelection" type="button" class="ghost">Auswahl sichern</button>
|
||||
<button id="saveSelection" type="button" class="ghost">Einstellungen sichern</button>
|
||||
</div>
|
||||
|
||||
<p id="status" class="status"></p>
|
||||
|
||||
+28
-3
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user