repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/diagnostics.js
Raw.pragma library
// Explicit projections only. Never serialize a service, output, or caller string.
function choice(value, allowed) {
return allowed.indexOf(value) >= 0 ? value : "unknown";
}
function number(value) {
return typeof value === "number" && Number.isFinite(value) ? value : 0;
}
function rect(value) {
return {
"x": number(value.x),
"y": number(value.y),
"width": number(value.width),
"height": number(value.height)
};
}
// Registry popup names only; anything else is "unknown".
function name(value, surfaces) {
if (value === "")
return "";
if (typeof value !== "string")
return "unknown";
return surfaces && surfaces.registry && surfaces.registry.popup(value) ? value : "unknown";
}
function phase(value) {
return choice(value, ["closed", "opening", "open", "closing"]);
}
function nextOperationId(current) {
return current >= 2147483647 ? 1 : current + 1;
}
function transition(event, surfaces) {
return {
"version": 1,
"kind": "popup-transition",
"operationId": number(surfaces.operationId),
"event": choice(event, ["opening", "opened", "switched", "closed"]),
"name": name(surfaces.popupName, surfaces),
"phase": phase(surfaces.popupPhase)
};
}
function popup(surfaces) {
return {
"operationId": number(surfaces.operationId),
"name": name(surfaces.popupName, surfaces),
"phase": phase(surfaces.popupPhase),
"open": surfaces.popupOpen === true,
// Retained by the version 1 diagnostics schema; no closing lifecycle exists.
"closing": false,
"orientation": choice(surfaces.orientation, ["horizontal", "vertical"]),
"progress": number(surfaces.popupProgress),
"anchor": rect(surfaces.popupAnchor),
"card": rect(surfaces.popupCardFrame(surfaces.popupProgress).currentRect),
"viewport": {
"width": number(surfaces.screenWidth),
"height": number(surfaces.screenHeight),
"barHeight": number(surfaces.barHeight)
}
};
}
function snapshot(surfaces, screens, services) {
const displays = [];
for (let i = 0; i < screens.length; i++) {
const screen = screens[i];
const display = rect(screen);
display.scale = number(screen.devicePixelRatio);
displays.push(display);
}
return {
"version": 1,
"popup": popup(surfaces),
"displays": displays,
"services": {
"niri": {
"available": services.niri.available === true,
"ready": services.niri.ready === true,
"windowCount": number(services.niri.windows.length),
"workspaceCount": number(services.niri.workspaces.length)
},
"audio": { "ready": services.audio.pipewireReady === true },
"network": {
"enabled": services.network.wifiEnabled === true,
"scanning": services.network.scanning === true
},
"vault": {
"status": choice(services.vault.status, ["needs-setup", "locked", "loading", "unlocked", "syncing", "sync-failure", "stale-cache", "second-factor", "authentication-failure", "unavailable-vault"]),
"lockPending": services.vault.lockPending === true
},
"noko": {
"ready": services.noko.ready === true,
"phase": choice(services.noko.overlayState, ["", "starting", "capturing", "transcribing", "finished", "failed"]),
"installing": services.noko.installing === true,
"wakeListening": services.noko.wakeListening === true
}
}
};
}