null safety so that it might load properly idk

This commit is contained in:
2026-08-08 19:59:10 +01:00
parent b3c46e2df2
commit 021ddae2d0
2 changed files with 25 additions and 10 deletions

View File

@@ -8,9 +8,11 @@ import "../Color.js" as Colors
Singleton { Singleton {
id: root id: root
property double batteryPercentage: root.mainBattery.percentage property double batteryPercentage: root.mainBattery.percentage || 0
property bool batteryPresent: root.mainBattery.ready property bool batteryPresent: root.mainBattery.ready || false
property UPowerDevice mainBattery: UPower.displayDevice property UPowerDevice mainBattery: UPower.displayDevice || undefined
function getBatteryColor() { function getBatteryColor() {
let criticalLevel = 20; let criticalLevel = 20;

View File

@@ -6,22 +6,29 @@ import Quickshell.Bluetooth
Singleton { Singleton {
id: root id: root
property BluetoothAdapter defaultAdapter: Bluetooth.defaultAdapter property BluetoothAdapter defaultAdapter: Bluetooth.defaultAdapter || null
property string defaultAdapterName: Bluetooth.defaultAdapter.adapterId property string defaultAdapterName: defaultAdapter ? defaultAdapter.adapterId : ""
function getConnected() { function getConnected() {
let deviceList = getDevicesList(); let deviceList = getDevicesList();
for (let device in deviceList) { if (deviceList.length == 0) {
let currentDevice = deviceList[device]; return false;
if (currentDevice.connected == true) { } else {
return true; for (let device in deviceList) {
let currentDevice = deviceList[device];
if (currentDevice.connected == true) {
return true;
}
} }
return false;
} }
return false;
} }
function getConnectedDevicesList() { function getConnectedDevicesList() {
let devicesList = getDevicesList(); let devicesList = getDevicesList();
if (!devicesList) {
return [];
}
let connectedList = []; let connectedList = [];
for (let device of devicesList) { for (let device of devicesList) {
if (device.connected == true) { if (device.connected == true) {
@@ -32,6 +39,9 @@ Singleton {
} }
function getDeviceText(device) { function getDeviceText(device) {
if (!device) {
return undefined;
}
let deviceName = device.deviceName; let deviceName = device.deviceName;
let deviceIcon = getIcon(device.icon); let deviceIcon = getIcon(device.icon);
let deviceMac = device.address; let deviceMac = device.address;
@@ -54,6 +64,9 @@ Singleton {
} }
function getDevicesList() { function getDevicesList() {
if (!root.defaultAdapter) {
return [];
}
return root.defaultAdapter.devices.values; return root.defaultAdapter.devices.values;
} }