From 4ee4f0d31e921daaf1042a50708681ee0d3679b0 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Sat, 11 May 2024 09:09:52 +0700 Subject: [PATCH] sideright: hide night light button when unavailable --- .config/ags/modules/sideright/quicktoggles.js | 67 ++++++++++--------- .config/ags/modules/sideright/sideright.js | 2 +- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/.config/ags/modules/sideright/quicktoggles.js b/.config/ags/modules/sideright/quicktoggles.js index 39b08c908..a294a4b9c 100644 --- a/.config/ags/modules/sideright/quicktoggles.js +++ b/.config/ags/modules/sideright/quicktoggles.js @@ -78,38 +78,41 @@ export const HyprToggleIcon = async (icon, name, hyprlandConfigValue, props = {} } } -export const ModuleNightLight = (props = {}) => Widget.Button({ - attribute: { - enabled: false, - }, - className: 'txt-small sidebar-iconbutton', - tooltipText: 'Night Light', - onClicked: (self) => { - self.attribute.enabled = !self.attribute.enabled; - self.toggleClassName('sidebar-button-active', self.attribute.enabled); - if (self.attribute.enabled) Utils.execAsync('gammastep').catch(print) - else Utils.execAsync('pkill gammastep') - .then(() => { - // disable the button until fully terminated to avoid race - self.sensitive = false; - const source = setInterval(() => { - Utils.execAsync('pkill -0 gammastep') - .catch(() => { - self.sensitive = true; - source.destroy(); - }); - }, 500); - }) - .catch(print); - }, - child: MaterialIcon('nightlight', 'norm'), - setup: (self) => { - setupCursorHover(self); - self.attribute.enabled = !!exec('pidof gammastep'); - self.toggleClassName('sidebar-button-active', self.attribute.enabled); - }, - ...props, -}); +export const ModuleNightLight = async (props = {}) => { + if (!exec(`bash -c 'command -v gammastep'`)) return null; + return Widget.Button({ + attribute: { + enabled: false, + }, + className: 'txt-small sidebar-iconbutton', + tooltipText: 'Night Light', + onClicked: (self) => { + self.attribute.enabled = !self.attribute.enabled; + self.toggleClassName('sidebar-button-active', self.attribute.enabled); + if (self.attribute.enabled) Utils.execAsync('gammastep').catch(print) + else Utils.execAsync('pkill gammastep') + .then(() => { + // disable the button until fully terminated to avoid race + self.sensitive = false; + const source = setInterval(() => { + Utils.execAsync('pkill -0 gammastep') + .catch(() => { + self.sensitive = true; + source.destroy(); + }); + }, 500); + }) + .catch(print); + }, + child: MaterialIcon('nightlight', 'norm'), + setup: (self) => { + setupCursorHover(self); + self.attribute.enabled = !!exec('pidof gammastep'); + self.toggleClassName('sidebar-button-active', self.attribute.enabled); + }, + ...props, + }); +} export const ModuleInvertColors = async (props = {}) => { try { diff --git a/.config/ags/modules/sideright/sideright.js b/.config/ags/modules/sideright/sideright.js index 94f8ba0a2..56b9d0d2d 100644 --- a/.config/ags/modules/sideright/sideright.js +++ b/.config/ags/modules/sideright/sideright.js @@ -90,7 +90,7 @@ const togglesBox = Widget.Box({ ToggleIconBluetooth(), await ModuleRawInput(), await HyprToggleIcon('touchpad_mouse', 'No touchpad while typing', 'input:touchpad:disable_while_typing', {}), - ModuleNightLight(), + await ModuleNightLight(), await ModuleInvertColors(), ModuleIdleInhibitor(), ]