Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/bar/layout/coreWidgets.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -30,7 +30,7 @@ import { WidgetFactory } from './WidgetRegistry';

export function getCoreWidgets(): Record<string, WidgetFactory> {
return {
battery: () => WidgetContainer(BatteryLabel()),
battery: () => BatteryWidgetContainer(WidgetContainer(BatteryLabel())),
dashboard: () => WidgetContainer(Menu()),
workspaces: (monitor: number) => WidgetContainer(Workspaces(monitor)),
windowtitle: () => WidgetContainer(ClientTitle()),
Expand Down
23 changes: 22 additions & 1 deletion src/components/bar/modules/battery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
scrollUp,
scrollDown,
hideLabelWhenFull,
hideModuleWhenNoBatteryFound,
} = options.bar.battery;

const BatteryLabel = (): BarBoxChild => {
Expand Down Expand Up @@ -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 (
<box
visible={bind(isVisible)}
onDestroy={() => {
isVisible.drop();
}}
>
{child}
</box>
);
};

export { BatteryLabel, BatteryWidgetContainer };
5 changes: 5 additions & 0 deletions src/components/settings/pages/config/bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ export const BarSettings = (): JSX.Element => {
title="Hide Battery Percentage When Full"
type="boolean"
/>
<Option
opt={options.bar.battery.hideModuleWhenNoBatteryFound}
title="Hide When No Battery Found"
type="boolean"
/>
<Option
opt={options.theme.bar.buttons.battery.spacing}
title="Inner Spacing"
Expand Down
1 change: 1 addition & 0 deletions src/configuration/modules/config/bar/battery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { opt } from 'src/lib/options';
export default {
label: opt(true),
hideLabelWhenFull: opt(false),
hideModuleWhenNoBatteryFound: opt(false),
rightClick: opt(''),
middleClick: opt(''),
scrollUp: opt(''),
Expand Down