Line data Source code
1 : // SPDX-License-Identifier: LGPL-2.1-or-later
2 120 : import cockpit from "cockpit";
3 :
4 : // This is the basic structure of a preloaded page. It has a two
5 : // phase initialization: phase 1 while it is still invisible, and
6 : // phase 2 when it becomes visible.
7 : //
8 : // Elements on the page (including the body) are made visible only
9 : // once the page itself is visible. Otherwise layout might go wrong
10 : // and not recover automatically.
11 :
12 120 : function init_1() {
13 120 : return (cockpit.spawn(["hostname"])
14 119 : .then(data => {
15 119 : document.getElementById("host").innerText = data.trim();
16 119 : }));
17 120 : }
18 :
19 0 : function init_2() {
20 0 : return (cockpit.file("/etc/os-release").read()
21 0 : .then(data => {
22 0 : document.getElementById("release").innerText = data;
23 0 : }));
24 0 : }
25 :
26 0 : function navigate() {
27 0 : document.getElementById("path").innerText = cockpit.location.path.join("/");
28 0 : document.body.removeAttribute("hidden");
29 0 : }
30 :
31 119 : function maybe_phase_2() {
32 119 : cockpit.removeEventListener("visibilitychange", maybe_phase_2);
33 119 : if (cockpit.hidden) {
34 119 : cockpit.addEventListener("visibilitychange", maybe_phase_2);
35 18 : } else {
36 18 : init_2().then(navigate);
37 18 : }
38 119 : }
39 :
40 120 : function init() {
41 120 : init_1().then(maybe_phase_2);
42 120 : }
43 :
44 120 : document.addEventListener("DOMContentLoaded", init);
|