diff --git a/src/components/bar/layout/coreWidgets.tsx b/src/components/bar/layout/coreWidgets.tsx index f3be40ec3..757919f24 100644 --- a/src/components/bar/layout/coreWidgets.tsx +++ b/src/components/bar/layout/coreWidgets.tsx @@ -1,4 +1,4 @@ -import { BatteryLabel } from '../modules/battery'; +import { BatteryLabel, BatteryWidgetContainer } from '../modules/battery'; import { Bluetooth } from '../modules/bluetooth'; import { Cava } from '../modules/cava'; import { Clock } from '../modules/clock'; @@ -30,7 +30,7 @@ import { WidgetFactory } from './WidgetRegistry'; export function getCoreWidgets(): Record { return { - battery: () => WidgetContainer(BatteryLabel()), + battery: () => BatteryWidgetContainer(WidgetContainer(BatteryLabel())), dashboard: () => WidgetContainer(Menu()), workspaces: (monitor: number) => WidgetContainer(Workspaces(monitor)), windowtitle: () => WidgetContainer(ClientTitle()), diff --git a/src/components/bar/modules/battery/index.tsx b/src/components/bar/modules/battery/index.tsx index f61f7f53b..ed6ec5d69 100644 --- a/src/components/bar/modules/battery/index.tsx +++ b/src/components/bar/modules/battery/index.tsx @@ -19,6 +19,7 @@ const { scrollUp, scrollDown, hideLabelWhenFull, + hideModuleWhenNoBatteryFound, } = options.bar.battery; const BatteryLabel = (): BarBoxChild => { @@ -164,4 +165,24 @@ const BatteryLabel = (): BarBoxChild => { }; }; -export { BatteryLabel }; +const BatteryWidgetContainer = (child: BarBoxChild): JSX.Element => { + const isVisible = Variable.derive( + [bind(batteryService, 'device-type'), bind(hideModuleWhenNoBatteryFound)], + (deviceType: number, hideModuleWhenNoBatteryFound: boolean) => { + const isBattery = deviceType === AstalBattery.Type.ASTAL_BATTERY_TYPE_BATTERY; + return !hideModuleWhenNoBatteryFound || isBattery; + }, + ); + return ( + { + isVisible.drop(); + }} + > + {child} + + ); +}; + +export { BatteryLabel, BatteryWidgetContainer }; diff --git a/src/components/settings/pages/config/bar/index.tsx b/src/components/settings/pages/config/bar/index.tsx index 8bba498e1..172fb88c0 100644 --- a/src/components/settings/pages/config/bar/index.tsx +++ b/src/components/settings/pages/config/bar/index.tsx @@ -477,6 +477,11 @@ export const BarSettings = (): JSX.Element => { title="Hide Battery Percentage When Full" type="boolean" /> +