Pause and resume during system suspend

This commit is contained in:
Gobinath 2016-10-30 15:14:15 +05:30
parent 4f8b377b28
commit a9747ff659
3 changed files with 29 additions and 4 deletions

View File

@ -23,11 +23,11 @@ Manual installation is not tested in any systems. I will update this page as soo
1: Install the dependencies:
* Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib` and `python2-gobject`
* Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib`, `python2-gobject` and `python2-dbus`
* Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject` and `python-gi`
* Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject`, `python-gi` and `python-dbus`
* Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject` and `xorg-x11-utils`
* Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject`, `xorg-x11-utils` and `python-dbus`
2: Download and extract [safeeyes.tar.gz](https://github.com/slgobinath/SafeEyes/releases/download/v1.0.7/safeeyes.tar.gz) into `/`: `sudo tar -xzvf safeeyes.tar.gz -C /`

View File

@ -8,7 +8,7 @@ Homepage: https://github.com/slgobinath/SafeEyes/
Package: safeeyes
Architecture: any
Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi
Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus
Description: Safe Eyes
Safe Eyes is a simple tool to remind you to take periodic breaks for your eyes. This is essential for anyone spending more time on the computer to avoid eye strain and other physical problems.
.

View File

@ -23,11 +23,15 @@ import gi
import json
import shutil
import errno
import dbus
from dbus.mainloop.glib import DBusGMainLoop
from BreakScreen import BreakScreen
from TrayIcon import TrayIcon
from SettingsDialog import SettingsDialog
from SafeEyesCore import SafeEyesCore
from Notification import Notification
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
@ -40,6 +44,8 @@ settings_dialog_glade = os.path.join(bin_directory, "glade/settings_dialog.glade
system_config_file_path = os.path.join(bin_directory, "config/safeeyes.json")
system_style_sheet_path = os.path.join(bin_directory, "config/style/safeeyes_style.css")
is_active = True
def show_settings():
settings_dialog = SettingsDialog(config, save_settings, settings_dialog_glade)
settings_dialog.show()
@ -72,6 +78,21 @@ def on_quite():
notification.quite();
Gtk.main_quit()
def handle_suspend_callback(sleeping):
if sleeping:
# Sleeping / suspending
if is_active:
core.stop()
else:
# Resume from sleep
if is_active:
core.start()
def handle_system_suspend():
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
bus.add_signal_receiver(handle_suspend_callback, 'PrepareForSleep', 'org.freedesktop.login1.Manager', 'org.freedesktop.login1')
def on_skipped():
# Hide and show tray icon if strict break is on
# This feature is required because, by disabling Safe Eyes,
@ -90,9 +111,11 @@ def save_settings(config):
break_screen.initialize(config)
def enable_safeeyes():
is_active = True
core.toggle_active_state()
def disable_safeeyes():
is_active = False
core.toggle_active_state()
def prepare_local_config_dir():
@ -147,6 +170,8 @@ def main():
core.start()
notification = Notification()
handle_system_suspend()
Gtk.main()
main()