Files
custum-hyprpanel/customModules/hyprsunset/helpers.ts
Jas Singh a4f5fb5917 Refactor Polling Mechanism: Implement Class-Based Poller with Start/Stop Control (#528)
* custom module updates to class based.

* Finish poller logic.

* Use composition for pollers

* Rename poller

* Handle recorder polling.

* Fix quotes in bash command

* Remove logs
2024-11-23 03:55:00 -08:00

34 lines
1.1 KiB
TypeScript

import options from 'options';
import { Variable as TVariable } from 'types/variable';
const { temperature } = options.bar.customModules.hyprsunset;
export const isActiveCommand = `bash -c "pgrep -x 'hyprsunset' > /dev/null && echo 'yes' || echo 'no'"`;
export const isActive = Variable(false);
export const toggleSunset = (isActive: TVariable<boolean>): void => {
Utils.execAsync(isActiveCommand).then((res) => {
if (res === 'no') {
Utils.execAsync(`bash -c "nohup hyprsunset -t ${temperature.value} > /dev/null 2>&1 &"`).then(() => {
Utils.execAsync(isActiveCommand).then((res) => {
isActive.value = res === 'yes';
});
});
} else {
Utils.execAsync(`bash -c "pkill hyprsunset "`).then(() => {
Utils.execAsync(isActiveCommand).then((res) => {
isActive.value = res === 'yes';
});
});
}
});
};
export const checkSunsetStatus = (): undefined => {
Utils.execAsync(isActiveCommand).then((res) => {
isActive.value = res === 'yes';
});
};