Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pymodoro as app name in notifications (+ more cleanup) #54

Open
wants to merge 31 commits into
base: master
Choose a base branch
from

Conversation

dkasak
Copy link
Contributor

@dkasak dkasak commented Mar 31, 2019

No description provided.

Prior to this commit, there was still some inconsistency in how XDG Base
Directory was handled. For instance, hooks were still being loaded from
the old-style config directory.

This commit unifies the handling of directory locations in the method
`init_dirs`. Directories are not hardcoded, respecting the XDG_*
environment variables, only falling back to the defaults if they are not
set. Any missing directories are created. Any tildes in the paths are
immediately expanded using `path.expanduser`.

For backward compatibility, the implementation prefers the old-style
directory if it exists, but emits a deprecation warning to the user on
stderr.

All methods should now use the `Config` instance variables `_config_dir`
and `_cache_dir` for the config and cache directories (respectively),
instead of calculating those paths themselves.
Instead of specifying defaults by directly assigning them to Pymodoro's
internal state, a PymodoroConfigParser (a derived class of
RawConfigParser) instance is constructed containing the defaults.
A separate function then takes such an instance and assigns its settings
to the internal state.

This allows us to easily merge user settings from the config file over
the defaults. It also obviates the need for a separate function for
creating the config file, because we can simply use
`PymodoroConfigParser.write`.

In addition, it provides the following benefits:

- Lays groundwork for supporting multiple configuration files of
  increasing priority (e.g. system-wide, followed by user
  configuration), if wanted.
- The config parser now tolerates missing options in the config file.
- Self-documenting: when the config file is missing, it will get created
  with all available settings populated with their default values.
- Hooks were made configurable.
- Allows all sounds used by Pymodoro to be customized via the config
  file.
Command-line argument parsing has been moved out of the Config class and
into main, as part of this change. Instead, the Config class now
receives parsed arguments.
Previously the state calculation algorithm worked by separately determining the
current state and then predicting (based on the current state and parameters
such as pomodoro and break lengths) what the next state will be, after the next
tick elapses. Unfortunately this method is unable to predict user actions and
will therefore never predict that the next state would be the active state
(because it can never predict a user clicking to start a pomodoro). This left
start hooks completely broken.

Fortunately, this kind of prediction is entirely unnecessary. The new algorithm
works as follows:

1. Initialize current state to IDLE_STATE.
2. Loop:

    a. Calculate the next state by comparing the mtime of the cache file with
       the current time. *Do not* assign this state as the current state yet.
    b. Run events (notifications, hooks) based on the difference between the current and next states.
    c. Assume the next state as the current state.
    d. Print output and play tick sounds.
    e. Wait for the next tick.
    f. Go back to a.
This is a hook which fires whenever a pomodoro is ended, regardless
of whether it because the pomodoro completed naturally or it was
terminated by the user.

A possible use case is to be able to pause system notifications when the
pomodoro starts and turn them back on when it is no longer active.
There's no reason to specify default paths for the hooks in the config
file since the hooks are not created automatically.

Furthermore, since the only constraint on hooks is that they should be
executable files, there's no reason to suggest that they should be
Python modules (as was previously the case due to the default filenames
having the .py extension).
- Reflect changes in location of the config and session files (due to
  following XDG Base Directory).
- Document hooks.
- Fix typos.
- Wrap paragraphs.
The names reflect the config option names, i.e.
pomodoro_{start,end,complete}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant