refined client configuration manager flow
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
let saving = false;
|
||||
let errorMessage = "";
|
||||
let successMessage = "";
|
||||
let restartError = "";
|
||||
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
@@ -36,11 +37,51 @@
|
||||
}
|
||||
};
|
||||
|
||||
const validate = () => {
|
||||
if (!form.auth.auth_url.trim()) {
|
||||
return "Auth URL is required";
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = new URL(form.auth.auth_url.trim());
|
||||
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
||||
return "Auth URL must start with http or https";
|
||||
}
|
||||
} catch (e) {
|
||||
return "Auth URL must be a valid URL";
|
||||
}
|
||||
|
||||
if (!form.auth.audience.trim()) {
|
||||
return "JWT audience is required";
|
||||
}
|
||||
|
||||
if (form.api_base_url?.trim()) {
|
||||
try {
|
||||
const parsed = new URL(
|
||||
form.api_base_url.trim().startsWith("http")
|
||||
? form.api_base_url.trim()
|
||||
: `https://${form.api_base_url.trim()}`
|
||||
);
|
||||
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
||||
return "API base URL must start with http or https";
|
||||
}
|
||||
} catch (e) {
|
||||
return "API base URL must be a valid URL";
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
const save = async () => {
|
||||
if (saving) return;
|
||||
errorMessage = validate();
|
||||
if (errorMessage) return;
|
||||
|
||||
saving = true;
|
||||
errorMessage = "";
|
||||
successMessage = "";
|
||||
restartError = "";
|
||||
try {
|
||||
await invoke("save_client_config", {
|
||||
config: {
|
||||
@@ -52,8 +93,7 @@
|
||||
},
|
||||
});
|
||||
|
||||
successMessage = "Configuration saved. Please restart the app.";
|
||||
await invoke("restart_app");
|
||||
successMessage = "Configuration saved. Restart to apply changes.";
|
||||
} catch (err) {
|
||||
errorMessage = `Failed to save config: ${err}`;
|
||||
} finally {
|
||||
@@ -61,6 +101,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
const restart = async () => {
|
||||
restartError = "";
|
||||
try {
|
||||
await invoke("restart_app");
|
||||
} catch (err) {
|
||||
restartError = `Restart failed: ${err}`;
|
||||
}
|
||||
};
|
||||
|
||||
onMount(loadConfig);
|
||||
</script>
|
||||
|
||||
@@ -95,7 +144,10 @@
|
||||
{#if successMessage}
|
||||
<p class="text-sm text-success">{successMessage}</p>
|
||||
{/if}
|
||||
|
||||
{#if restartError}
|
||||
<p class="text-sm text-error">{restartError}</p>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-row gap-2">
|
||||
<button
|
||||
class="btn"
|
||||
@@ -105,5 +157,9 @@
|
||||
>
|
||||
{saving ? "Saving..." : "Save"}
|
||||
</button>
|
||||
<button class="btn btn-outline" on:click={restart}>
|
||||
Restart app
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user