Files
dotfiles/quickshell/services/HardwarePolicy.js
T
2026-11-17 18:15:16 +07:00

47 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
.pragma library
// Pure capability-to-UI policy. Device existence and device state are different:
// disconnected Ethernet and disabled Wi-Fi must remain discoverable.
function networkCapabilities(devices, wifiType, wiredType) {
const list = devices || [];
return {
wifi: list.some(d => d && d.type === wifiType),
wired: list.filter(d => d && d.type === wiredType),
hasNetworkDevices: list.length > 0
};
}
function ethernetSummary(devices) {
const list = devices || [];
if (list.length === 0) return "";
const connected = list.filter(d => d && d.connected).length;
if (list.length === 1) return connected ? "Ethernet · подключено" : "Ethernet · нет подключения";
return "Ethernet · " + connected + "/" + list.length;
}
function visibleSettingsSections(hasAudio, hasNetwork, hasBluetooth, hasModem, hasBattery) {
const sections = [{id: "appearance", title: "Оболочка"}];
if (hasAudio) sections.push({id: "audio", title: "Звук"});
if (hasNetwork) sections.push({id: "network", title: "Сеть и подключения"});
sections.push({id: "wallpaper", title: "Обои"});
if (hasBluetooth) sections.push({id: "bluetooth", title: "Bluetooth"});
if (hasModem) sections.push({id: "modem", title: "Мобильная сеть и SIM"});
if (hasBattery) sections.push({id: "battery", title: "Батарея и питание"});
sections.push({id: "display", title: "Дисплей и яркость"});
sections.push({id: "system", title: "О системе"});
return sections;
}
// Map stable section identifiers to the fixed StackLayout pages.
function pageIndex(id) {
const pages = {appearance: 0, audio: 1, network: 2, wallpaper: 3, bluetooth: 4, modem: 5, system: 6, battery: 7, display: 8};
return Object.prototype.hasOwnProperty.call(pages, id) ? pages[id] : 0;
}
function sectionIndex(sections, id) {
const list = sections || [];
for (let i = 0; i < list.length; ++i)
if (list[i].id === id) return i;
return -1;
}