Skip to content

Fixed breaks not being called and two other problems #564

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
.
  • Loading branch information
adventuretc committed Oct 5, 2024
commit 83f069cd50723fdcbdc57fd4f8525f7bec068b2d
4 changes: 3 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ rm -rf build/ dist/ safeeyes.egg-info/ .eggs/
python3 setup.py sdist bdist_wheel
twine upload --repository pypitest dist/safeeyes*.tar.gz
clear >$(tty)
twine upload --repository pypitest dist/safeeyes*.whl
twine upload --repository pypitest dist/safeeyes*.whl

read x;
3 changes: 3 additions & 0 deletions gitkraken.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

gitkraken -p .
4 changes: 4 additions & 0 deletions safeeyes/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def main():
group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
parser.add_argument('--status', help=_('print the status of running safeeyes instance and exit'), action='store_true')
parser.add_argument('--reset', help=_('Reset the scheduled time of the next break but not total break status like if a long break is due soon.'), action='store_true')
# sajt. Noh, sikerült implementálnom ezt a feature-t. Viszont nem jöttem rá arra, hogy hogyan kell úgy futtatni a programomat, hogy éljen is benne ez, mert még mindig a régi verzió működését kapom úgy látom. :/ a python3 -m safeeyes paranccsal futtattam és a --reset opciónak nyoma sehol. Mondjuk a smartpause plugin az meg átállt az új működésre szóval lehet h más a baj.
parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
args = parser.parse_args()

Expand Down Expand Up @@ -135,6 +137,8 @@ def main():
rpc_client.take_break()
elif args.status:
print(rpc_client.status())
elif args.reset:
rpc_client.reset()
elif args.quit:
rpc_client.quit()
else:
Expand Down
8 changes: 7 additions & 1 deletion safeeyes/plugins/smartpause/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"meta": {
"name": "Smart Pause",
"description": "Pause Safe Eyes if the system is idle",
"version": "0.0.3"
"version": "0.0.3-adventuretc-2024-08-18"
},
"dependencies": {
"python_modules": [],
Expand All @@ -20,6 +20,12 @@
"max": 3600,
"min": 5
},
{
"id": "interpret_idle_as_break",
"label": "Interpret idle time equivalent to upcoming break duration as a break",
"type": "BOOL",
"default": false
},
{
"id": "postpone_if_active",
"label": "Postpone the next break until the system becomes idle",
Expand Down
12 changes: 11 additions & 1 deletion safeeyes/plugins/smartpause/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
next_break_duration = 0
short_break_interval = 0
waiting_time = 2
interpret_idle_as_break = False
is_wayland_and_gnome = False

use_swayidle = False
Expand Down Expand Up @@ -156,6 +157,7 @@ def init(ctx, safeeyes_config, plugin_config):
global short_break_interval
global long_break_duration
global waiting_time
global interpret_idle_as_break
global postpone_if_active
global is_wayland_and_gnome
global use_swayidle
Expand All @@ -165,6 +167,7 @@ def init(ctx, safeeyes_config, plugin_config):
disable_safeeyes = context['api']['disable_safeeyes']
postpone = context['api']['postpone']
idle_time = plugin_config['idle_time']
interpret_idle_as_break = plugin_config['interpret_idle_as_break']
postpone_if_active = plugin_config['postpone_if_active']
short_break_interval = safeeyes_config.get(
'short_break_interval') * 60 # Convert to seconds
Expand Down Expand Up @@ -197,12 +200,19 @@ def __start_idle_monitor():
info = _('Paused Safe Eyes due to system being idle')
disable_safeeyes(info, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this still doesn't work for me - now it fails with
TypeError: SafeEyes.__init__.<locals>.<lambda>() takes 1 positional argument but 2 were given
I guess the is_resting parameter has to be passed along in the lambda in safeeyes/safeeyes.py:74 as well:

self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread(
self.disable_safeeyes, status)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, looks like it.

elif system_idle_time < idle_time and context['state'] == State.RESTING and idle_start_time is not None:
#2.1.4-ben ez a sor még más volt. Biztos, hogy jó most? "elif system_idle_time < idle_time and context['state'] == State.STOPPED and idle_start_time is not None:"
logging.info('Resume Safe Eyes due to user activity')
smart_pause_activated = False
idle_period = (datetime.datetime.now() - idle_start_time)
idle_seconds = idle_period.total_seconds()
context['idle_period'] = idle_seconds
if idle_seconds < short_break_interval:
if interpret_idle_as_break and idle_seconds >= next_break_duration:
# User is idle for break duration and wants to consider it as a break
logging.debug("Idle for %d seconds; long breaks are %d seconds long", idle_seconds, long_break_duration)
enable_safeeyes(-1, idle_seconds >= long_break_duration)
elif idle_seconds < short_break_interval:
# Ja mostmár értem. Baszná meg. 2.1.4 és 2.1.6 közt azt változtatták meg ebben a pluginban, hogy nincs "interpret_idle_as_break" opció hanem az idle time-ot mindig csak úgy értemezi a program, hogy annyival kitolja a következő szünet esedékességi idejét és pause-ra teszi a safeeyes-t amíg nem ülsz a gépnél. De nekem nem ez kell hanem a interpret_idle_as_break működés.
# Ráadásul nem írta át a verziószámot amikor megváltoztatta a plugint.
# Credit back the idle time
if next_break_time is not None:
# This method runs in a thread since the start.
Expand Down
9 changes: 8 additions & 1 deletion safeeyes/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(self, port, context):
self.__server.register_function(context['api']['disable_safeeyes'], 'disable_safeeyes')
self.__server.register_function(context['api']['take_break'], 'take_break')
self.__server.register_function(context['api']['status'], 'status')
self.__server.register_function(context['api']['reset'], 'reset')
self.__server.register_function(context['api']['quit'], 'quit')

def start(self):
Expand Down Expand Up @@ -92,7 +93,7 @@ def disable_safeeyes(self):
"""
Disable Safe Eyes.
"""
self.proxy.disable_safeeyes(None)
self.proxy.disable_safeeyes(None, False)

def take_break(self):
"""
Expand All @@ -106,6 +107,12 @@ def status(self):
"""
return self.proxy.status()

def reset(self):
"""
Reset the scheduled time of the next break but not total break status like if a long break is due soon.
"""
return self.proxy.reset()

def quit(self):
"""
Quit Safe Eyes.
Expand Down
13 changes: 11 additions & 2 deletions safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def __init__(self, system_locale, config):
self.show_about)
self.context['api']['enable_safeeyes'] = lambda next_break_time=-1, reset_breaks=False: \
utility.execute_main_thread(self.enable_safeeyes, next_break_time, reset_breaks)
self.context['api']['disable_safeeyes'] = lambda status: utility.execute_main_thread(
self.disable_safeeyes, status)
self.context['api']['disable_safeeyes'] = lambda status, is_resting: \
utility.execute_main_thread(self.disable_safeeyes, status, is_resting)
# fixed a bug.
self.context['api']['status'] = self.status
self.context['api']['reset'] = self.reset
self.context['api']['quit'] = lambda: utility.execute_main_thread(
self.quit)
if self.config.get('persist_state'):
Expand Down Expand Up @@ -307,6 +309,13 @@ def status(self):
"""
return self._status

def reset(self):
"""
Reset the scheduled time of the next break but not total break status like if a long break is due soon.
"""
self.disable_safeeyes(None, False)
self.enable_safeeyes(scheduled_next_break_time=-1, reset_breaks=True)

def persist_session(self):
"""
Save the session object to the session file.
Expand Down