fix: homelab setup form liest entry werte direkt per setup-ref statt closure-variablen, saveConfig mit try/catch und rebuild()
This commit is contained in:
@@ -9,11 +9,16 @@ const CONFIG_PATH = GLib.getenv("HOMELAB_CONFIG") || `${GLib.getenv("HOME")}/.co
|
|||||||
|
|
||||||
function saveConfig(host: string, user: string, port: string) {
|
function saveConfig(host: string, user: string, port: string) {
|
||||||
const yaml = `# Homelab Configuration\ngenerated_by: Omeron\n\nserver:\n address: "${host}"\n username: "${user}"\n port: ${port}\n\ncontrol_center:\n refresh_interval: 5\n theme: "dark"\n\nfeatures:\n docker: true\n services: true\n storage: true\n network: true\n monitoring: true\n`;
|
const yaml = `# Homelab Configuration\ngenerated_by: Omeron\n\nserver:\n address: "${host}"\n username: "${user}"\n port: ${port}\n\ncontrol_center:\n refresh_interval: 5\n theme: "dark"\n\nfeatures:\n docker: true\n services: true\n storage: true\n network: true\n monitoring: true\n`;
|
||||||
GLib.mkdir_with_parents(GLib.path_get_dirname(CONFIG_PATH), 0o755);
|
try {
|
||||||
GLib.file_set_contents(CONFIG_PATH, yaml);
|
GLib.mkdir_with_parents(GLib.path_get_dirname(CONFIG_PATH), 0o755);
|
||||||
|
const ok = GLib.file_set_contents(CONFIG_PATH, yaml);
|
||||||
|
print(`[homelab] save: dir created, write=${ok}`);
|
||||||
|
} catch (e) {
|
||||||
|
print(`[homelab] save error: ${e}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
hasConfig = true;
|
hasConfig = true;
|
||||||
const win = app.get_window("homelab-control");
|
rebuild();
|
||||||
if (win) win.set_child(<box marginTop={WINDOW_MARGIN_TOP}>{!hasConfig ? <SetupView /> : (authed ? <DashboardView /> : <LoginView />)}</box> as Gtk.Widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig() {
|
||||||
@@ -1126,9 +1131,16 @@ function startRefreshTimer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SetupView() {
|
function SetupView() {
|
||||||
let host = "";
|
let hostEntry: Gtk.Entry | null = null;
|
||||||
let user = "root";
|
let userEntry: Gtk.Entry | null = null;
|
||||||
let port = "22";
|
let portEntry: Gtk.Entry | null = null;
|
||||||
|
|
||||||
|
function doSave() {
|
||||||
|
if (!hostEntry || !userEntry || !portEntry) return;
|
||||||
|
const host = hostEntry.get_text();
|
||||||
|
if (!host) return;
|
||||||
|
saveConfig(host, userEntry.get_text() || "root", portEntry.get_text() || "22");
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<box class="login-panel" orientation={Gtk.Orientation.VERTICAL} spacing={14}>
|
<box class="login-panel" orientation={Gtk.Orientation.VERTICAL} spacing={14}>
|
||||||
@@ -1137,38 +1149,29 @@ function SetupView() {
|
|||||||
<label class="subtitle" xalign={0} label="Ersteinrichtung — Serververbindung konfigurieren" />
|
<label class="subtitle" xalign={0} label="Ersteinrichtung — Serververbindung konfigurieren" />
|
||||||
</box>
|
</box>
|
||||||
<entry
|
<entry
|
||||||
|
setup={self => { hostEntry = self; }}
|
||||||
placeholderText="Server-Adresse (IP oder Domain)"
|
placeholderText="Server-Adresse (IP oder Domain)"
|
||||||
hexpand
|
hexpand
|
||||||
onChanged={entry => { host = entry.get_text(); }}
|
onActivate={doSave}
|
||||||
onActivate={() => {
|
|
||||||
if (host && user && port) saveConfig(host, user, port);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<entry
|
<entry
|
||||||
|
setup={self => { userEntry = self; }}
|
||||||
placeholderText="SSH-Benutzer"
|
placeholderText="SSH-Benutzer"
|
||||||
text="root"
|
text="root"
|
||||||
hexpand
|
hexpand
|
||||||
onChanged={entry => { user = entry.get_text() || "root"; }}
|
onActivate={doSave}
|
||||||
onActivate={() => {
|
|
||||||
if (host && user && port) saveConfig(host, user, port);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<entry
|
<entry
|
||||||
|
setup={self => { portEntry = self; }}
|
||||||
placeholderText="SSH-Port"
|
placeholderText="SSH-Port"
|
||||||
text="22"
|
text="22"
|
||||||
hexpand
|
hexpand
|
||||||
onChanged={entry => { port = entry.get_text() || "22"; }}
|
onActivate={doSave}
|
||||||
onActivate={() => {
|
|
||||||
if (host && user && port) saveConfig(host, user, port);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="button primary"
|
class="button primary"
|
||||||
label="Speichern"
|
label="Speichern"
|
||||||
onClicked={() => {
|
onClicked={doSave}
|
||||||
if (!host) return;
|
|
||||||
saveConfig(host, user, port);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</box>
|
</box>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user