Update bluetooth battery indicator padding and provide option to define when to show battery icon. (#403)
* Update bluetooth battery indicator visuals and behavior. * Remove log * Update default battery state to paired. * Change to connected
This commit is contained in:
@@ -13,7 +13,11 @@ const formatFrequency = (frequency: number): string => {
|
||||
};
|
||||
|
||||
const formatWifiInfo = (wifi: Wifi): string => {
|
||||
return `Network: ${wifi.ssid === '' ? 'None' : wifi.ssid} \nSignal Strength: ${wifi.strength >= 0 ? wifi.strength : '--'}% \nFrequency: ${wifi.frequency >= 0 ? formatFrequency(wifi.frequency) : '--'}`;
|
||||
const netSsid = wifi.ssid === '' ? 'None' : wifi.ssid;
|
||||
const wifiStrength = wifi.strength >= 0 ? wifi.strength : '--';
|
||||
const wifiFreq = wifi.frequency >= 0 ? formatFrequency(wifi.frequency) : '--';
|
||||
|
||||
return `Network: ${netSsid} \nSignal Strength: ${wifiStrength}% \nFrequency: ${wifiFreq}`;
|
||||
};
|
||||
|
||||
const {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { Bluetooth } from 'types/service/bluetooth.js';
|
||||
import { Bluetooth, BluetoothDevice } from 'types/service/bluetooth.js';
|
||||
import Box from 'types/widgets/box.js';
|
||||
import { connectedControls } from './connectedControls.js';
|
||||
import { getBluetoothIcon } from '../utils.js';
|
||||
import Gtk from 'types/@girs/gtk-3.0/gtk-3.0.js';
|
||||
import { Attribute, Child } from 'lib/types/widget.js';
|
||||
import options from 'options';
|
||||
import Label from 'types/widgets/label.js';
|
||||
|
||||
const { showBattery, batteryIcon } = options.menus.bluetooth;
|
||||
const { showBattery, batteryIcon, batteryState } = options.menus.bluetooth;
|
||||
|
||||
const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Child, Attribute> => {
|
||||
return self.hook(bluetooth, () => {
|
||||
@@ -65,6 +66,33 @@ const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Chil
|
||||
}));
|
||||
}
|
||||
|
||||
const getConnectionStatusLabel = (device: BluetoothDevice): Label<Attribute> => {
|
||||
return Widget.Label({
|
||||
hpack: 'start',
|
||||
class_name: 'connection-status dim',
|
||||
label: device.connected ? 'Connected' : 'Paired',
|
||||
});
|
||||
};
|
||||
|
||||
const getBatteryInfo = (device: BluetoothDevice, batIcon: string): Gtk.Widget[] => {
|
||||
if (typeof device.battery_percentage === 'number' && device.battery_percentage >= 0) {
|
||||
return [
|
||||
Widget.Separator({
|
||||
class_name: 'menu-separator bluetooth-battery',
|
||||
}),
|
||||
Widget.Label({
|
||||
class_name: 'connection-status txt-icon',
|
||||
label: `${batIcon}`,
|
||||
}),
|
||||
Widget.Label({
|
||||
class_name: 'connection-status battery',
|
||||
label: `${device.battery_percentage}%`,
|
||||
}),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
return (self.child = Widget.Box({
|
||||
vertical: true,
|
||||
children: availableDevices.map((device) => {
|
||||
@@ -107,50 +135,24 @@ const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Chil
|
||||
child: Widget.Box({
|
||||
hpack: 'start',
|
||||
children: Utils.merge(
|
||||
[showBattery.bind('value'), batteryIcon.bind('value')],
|
||||
(showBat, batIcon) => {
|
||||
if (!showBat) {
|
||||
return [
|
||||
Widget.Label({
|
||||
hpack: 'start',
|
||||
class_name: 'connection-status dim',
|
||||
label: device.connected
|
||||
? 'Connected'
|
||||
: 'Paired',
|
||||
}),
|
||||
];
|
||||
[
|
||||
showBattery.bind('value'),
|
||||
batteryIcon.bind('value'),
|
||||
batteryState.bind('value'),
|
||||
],
|
||||
(showBat, batIcon, batState) => {
|
||||
if (
|
||||
!showBat ||
|
||||
(batState === 'paired' && !device.paired) ||
|
||||
(batState === 'connected' && !device.connected)
|
||||
) {
|
||||
return [getConnectionStatusLabel(device)];
|
||||
}
|
||||
|
||||
return [
|
||||
Widget.Label({
|
||||
hpack: 'start',
|
||||
class_name: 'connection-status dim',
|
||||
label: device.connected
|
||||
? 'Connected'
|
||||
: 'Paired',
|
||||
}),
|
||||
getConnectionStatusLabel(device),
|
||||
Widget.Box({
|
||||
children:
|
||||
typeof device.battery_percentage ===
|
||||
'number' &&
|
||||
device.battery_percentage >= 0
|
||||
? [
|
||||
Widget.Separator({
|
||||
class_name:
|
||||
'menu-separator',
|
||||
}),
|
||||
Widget.Label({
|
||||
class_name:
|
||||
'connection-status txt-icon',
|
||||
label: `${batIcon}`,
|
||||
}),
|
||||
Widget.Label({
|
||||
class_name:
|
||||
'connection-status battery',
|
||||
label: `${device.battery_percentage}%`,
|
||||
}),
|
||||
]
|
||||
: [],
|
||||
children: getBatteryInfo(device, batIcon),
|
||||
}),
|
||||
];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user