mirror of
https://github.com/Andre-Bzk/AnyClip.git
synced 2026-11-15 15:43:07 +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:
+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