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

Fixed breaks not being called and two other problems #564

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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 .
36 changes: 36 additions & 0 deletions install in development mode and run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash


python3 -m pip install -e '/home/xy/workspace/Safeeyes fixálása/SafeEyes 2.1.6, fixálva 3 dologgal, lásd a git logot/'
# sleep 3
# read x;
safeeyes &


# How to: https://packaging.python.org/en/latest/tutorials/installing-packages/

# Installing from a local src tree

# Installing from local src in Development Mode, i.e. in such a way that the project appears to be installed, but yet is still editable from the src tree.
# Unix/macOS

# python3 -m pip install -e <path>

# Windows

# You can also install normally from src
# Unix/macOS

# python3 -m pip install <path>



# Installing from VCS

# Install a project from VCS in “editable” mode. For a full breakdown of the syntax, see pip’s section on VCS Support.
# Unix/macOS

# python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git # from git
# python3 -m pip install -e SomeProject @ hg+https://hg.repo/some_pkg # from mercurial
# python3 -m pip install -e SomeProject @ svn+svn://svn.repo/some_pkg/trunk/ # from svn
# python3 -m pip install -e SomeProject @ git+https://git.repo/some_pkg.git@feature # from a branch
5 changes: 5 additions & 0 deletions run reset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

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

safeeyes &
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
3 changes: 2 additions & 1 deletion safeeyes/plugins/healthstats/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def init(ctx, safeeyes_config, plugin_config):
'total_resets': 0,
}

session = context['session']['plugin'].get('healthstats', {}) | defaults
session = context['session']['plugin'].get('healthstats', {}).copy()
session.update(defaults) # refactored to maintain compatibility with python3.8 on Ubuntu 20.04 LTS (dict | dict syntax was introduced in python3.9).
if 'no_of_breaks' in session:
# Ignore old format session.
session = defaults
Expand Down
18 changes: 13 additions & 5 deletions safeeyes/plugins/mediacontrol/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging
import os
import dbus
import dbus.exceptions
import re
import gi
from safeeyes.model import TrayAction
Expand All @@ -41,11 +42,18 @@ def __active_players():

for service in bus.list_names():
if re.match('org.mpris.MediaPlayer2.', service):
player = bus.get_object(service, "/org/mpris/MediaPlayer2")
interface = dbus.Interface(player, 'org.freedesktop.DBus.Properties')
status = str(interface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')).lower()
if status == "playing":
players.append(player)
try:
player = bus.get_object(service, "/org/mpris/MediaPlayer2")
interface = dbus.Interface(player, 'org.freedesktop.DBus.Properties')
status = str(interface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')).lower()
if status == "playing":
players.append(player)
except dbus.exceptions.DBusException as e:
# Purpose of this: The Chromium snap (at least on ubuntu 20.04 LTS) forbids SafeEyes from sending dbus messages to Chromium and we must catch that exception and ignore that particular player. If we don't, the the method and plugin fails and the break itself fails to be called. With this fix, only impossible-to-reach players are ignored and all else works.
# The specific exception is (dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied)
# We don't care about logging the error but maybe we should log it in debug mode:
logging.debug(f"DBusException: {e}")

return players


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
15 changes: 13 additions & 2 deletions 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 @@ -194,14 +197,22 @@ def __start_idle_monitor():
smart_pause_activated = True
idle_start_time = datetime.datetime.now() - datetime.timedelta(seconds=system_idle_time)
logging.info('Pause Safe Eyes due to system idle')
disable_safeeyes(None, True)
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
32 changes: 30 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,32 @@ 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.
"""

# Stop the Safe Eyes core
if self.active:
self.plugins_manager.stop()
self.safe_eyes_core.stop()

if self.rpc_server is None and self.config.get('use_rpc_server'):
# # RPC server wasn't running but now enabled
self.__start_rpc_server()
elif self.rpc_server is not None and not self.config.get('use_rpc_server'):
# # RPC server was running but now disabled
self.__stop_rpc_server()

# Restart the core and initialize the components
self.safe_eyes_core.initialize(self.config)
self.break_screen.initialize(self.config)
self.plugins_manager.init(self.context, self.config)
if self.active and self.safe_eyes_core.has_breaks():
# 1 sec delay is required to give enough time for core to be stopped
Timer(1.0, self.safe_eyes_core.start).start()
self.plugins_manager.start()

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