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) {
|
||||
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);
|
||||
GLib.file_set_contents(CONFIG_PATH, yaml);
|
||||
try {
|
||||
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;
|
||||
const win = app.get_window("homelab-control");
|
||||
if (win) win.set_child(<box marginTop={WINDOW_MARGIN_TOP}>{!hasConfig ? <SetupView /> : (authed ? <DashboardView /> : <LoginView />)}</box> as Gtk.Widget);
|
||||
rebuild();
|
||||
}
|
||||
|
||||
function loadConfig() {
|
||||
@@ -1126,9 +1131,16 @@ function startRefreshTimer() {
|
||||
}
|
||||
|
||||
function SetupView() {
|
||||
let host = "";
|
||||
let user = "root";
|
||||
let port = "22";
|
||||
let hostEntry: Gtk.Entry | null = null;
|
||||
let userEntry: Gtk.Entry | null = null;
|
||||
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 (
|
||||
<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" />
|
||||
</box>
|
||||
<entry
|
||||
setup={self => { hostEntry = self; }}
|
||||
placeholderText="Server-Adresse (IP oder Domain)"
|
||||
hexpand
|
||||
onChanged={entry => { host = entry.get_text(); }}
|
||||
onActivate={() => {
|
||||
if (host && user && port) saveConfig(host, user, port);
|
||||
}}
|
||||
onActivate={doSave}
|
||||
/>
|
||||
<entry
|
||||
setup={self => { userEntry = self; }}
|
||||
placeholderText="SSH-Benutzer"
|
||||
text="root"
|
||||
hexpand
|
||||
onChanged={entry => { user = entry.get_text() || "root"; }}
|
||||
onActivate={() => {
|
||||
if (host && user && port) saveConfig(host, user, port);
|
||||
}}
|
||||
onActivate={doSave}
|
||||
/>
|
||||
<entry
|
||||
setup={self => { portEntry = self; }}
|
||||
placeholderText="SSH-Port"
|
||||
text="22"
|
||||
hexpand
|
||||
onChanged={entry => { port = entry.get_text() || "22"; }}
|
||||
onActivate={() => {
|
||||
if (host && user && port) saveConfig(host, user, port);
|
||||
}}
|
||||
onActivate={doSave}
|
||||
/>
|
||||
<button
|
||||
class="button primary"
|
||||
label="Speichern"
|
||||
onClicked={() => {
|
||||
if (!host) return;
|
||||
saveConfig(host, user, port);
|
||||
}}
|
||||
onClicked={doSave}
|
||||
/>
|
||||
</box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user