feat: show battery on bluetooth device list (#352)

* feat: show battery on bluetooth device list

* feat: show battery on bluetooth device list

* fix: handle case when battery is not defined

* fix: handle case when battery is not defined

* feat: add bluetooth menu

* feat: add bluetooth menu

* fix: separate icon and percentage

* fix: group battery stuffs

* Update options.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

* Update modules/menus/bluetooth/devices/devicelist.ts

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-10-30 09:44:45 +05:45
committed by GitHub
parent a64fd64ac0
commit 0bdaf461f6
5 changed files with 93 additions and 3 deletions

View File

@@ -4,6 +4,9 @@ import { connectedControls } from './connectedControls.js';
import { getBluetoothIcon } from '../utils.js'; import { getBluetoothIcon } from '../utils.js';
import Gtk from 'types/@girs/gtk-3.0/gtk-3.0.js'; import Gtk from 'types/@girs/gtk-3.0/gtk-3.0.js';
import { Attribute, Child } from 'lib/types/widget.js'; import { Attribute, Child } from 'lib/types/widget.js';
import options from 'options';
const { showBattery, batteryIcon } = options.menus.bluetooth;
const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Child, Attribute> => { const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Child, Attribute> => {
return self.hook(bluetooth, () => { return self.hook(bluetooth, () => {
@@ -101,10 +104,57 @@ const devices = (bluetooth: Bluetooth, self: Box<Gtk.Widget, unknown>): Box<Chil
Widget.Revealer({ Widget.Revealer({
hpack: 'start', hpack: 'start',
reveal_child: device.connected || device.paired, reveal_child: device.connected || device.paired,
child: Widget.Label({ child: Widget.Box({
hpack: 'start',
children: Utils.merge(
[showBattery.bind('value'), batteryIcon.bind('value')],
(showBat, batIcon) => {
if (!showBat) {
return [
Widget.Label({
hpack: 'start', hpack: 'start',
class_name: 'connection-status dim', class_name: 'connection-status dim',
label: device.connected ? 'Connected' : 'Paired', label: device.connected
? 'Connected'
: 'Paired',
}),
];
}
return [
Widget.Label({
hpack: 'start',
class_name: 'connection-status dim',
label: device.connected
? 'Connected'
: 'Paired',
}),
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}%`,
}),
]
: [],
}),
];
},
),
}), }),
}), }),
], ],

View File

@@ -1054,6 +1054,10 @@ const options = mkOptions(OPTIONS, {
menus: { menus: {
transition: opt<Transition>('crossfade'), transition: opt<Transition>('crossfade'),
transitionTime: opt(200), transitionTime: opt(200),
bluetooth: {
showBattery: opt(false),
batteryIcon: opt('󰥉'),
},
volume: { volume: {
raiseMaximumVolume: opt(false), raiseMaximumVolume: opt(false),
}, },

View File

@@ -111,6 +111,9 @@
color: if($bar-menus-monochrome, $bar-menus-text, $bar-menus-menu-bluetooth-text); color: if($bar-menus-monochrome, $bar-menus-text, $bar-menus-menu-bluetooth-text);
opacity: 0.4; opacity: 0.4;
} }
.battery{
opacity: 0.6;
}
} }
spinner { spinner {

View File

@@ -7,6 +7,7 @@ import { OSDSettings } from './osd/index';
import { CustomModuleSettings } from 'customModules/config'; import { CustomModuleSettings } from 'customModules/config';
import { PowerMenuSettings } from './menus/power'; import { PowerMenuSettings } from './menus/power';
import { GBox } from 'lib/types/widget'; import { GBox } from 'lib/types/widget';
import { BluetoothMenuSettings } from './menus/bluetooth';
import { VolumeMenuSettings } from './menus/volume'; import { VolumeMenuSettings } from './menus/volume';
type Page = type Page =
@@ -15,6 +16,7 @@ type Page =
| 'Clock Menu' | 'Clock Menu'
| 'Dashboard Menu' | 'Dashboard Menu'
| 'Power Menu' | 'Power Menu'
| 'Bluetooth Menu'
| 'Volume' | 'Volume'
| 'Notifications' | 'Notifications'
| 'OSD' | 'OSD'
@@ -28,6 +30,7 @@ const pagerMap: Page[] = [
'Notifications', 'Notifications',
'OSD', 'OSD',
'Power Menu', 'Power Menu',
'Bluetooth Menu',
'Volume', 'Volume',
'Clock Menu', 'Clock Menu',
'Dashboard Menu', 'Dashboard Menu',
@@ -64,6 +67,7 @@ export const SettingsMenu = (): GBox => {
'Clock Menu': ClockMenuSettings(), 'Clock Menu': ClockMenuSettings(),
'Dashboard Menu': DashboardMenuSettings(), 'Dashboard Menu': DashboardMenuSettings(),
'Custom Modules': CustomModuleSettings(), 'Custom Modules': CustomModuleSettings(),
'Bluetooth Menu': BluetoothMenuSettings(),
'Power Menu': PowerMenuSettings(), 'Power Menu': PowerMenuSettings(),
}, },
shown: CurrentPage.bind('value'), shown: CurrentPage.bind('value'),

View File

@@ -0,0 +1,29 @@
import { Option } from 'widget/settings/shared/Option';
import { Header } from 'widget/settings/shared/Header';
import options from 'options';
import Scrollable from 'types/widgets/scrollable';
import { Attribute, Child } from 'lib/types/widget';
export const BluetoothMenuSettings = (): Scrollable<Child, Attribute> => {
return Widget.Scrollable({
vscroll: 'automatic',
child: Widget.Box({
class_name: 'bar-theme-page paged-container',
vertical: true,
children: [
Header('Bluetooth'),
Option({
opt: options.menus.bluetooth.showBattery,
title: 'Show Battery Percentage for Connected Devices (If Supported)',
type: 'boolean',
}),
Option({
opt: options.menus.bluetooth.batteryIcon,
title: 'Battery Icon',
type: 'string',
}),
],
}),
});
};