Skip to content

Commit

Permalink
feat(hypridle): add option for start and stop command
Browse files Browse the repository at this point in the history
  • Loading branch information
FerranAD committed Jan 17, 2025
1 parent 88609f7 commit aaed198
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
6 changes: 6 additions & 0 deletions nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ in
bar.customModules.hypridle.rightClick = mkStrOption "";
bar.customModules.hypridle.scrollDown = mkStrOption "";
bar.customModules.hypridle.scrollUp = mkStrOption "";
bar.customModules.hypridle.startCommand = mkStrOption "nohup hypridle > /dev/null 2>&1 &";
bar.customModules.hypridle.stopCommand = mkStrOption "pkill hypridle";
bar.customModules.hypridle.isActiveCommand = mkStrOption "pgrep -x 'hypridle' &>/dev/null && echo 'yes' || echo 'no'";
bar.customModules.hyprsunset.label = mkBoolOption true;
bar.customModules.hyprsunset.middleClick = mkStrOption "";
bar.customModules.hyprsunset.offIcon = mkStrOption "󰛨";
Expand Down Expand Up @@ -457,6 +460,9 @@ in
theme.bar.buttons.media.spacing = mkStrOption "0.5em";
theme.bar.buttons.modules.cpu.enableBorder = mkBoolOption false;
theme.bar.buttons.modules.cpu.spacing = mkStrOption "0.5em";
theme.bar.buttons.modules.cpu.border = mkStrOption "";
theme.bar.buttons.modules.cpu.icon_background = mkStrOption "";
theme.bar.buttons.modules.cpu.text = mkStrOption "";
theme.bar.buttons.modules.cpuTemp.enableBorder = mkBoolOption false;
theme.bar.buttons.modules.cpuTemp.spacing = mkStrOption "0.5em";
theme.bar.buttons.modules.hypridle.enableBorder = mkBoolOption false;
Expand Down
19 changes: 11 additions & 8 deletions src/components/bar/modules/hypridle/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import options from 'src/options';
import { execAsync, Variable } from 'astal';

const { startCommand, stopCommand, isActiveCommand } = options.bar.customModules.hypridle;

/**
* Checks if the hypridle process is active.
*
* This command checks if the hypridle process is currently running by using the `pgrep` command.
* This command checks if the hypridle process is currently running by using the configured `isActiveCommand`.
* It returns 'yes' if the process is found and 'no' otherwise.
*/
export const isActiveCommand = `bash -c "pgrep -x 'hypridle' &>/dev/null && echo 'yes' || echo 'no'"`;
export const isActiveCmd = `bash -c "${isActiveCommand.get()}"`;

/**
* A variable to track the active state of the hypridle process.
Expand All @@ -21,8 +24,8 @@ export const isActive = Variable(false);
* @param isActive A Variable<boolean> that tracks the active state of the hypridle process.
*/
const updateIsActive = (isActive: Variable<boolean>): void => {
execAsync(isActiveCommand).then((res) => {
isActive.set(res === 'yes');
execAsync(isActiveCmd).then((res) => {
isActive.set(res.trim() === 'yes');
});
};

Expand All @@ -35,9 +38,9 @@ const updateIsActive = (isActive: Variable<boolean>): void => {
* @param isActive A Variable<boolean> that tracks the active state of the hypridle process.
*/
export const toggleIdle = (isActive: Variable<boolean>): void => {
execAsync(isActiveCommand).then((res) => {
execAsync(isActiveCmd).then((res) => {
const toggleIdleCommand =
res === 'no' ? `bash -c "nohup hypridle > /dev/null 2>&1 &"` : `bash -c "pkill hypridle"`;
res.trim() === 'no' ? `bash -c "${startCommand.get()}"` : `bash -c "${stopCommand.get()}"`;

execAsync(toggleIdleCommand).then(() => updateIsActive(isActive));
});
Expand All @@ -49,7 +52,7 @@ export const toggleIdle = (isActive: Variable<boolean>): void => {
* This function checks if the hypridle process is currently running and updates the `isActive` variable accordingly.
*/
export const checkIdleStatus = (): undefined => {
execAsync(isActiveCommand).then((res) => {
isActive.set(res === 'yes');
execAsync(isActiveCmd).then((res) => {
isActive.set(res.trim() === 'yes');
});
};
15 changes: 15 additions & 0 deletions src/components/bar/settings/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ export const CustomModuleSettings = (): JSX.Element => {
<Option opt={options.bar.customModules.hypridle.middleClick} title="Middle Click" type="string" />
<Option opt={options.bar.customModules.hypridle.scrollUp} title="Scroll Up" type="string" />
<Option opt={options.bar.customModules.hypridle.scrollDown} title="Scroll Down" type="string" />
<Option
opt={options.bar.customModules.hypridle.startCommand}
title="Start Hypridle Command"
type="string"
/>
<Option
opt={options.bar.customModules.hypridle.stopCommand}
title="Stop Hypridle Command"
type="string"
/>
<Option
opt={options.bar.customModules.hypridle.isActiveCommand}
title="Hypridle Status Command"
type="string"
/>

{/* Cava Section */}
<Header title="Cava" />
Expand Down
3 changes: 3 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,9 @@ const options = mkOptions(CONFIG, {
middleClick: opt(''),
scrollUp: opt(''),
scrollDown: opt(''),
isActiveCommand: opt("pgrep -x 'hypridle' &>/dev/null && echo 'yes' || echo 'no'"),
startCommand: opt("nohup hypridle > /dev/null 2>&1 &"),

Check failure on line 1185 in src/options.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `"nohup·hypridle·>·/dev/null·2>&1·&"` with `'nohup·hypridle·>·/dev/null·2>&1·&'`

Check failure on line 1185 in src/options.ts

View workflow job for this annotation

GitHub Actions / code_quality

Strings must use singlequote
stopCommand: opt("pkill hypridle"),

Check failure on line 1186 in src/options.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `"pkill·hypridle"` with `'pkill·hypridle'`

Check failure on line 1186 in src/options.ts

View workflow job for this annotation

GitHub Actions / code_quality

Strings must use singlequote
},
cava: {
showIcon: opt(true),
Expand Down

0 comments on commit aaed198

Please sign in to comment.