-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #526 from undefiened/limit_consecutive_skips
Plugin for limiting the number of consecutive skips or postpones
- Loading branch information
Showing
6 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"meta": { | ||
"name": "Limit Consecutive Skipping", | ||
"description": "Limit how many breaks can be skipped or postponed in a row", | ||
"version": "0.0.1" | ||
}, | ||
"dependencies": { | ||
"python_modules": [], | ||
"shell_commands": [], | ||
"operating_systems": [], | ||
"desktop_environments": [], | ||
"resources": [] | ||
}, | ||
"settings": [{ | ||
"id": "number_of_allowed_skips_in_a_row", | ||
"label": "How many skips or postpones are allowed in a row", | ||
"type": "INT", | ||
"default": 2, | ||
"min": 1, | ||
"max": 100 | ||
}], | ||
"break_override_allowed": true | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/usr/bin/env python | ||
# Safe Eyes is a utility to remind you to take break frequently | ||
# to protect your eyes from eye strain. | ||
|
||
# Copyright (C) 2024 Leo (@undefiened), based on the code written by Gobinath | ||
|
||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
|
||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
""" | ||
Limit how many breaks can be skipped or postponed in a row. | ||
""" | ||
|
||
import logging | ||
|
||
context = None | ||
no_of_skipped_breaks = 0 | ||
session = None | ||
enabled = True | ||
|
||
def init(ctx, safeeyes_config, plugin_config): | ||
""" | ||
Initialize the plugin. | ||
""" | ||
global enabled | ||
global context | ||
global session | ||
global no_of_skipped_breaks | ||
global no_allowed_skips | ||
|
||
logging.debug('Initialize Limit consecutive skipping plugin') | ||
context = ctx | ||
|
||
no_allowed_skips = plugin_config.get('number_of_allowed_skips_in_a_row', 2) | ||
|
||
if session is None: | ||
# Read the session | ||
session = context['session']['plugin'].get('limitconsecutiveskipping', None) | ||
if session is None: | ||
session = {'no_of_skipped_breaks': 0} | ||
context['session']['plugin']['limitconsecutiveskipping'] = session | ||
no_of_skipped_breaks = session.get('no_of_skipped_breaks', 0) | ||
|
||
|
||
def on_stop_break(): | ||
""" | ||
After the break, check if it is skipped. | ||
""" | ||
# Check if the plugin is enabled | ||
if not enabled: | ||
return | ||
|
||
global no_of_skipped_breaks | ||
if context['skipped'] or context['postponed']: | ||
no_of_skipped_breaks += 1 | ||
session['no_of_skipped_breaks'] = no_of_skipped_breaks | ||
else: | ||
no_of_skipped_breaks = 0 | ||
session['no_of_skipped_breaks'] = no_of_skipped_breaks | ||
|
||
|
||
def on_start_break(break_obj): | ||
logging.debug('Skipped / allowed = {} / {}'.format(no_of_skipped_breaks, no_allowed_skips)) | ||
|
||
if no_of_skipped_breaks >= no_allowed_skips: | ||
context['postpone_button_disabled'] = True | ||
context['skip_button_disabled'] = True | ||
|
||
|
||
def get_widget_title(break_obj): | ||
""" | ||
Return the widget title. | ||
""" | ||
# Check if the plugin is enabled | ||
if not enabled: | ||
return "" | ||
|
||
return _('Limit Consecutive Skipping') | ||
|
||
|
||
def get_widget_content(break_obj): | ||
""" | ||
Return the statistics. | ||
""" | ||
# Check if the plugin is enabled | ||
if not enabled: | ||
return "" | ||
|
||
return _('Skipped or postponed %d/%d breaks in a row') % (no_of_skipped_breaks, no_allowed_skips) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters