Added the hyprsunset module (requires hyprland v0.45.0) (#485)

* add sunset module

* Implement hyprsunset module.

* Update themes

* Undo vivids

* Fix vivids
This commit is contained in:
Jas Singh
2024-11-12 03:35:27 -08:00
committed by GitHub
parent a7855baf13
commit 6cab0ff4b7
51 changed files with 1546 additions and 1086 deletions

View File

@@ -0,0 +1,33 @@
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';
});
};

View File

@@ -0,0 +1,65 @@
import options from 'options';
import { module } from '../module';
import { inputHandler, throttleInput } from 'customModules/utils';
import Button from 'types/widgets/button';
import { Attribute, Child } from 'lib/types/widget';
import { BarBoxChild } from 'lib/types/bar';
import { pollVariable } from 'customModules/PollVar';
import { checkSunsetStatus, isActive, toggleSunset } from './helpers';
const { label, pollingInterval, onIcon, offIcon, onLabel, offLabel, rightClick, middleClick, scrollUp, scrollDown } =
options.bar.customModules.hyprsunset;
const dummyVar = Variable(undefined);
checkSunsetStatus();
pollVariable(dummyVar, [], pollingInterval.bind('value'), checkSunsetStatus);
const throttledToggleSunset = throttleInput(() => toggleSunset(isActive), 1000);
export const Hyprsunset = (): BarBoxChild => {
const hyprsunsetModule = module({
textIcon: Utils.merge(
[isActive.bind('value'), onIcon.bind('value'), offIcon.bind('value')],
(active, onIcn, offIcn) => {
return active ? onIcn : offIcn;
},
),
tooltipText: isActive.bind('value').as((active) => `Hyprsunset ${active ? 'enabled' : 'disabled'}`),
boxClass: 'hyprsunset',
label: Utils.merge(
[isActive.bind('value'), onLabel.bind('value'), offLabel.bind('value')],
(active, onLbl, offLbl) => {
return active ? onLbl : offLbl;
},
),
showLabelBinding: label.bind('value'),
props: {
setup: (self: Button<Child, Attribute>) => {
inputHandler(self, {
onPrimaryClick: {
fn: () => {
throttledToggleSunset();
},
},
onSecondaryClick: {
cmd: rightClick,
},
onMiddleClick: {
cmd: middleClick,
},
onScrollUp: {
cmd: scrollUp,
},
onScrollDown: {
cmd: scrollDown,
},
});
},
},
});
return hyprsunsetModule;
};