var wm; function main() { wm = new WindowManager(); if (checkBrowser()) { __setAppText(); __loadKvmdInfo(); } } function __setAppText() { $("app-text").innerHTML = ` # On Linux using Chromium/Chrome via any terminal:
$
\`which chromium 2>/dev/null || which chrome 2>/dev/null\` --app="${window.location.href}"

# On MacOS using Terminal application:
$
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --app="${window.location.href}"

# On Windows via cmd.exe:
C:\>
start chrome --app="${window.location.href}" `; } function __loadKvmdInfo() { var http = tools.makeRequest("GET", "/kvmd/info", function() { if (http.readyState === 4) { if (http.status === 200) { var info = JSON.parse(http.responseText).result; var apps = Object.values(info.extras).sort(function(a, b) { if (a["place"] < b["place"]) { return -1; } else if (a["place"] > b["place"]) { return 1; } else { return 0; } }); $("apps-box").innerHTML = ""; $("apps").innerHTML += __makeApp(null, "kvm", "share/svg/kvm.svg", "KVM"); apps.forEach(function(app) { $("apps").innerHTML += __makeApp(null, app.path, app.icon, app.name); }); $("apps").innerHTML += __makeApp("logout-button", "#", "share/svg/logout.svg", "Logout"); tools.setOnClick($("logout-button"), __logout); if (info.meta && info.meta.server && info.meta.server.host) { $("kvmd-meta-server-host").innerHTML = info.meta.server.host; document.title = "Pi-KVM Index: " + info.meta.server.host; } else { $("kvmd-meta-server-host").innerHTML = ""; document.title = "Pi-KVM Index"; } } else if (http.status === 401 || http.status === 403) { document.location.href = "/login"; } else { setTimeout(__loadKvmdInfo, 1000); } } }); } function __makeApp(id, path, icon, name) { return `
  • ${name}
  • `; } function __logout() { var http = tools.makeRequest("POST", "/kvmd/auth/logout", function() { if (http.readyState === 4) { if (http.status === 200 || http.status === 401 || http.status === 403) { document.location.href = "/login"; } else { wm.error("Logout error:
    ", http.responseText); } } }); }