repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/privilege.js
Raw// privilege.js — pure rendering helpers for the Nuguland polkit surface.
// Dual-mode: node `require` tests + QML import.
function escapeHtml(value) {
return String(value == null ? "" : value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
}
function stripCommandQuotes(command) {
var text = String(command || "").trim();
if (text.length >= 2) {
var first = text[0];
var last = text[text.length - 1];
if ((first === "`" || first === "'" || first === "\"") && (last === "'" || last === "`" || last === "\""))
return text.slice(1, -1);
}
return text;
}
function commandFromMessage(message) {
var text = String(message || "").trim();
var match = /^Authentication is needed to run\s+(.+?)\s+as the super user\.?$/i.exec(text);
return stripCommandQuotes(match ? match[1] : text);
}
function commandLines(command) {
var text = stripCommandQuotes(command);
var shell = /^(\/usr\/bin\/sh|sh)\s+-c\s+(.+)$/.exec(text);
var lines = shell ? [shell[1] + " -c"].concat(shell[2].split(/\s+&&\s+/)) : text.split(/\s+&&\s+/);
return lines.map(function (line) { return line.trim(); })
.filter(function (line) { return line.length > 0; });
}
function commandMarkdown(message) {
var lines = commandLines(commandFromMessage(message));
if (lines.length === 0) lines = ["A system change needs your password."];
return "<span style=\"font-family:'IBM Plex Mono'; font-size:13px; line-height:1.35\">" +
lines.map(escapeHtml).join("<br>") +
"</span>";
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
escapeHtml: escapeHtml,
commandFromMessage: commandFromMessage,
commandLines: commandLines,
commandMarkdown: commandMarkdown
};
}