diff --git a/dotfiles/hypr/ags/homelab.tsx b/dotfiles/hypr/ags/homelab.tsx index c4a9e55..768cebc 100644 --- a/dotfiles/hypr/ags/homelab.tsx +++ b/dotfiles/hypr/ags/homelab.tsx @@ -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({!hasConfig ? : (authed ? : )} 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 ( @@ -1137,38 +1149,29 @@ function SetupView() { { 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} /> { 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} /> { 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} />