mate-desktop / mate-power-manager

Power management tool for the MATE desktop
https://mate-desktop.org
GNU General Public License v2.0
59 stars 52 forks source link

Add CLI options for manage power settings #290

Open jumapico opened 5 years ago

jumapico commented 5 years ago

Doing remote support tasks, many times I need to change power settings for users as workaround for some known bugs.

I think that is more practical, instead to use the ui, copy-paste the new settings in the command line or using the options in a script.

I'm interested in working in this feature, or at least try it, but also want some comments/guidance before starting.

CLI

For the CLI options, I think that a command style is a good start. Due to the large number of options it seems better to group them using the same groups that the UI uses in tabs. Also, only one group of options are set by invocation.

Here the command line options:

mate-power-preferences general \
    when-power-button-pressed=[ask|suspend|hibernate|shutdown|nothing] \
    when-suspend-button-pressed=[ask|suspend|hibernate|shutdown|nothing] \
    display-icon-in-notification-area-when=[never|battery-power-low|charging-or-discharging|battery-present|always]

mate-power-preferences on-ac-power \
    sleep-computer-when-inactive=[never|X (seconds)] \
    when-laptop-lid-closed=[...] \
    display-sleep-when-inactive=[never|X (seconds)] \
    display-brightness=percent \
    display-dim-when-idle=[yes|no]

mate-power-preferences on-battery-power \
    sleep-when-inactive=[never|X (seconds)] \
    when-laptop-lid-closed=[...] \
    when-battery-power-critically-low=[...] \
    display-sleep-when-inactive=[never|X (seconds)] \
    display-reduce-backlight-brightness=[yes|no] \
    display-dim-when-idle=[yes|no]

mate-power-preferences on-ups-power \
    sleep-when-inactive=[never|X (seconds)] \
    when-ups-power-low=[...] \
    when-ups-power-critically-low=[...] \
    display-sleep-when-inactive=[never|X (seconds)]

mate-power-preferences show

The groups of options (names and values) were taken from the UI (glade-previewer --filename data/gpm-prefs.ui) and an execution of mate-power-preferences.

The show command is added to list all the settings for mate-power-manager.

Without doubt the names/options are not the best but I think a starting point; maybe someone can suggest better names or ideas for they.

If an option does not apply, eg on-battery-power in a desktop PC, the behavior can be:

a. Ignore the setting doing nothing. b. Set the setting, expecting that others MATE components ignores the setting if it does not apply.

Code

Some of the code to save the preferences is inside the UI code. Here two options:

a. Refactor the code to common functions, maybe a new module, for use in the UI and the CLI.

b. Duplicate the code (Copy/Paste) in a new CLI module.

I think that refactor is the best and elegant option, but maybe for a new contribution (and contributor) b. is a better approach. If the feature is finished and works, is feasible in a next step refactoring the common code.