Line data Source code
1 : // SPDX-License-Identifier: LGPL-2.1-or-later
2 324 : 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 324 : function init_1() {
13 324 : return (cockpit.spawn(["hostname"])
14 322 : .then(data => {
15 322 : document.getElementById("host").innerText = data.trim();
16 322 : }));
17 324 : }
18 :
19 1 : function init_2() {
20 1 : return (cockpit.file("/etc/os-release").read()
21 1 : .then(data => {
22 1 : document.getElementById("release").innerText = data;
23 1 : }));
24 1 : }
25 :
26 1 : function navigate() {
27 1 : document.getElementById("path").innerText = cockpit.location.path.join("/");
28 1 : document.body.removeAttribute("hidden");
29 1 : }
30 :
31 322 : function maybe_phase_2() {
32 322 : cockpit.removeEventListener("visibilitychange", maybe_phase_2);
33 322 : if (cockpit.hidden) {
34 322 : cockpit.addEventListener("visibilitychange", maybe_phase_2);
35 58 : } else {
36 58 : init_2().then(navigate);
37 58 : }
38 322 : }
39 :
40 324 : function init() {
41 324 : init_1().then(maybe_phase_2);
42 324 : }
43 :
44 324 : document.addEventListener("DOMContentLoaded", init);
|