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:
@@ -633,6 +633,83 @@ export const CustomModuleSettings = (): Scrollable<GtkWidget, Attribute> =>
|
||||
type: 'string',
|
||||
}),
|
||||
|
||||
/*
|
||||
************************************
|
||||
* HYPRSUNSET *
|
||||
************************************
|
||||
*/
|
||||
Header('Hyprsunset'),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.temperature,
|
||||
title: 'Temperature',
|
||||
subtitle: 'Ex: 1000k, 2000k, 5000k, etc.',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.theme.bar.buttons.modules.hyprsunset.enableBorder,
|
||||
title: 'Button Border',
|
||||
type: 'boolean',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.onIcon,
|
||||
title: 'Enabled Icon',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.offIcon,
|
||||
title: 'Disabled Icon',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.onLabel,
|
||||
title: 'Enabled Label',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.offLabel,
|
||||
title: 'Disabled Label',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.label,
|
||||
title: 'Show Label',
|
||||
type: 'boolean',
|
||||
}),
|
||||
Option({
|
||||
opt: options.theme.bar.buttons.modules.hyprsunset.spacing,
|
||||
title: 'Spacing',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.pollingInterval,
|
||||
title: 'Polling Interval',
|
||||
type: 'number',
|
||||
subtitle: "WARNING: Be careful of your package manager's rate limit.",
|
||||
min: 100,
|
||||
max: 60 * 24 * 1000,
|
||||
increment: 1000,
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.rightClick,
|
||||
title: 'Right Click',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.middleClick,
|
||||
title: 'Middle Click',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.scrollUp,
|
||||
title: 'Scroll Up',
|
||||
type: 'string',
|
||||
}),
|
||||
Option({
|
||||
opt: options.bar.customModules.hyprsunset.scrollDown,
|
||||
title: 'Scroll Down',
|
||||
type: 'string',
|
||||
}),
|
||||
|
||||
/*
|
||||
************************************
|
||||
* POWER *
|
||||
|
||||
33
customModules/hyprsunset/helpers.ts
Normal file
33
customModules/hyprsunset/helpers.ts
Normal 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';
|
||||
});
|
||||
};
|
||||
65
customModules/hyprsunset/index.ts
Normal file
65
customModules/hyprsunset/index.ts
Normal 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;
|
||||
};
|
||||
@@ -167,6 +167,23 @@ export const CustomModuleTheme = (): Scrollable<GtkWidget, Attribute> => {
|
||||
}),
|
||||
Option({ opt: options.theme.bar.buttons.modules.weather.border, title: 'Border', type: 'color' }),
|
||||
|
||||
Header('Hyprsunset'),
|
||||
Option({ opt: options.theme.bar.buttons.modules.hyprsunset.text, title: 'Text', type: 'color' }),
|
||||
Option({ opt: options.theme.bar.buttons.modules.hyprsunset.icon, title: 'Icon', type: 'color' }),
|
||||
Option({
|
||||
opt: options.theme.bar.buttons.modules.hyprsunset.background,
|
||||
title: 'Label Background',
|
||||
type: 'color',
|
||||
}),
|
||||
Option({
|
||||
opt: options.theme.bar.buttons.modules.hyprsunset.icon_background,
|
||||
title: 'Icon Background',
|
||||
subtitle:
|
||||
"Applies a background color to the icon section of the button.\nRequires 'split' button styling.",
|
||||
type: 'color',
|
||||
}),
|
||||
Option({ opt: options.theme.bar.buttons.modules.hyprsunset.border, title: 'Border', type: 'color' }),
|
||||
|
||||
Header('Power'),
|
||||
Option({ opt: options.theme.bar.buttons.modules.power.icon, title: 'Icon', type: 'color' }),
|
||||
Option({
|
||||
|
||||
@@ -36,7 +36,7 @@ export const runAsyncCommand: RunAsyncCommand = (cmd, events, fn, postInputUpdat
|
||||
.catch((err) => console.error(`Error running command "${cmd}": ${err})`));
|
||||
};
|
||||
|
||||
export function throttle<T extends ThrottleFn>(func: T, limit: number): T {
|
||||
export function throttleInput<T extends ThrottleFn>(func: T, limit: number): T {
|
||||
let inThrottle: boolean;
|
||||
return function (this: ThisParameterType<T>, ...args: Parameters<T>) {
|
||||
if (!inThrottle) {
|
||||
@@ -50,9 +50,12 @@ export function throttle<T extends ThrottleFn>(func: T, limit: number): T {
|
||||
}
|
||||
|
||||
export const throttledScrollHandler = (interval: number): ThrottleFn =>
|
||||
throttle((cmd: string, events: EventArgs, fn: ThrottleFnCallback, postInputUpdater?: VariableType<boolean>) => {
|
||||
runAsyncCommand(cmd, events, fn, postInputUpdater);
|
||||
}, 200 / interval);
|
||||
throttleInput(
|
||||
(cmd: string, events: EventArgs, fn: ThrottleFnCallback, postInputUpdater?: VariableType<boolean>) => {
|
||||
runAsyncCommand(cmd, events, fn, postInputUpdater);
|
||||
},
|
||||
200 / interval,
|
||||
);
|
||||
|
||||
const dummyVar = Variable('');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user