Aylur / ags

A customizable and extensible shell
GNU General Public License v3.0
2.18k stars 112 forks source link

Toggling quick settings and interval/timeout of the script #13

Closed cafetestrest closed 1 year ago

cafetestrest commented 1 year ago

I've implemented a nightlight (using wlsunset) toggle in the quick settings. On/Off toggling is working fine. I have 2 problems with my implementation:

  1. I have automatic script in the background that turns on nightlight in night hours and disables it in the morning. I can not work it out where should I implement timeout or interval script and how to?
  2. Icon does not change on startup/on restart of ags depending on if the nightlight is enabled or disabled

What is expected behavior: The icon is representing exact state of night-light and by clicking of the toggle I can choose to either enable/disable the night-light effect on the screen - hard switch.

This is my nightlight.js file: https://github.com/cafetestrest/dotfiles/blob/develop/.config/ags/modules/nightlight.js

PS: Is there a right-click command of the icon?

Aylur commented 1 year ago
  1. For wlsunset, or any other binary you want to use/monitor, I recommend you have a look at modules/brightness.js Essentially it is a wrapper over said binary, so that you can control its state. Instead of running wlsunset in your other script make a Service like in brightness.js and then do
    # in your script which I assume is a shell script
    ags run-js "ags.Service.Nightlight.yourWrapperFunction()"

or you can make that other script inside an ags module I see you are using the Settings Service for this variable but that service is for the settings dialog and It would more sense to have that in nightlight.js as a Service. You can also look at modules/asusctl.js for reference

  1. If you setup a Service for this your icon issue would be solved

also just a side note

// you don't need to run these with bash
if (Settings.nightlight) {
    execAsync("wlsunset -t 3500 -S 06:00 -s 06:01")
} else {
    execAsync("killall -9 wlsunset")
}

There is no right click menu yet. Or if you mean like an onClick on icon then no, but you have onSecondaryClick on buttons