fix: add battery notif (#441)

* fix: waybar style battery msgs

* Revert "fix: waybar style battery msgs"

This reverts commit 924d998ddda6cb4becc87fabfd7958a0f7ecc773.

* fix: revert changes

---------

Co-authored-by: Jas Singh <jaskiratpal.singh@outlook.com>
This commit is contained in:
Rubin Bhandari
2024-11-18 01:55:16 +05:45
committed by GitHub
parent 0028b9484e
commit ac794dccb0
5 changed files with 54 additions and 5 deletions

View File

@@ -13,6 +13,8 @@ import { Window } from 'types/@girs/gtk-3.0/gtk-3.0.cjs';
import { namedColors } from './constants/colors';
import { distroIcons } from './constants/distro';
import { distro } from './variables';
const battery = await Service.import('battery');
import options from 'options';
export type Binding<T> = import('types/service').Binding<any, any, T>;
@@ -200,3 +202,22 @@ export function getDistroIcon(): string {
const icon = distroIcons.find(([id]) => id === distro.id);
return icon ? icon[1] : ''; // default icon if not found
}
export const warnOnLowBattery = (): void => {
battery.connect('notify::percent', () => {
const { lowBatteryThreshold, lowBatteryNotification, lowBatteryNotificationText, lowBatteryNotificationTitle } =
options.menus.power;
if (!lowBatteryNotification.value || battery.charging) return;
const lowThreshold = lowBatteryThreshold.value;
if (battery.percent === lowThreshold || battery.percent === lowThreshold / 2) {
Notify({
summary: lowBatteryNotificationTitle.value.replace('/$POWER_LEVEL/g', battery.percent.toString()),
body: lowBatteryNotificationText.value.replace('/$POWER_LEVEL/g', battery.percent.toString()),
iconName: icons.ui.warning,
urgency: 'critical',
timeout: 7000,
});
}
});
};