desktop version (100% AI I have 0 idea what I'm doing with electron tf)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
const form = document.getElementById("connect-form");
|
||||
const hostInput = document.getElementById("host");
|
||||
const portInput = document.getElementById("port");
|
||||
const tlsCheckbox = document.getElementById("use-tls");
|
||||
const connectBtn = document.getElementById("connect-btn");
|
||||
const statusEl = document.getElementById("status");
|
||||
|
||||
function setStatus(msg, type = "info") {
|
||||
statusEl.className = `status ${type}`;
|
||||
statusEl.innerHTML = msg;
|
||||
}
|
||||
|
||||
// Load saved connection on startup
|
||||
(async () => {
|
||||
try {
|
||||
const saved = await window.overlord.getSavedConnection();
|
||||
if (saved) {
|
||||
hostInput.value = saved.host;
|
||||
portInput.value = String(saved.port);
|
||||
tlsCheckbox.checked = saved.useTLS;
|
||||
}
|
||||
} catch {
|
||||
// first run, no saved data
|
||||
}
|
||||
})();
|
||||
|
||||
form.addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const host = hostInput.value.trim();
|
||||
const port = parseInt(portInput.value, 10);
|
||||
const useTLS = tlsCheckbox.checked;
|
||||
|
||||
if (!host) {
|
||||
setStatus("Please enter a host address.", "error");
|
||||
return;
|
||||
}
|
||||
if (isNaN(port) || port < 1 || port > 65535) {
|
||||
setStatus("Port must be between 1 and 65535.", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
connectBtn.disabled = true;
|
||||
connectBtn.querySelector(".btn-text").textContent = "Connecting…";
|
||||
setStatus('<span class="spinner"></span> Connecting…', "info");
|
||||
|
||||
try {
|
||||
const result = await window.overlord.connectToServer({ host, port, useTLS });
|
||||
|
||||
if (result.success) {
|
||||
setStatus("Connected! Loading Overlord…", "ok");
|
||||
} else {
|
||||
setStatus(result.error || "Connection failed.", "error");
|
||||
connectBtn.disabled = false;
|
||||
connectBtn.querySelector(".btn-text").textContent = "Connect";
|
||||
}
|
||||
} catch (err) {
|
||||
setStatus(err?.message || "Connection failed.", "error");
|
||||
connectBtn.disabled = false;
|
||||
connectBtn.querySelector(".btn-text").textContent = "Connect";
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user