slgobinath / SafeEyes

Protect your eyes from eye strain using this simple and beautiful, yet extensible break reminder
http://slgobinath.github.io/SafeEyes/
GNU General Public License v3.0
1.41k stars 159 forks source link

Stop requiring the "plugins" option from the configuration file #547

Open DamienCassou opened 7 months ago

DamienCassou commented 7 months ago

Describe the bug

If the plugins attribute is missing from safeeyes.json, safeeyes crashes with

Traceback (most recent call last):
  File "/nix/store/…-safeeyes-2.1.6/bin/.safeeyes-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/…-safeeyes-2.1.6/lib/python3.11/site-packages/safeeyes/__main__.py", line 116, in main
    config = Config()
             ^^^^^^^^
  File "/nix/store/…-safeeyes-2.1.6/lib/python3.11/site-packages/safeeyes/model.py", line 327, in __init__
    utility.merge_plugins(self.__user_config)
  File "/nix/store/…-safeeyes-2.1.6/lib/python3.11/site-packages/safeeyes/utility.py", line 595, in merge_plugins
    for plugin in config['plugins']:
                  ~~~~~~^^^^^^^^^^^
KeyError: 'plugins'

I think safeeyes could have a default value for this attribute so as not to require its presence in the configuration file. This way, users can keep their configuration file as small as possible, containing only what is strictly different from the default.

In the same spirit, it would be much better if the user could override 1 plugin without specifying all the non-changed ones as well. So, the following configuration file:

{
    "meta": {
        "config_version": "6.0.3"
    },
    "plugins": [
        {
            "enabled": false,
            "id": "notification",
            "version": "0.0.1"
        },
    ]
}

should be a valid way of saying

keep all plugins as they are configured by default except for 'notifications' which should be disabled

To Reproduce Steps to reproduce the behavior:

  1. Open safeeyes.json
  2. Delete the plugins option
  3. Restart safeeyes
  4. See error in the output (see above for the error message)

Expected behavior

It should be possible to both:

  1. remove the "plugins" option from safeeyes.json and still get a working safeeyes
  2. only specify a non-standard plugin configuration and leave the other plugins with their default values (see above for an example))

Desktop (please complete the following information):