Skip to content

Commit 815e91e

Browse files
committed
Merge PR Jas-SinghFSU#1123: hide battery widget when no battery
2 parents aece4e5 + 4b4a8cd commit 815e91e

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

src/components/bar/layout/coreWidgets.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BatteryLabel } from '../modules/battery';
1+
import { BatteryLabel, BatteryWidgetContainer } from '../modules/battery';
22
import { Bluetooth } from '../modules/bluetooth';
33
import { Cava } from '../modules/cava';
44
import { Clock } from '../modules/clock';
@@ -30,7 +30,7 @@ import { WidgetFactory } from './WidgetRegistry';
3030

3131
export function getCoreWidgets(): Record<string, WidgetFactory> {
3232
return {
33-
battery: () => WidgetContainer(BatteryLabel()),
33+
battery: () => BatteryWidgetContainer(WidgetContainer(BatteryLabel())),
3434
dashboard: () => WidgetContainer(Menu()),
3535
workspaces: (monitor: number) => WidgetContainer(Workspaces(monitor)),
3636
windowtitle: () => WidgetContainer(ClientTitle()),

src/components/bar/modules/battery/index.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
scrollUp,
2020
scrollDown,
2121
hideLabelWhenFull,
22+
hideModuleWhenNoBatteryFound,
2223
} = options.bar.battery;
2324

2425
const BatteryLabel = (): BarBoxChild => {
@@ -164,4 +165,24 @@ const BatteryLabel = (): BarBoxChild => {
164165
};
165166
};
166167

167-
export { BatteryLabel };
168+
const BatteryWidgetContainer = (child: BarBoxChild): JSX.Element => {
169+
const isVisible = Variable.derive(
170+
[bind(batteryService, 'device-type'), bind(hideModuleWhenNoBatteryFound)],
171+
(deviceType: number, hideModuleWhenNoBatteryFound: boolean) => {
172+
const isBattery = deviceType === AstalBattery.Type.ASTAL_BATTERY_TYPE_BATTERY;
173+
return !hideModuleWhenNoBatteryFound || isBattery;
174+
},
175+
);
176+
return (
177+
<box
178+
visible={bind(isVisible)}
179+
onDestroy={() => {
180+
isVisible.drop();
181+
}}
182+
>
183+
{child}
184+
</box>
185+
);
186+
};
187+
188+
export { BatteryLabel, BatteryWidgetContainer };

src/components/settings/pages/config/bar/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ export const BarSettings = (): JSX.Element => {
477477
title="Hide Battery Percentage When Full"
478478
type="boolean"
479479
/>
480+
<Option
481+
opt={options.bar.battery.hideModuleWhenNoBatteryFound}
482+
title="Hide When No Battery Found"
483+
type="boolean"
484+
/>
480485
<Option
481486
opt={options.theme.bar.buttons.battery.spacing}
482487
title="Inner Spacing"

src/configuration/modules/config/bar/battery/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { opt } from 'src/lib/options';
33
export default {
44
label: opt(true),
55
hideLabelWhenFull: opt(false),
6+
hideModuleWhenNoBatteryFound: opt(false),
67
rightClick: opt(''),
78
middleClick: opt(''),
89
scrollUp: opt(''),

0 commit comments

Comments
 (0)