LCOV - code coverage report
Current view: top level - pkg/playground - preloaded.js Coverage Total Hit
Test: cockpit Lines: 100.0 % 29 29
Test Date: 2026-07-03 07:31:16

            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          321 :             .then(data => {
      15          321 :                 document.getElementById("host").innerText = data.trim();
      16          321 :             }));
      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          321 : function maybe_phase_2() {
      32          321 :     cockpit.removeEventListener("visibilitychange", maybe_phase_2);
      33          321 :     if (cockpit.hidden) {
      34          321 :         cockpit.addEventListener("visibilitychange", maybe_phase_2);
      35           56 :     } else {
      36           56 :         init_2().then(navigate);
      37           56 :     }
      38          321 : }
      39              : 
      40          324 : function init() {
      41          324 :     init_1().then(maybe_phase_2);
      42          324 : }
      43              : 
      44          324 : document.addEventListener("DOMContentLoaded", init);
        

Generated by: LCOV version 2.0-1