Merge pull request #82 from radek-sprta/startup

Do not start SafeEyes if another instance is already running
This commit is contained in:
Gobinath 2017-02-23 20:29:58 -05:00 committed by GitHub
commit 984dbadebf
3 changed files with 49 additions and 27 deletions

View File

@ -32,11 +32,11 @@ yaourt -S safeeyes
### Other Linux: ### Other Linux:
1: Install the dependencies: 1: Install the dependencies:
* Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib`, `python2-gobject`, `python2-dbus`, `python2-babel`, `xprintidle` and `python-pyaudio` * Arch: `hicolor-icon-theme`, `libappindicator-gtk3`, `xorg-xprop`, `python2-xlib`, `python2-gobject`, `python2-dbus`, `python2-babel`, `xprintidle`, `python-psutil` and `python-pyaudio`
* Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject`, `python-gi`, `python-dbus`, `gir1.2-notify-0.7`, `python-gtk2`, `python-babel`, `xprintidle` and `python-pyaudio` * Debian: `gir1.2-appindicator3-0.1`, `python-xlib`, `python-gobject`, `python-gi`, `python-dbus`, `gir1.2-notify-0.7`, `python-gtk2`, `python-babel`, `xprintidle`, `python-psutil` and `python-pyaudio`
* Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject`, `xorg-x11-utils`, `python-dbus`, `python-babel`, `xprintidle` and `python-pyaudio` * Fedora 24: `libappindicator-gtk3`, `python-xlib`, `python-gobject`, `xorg-x11-utils`, `python-dbus`, `python-babel`, `xprintidle`, `python-psutil` and `python-pyaudio`
2: Download and extract [safeeyes.tar.gz](https://github.com/slgobinath/SafeEyes/releases/download/v1.1.8/safeeyes.tar.gz) into `/`: `sudo tar -xzvf safeeyes.tar.gz -C /` 2: Download and extract [safeeyes.tar.gz](https://github.com/slgobinath/SafeEyes/releases/download/v1.1.8/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 Package: safeeyes
Architecture: any Architecture: any
Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, python-babel, xprintidle, python-pyaudio Depends: gir1.2-appindicator3-0.1, python (>= 2.7.0), python-xlib, python-gi, python-dbus, gir1.2-notify-0.7, python-gtk2, python-babel, xprintidle, python-pyaudio, python-psutil
Description: Safe Eyes 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. 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

@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, gi, json, shutil, dbus, logging, operator, Utility import os, gi, json, shutil, dbus, logging, operator, Utility
import psutil
from threading import Timer from threading import Timer
from dbus.mainloop.glib import DBusGMainLoop from dbus.mainloop.glib import DBusGMainLoop
from BreakScreen import BreakScreen from BreakScreen import BreakScreen
@ -254,6 +255,22 @@ def read_lang_files():
return languages return languages
def running():
'''
Check if SafeEyes is already running.
'''
for proc in psutil.process_iter():
try:
# Check if safeeyes is in process arguments
if 'safeeyes' in proc.cmdline()[1]:
return True
# Ignore if process does not exist or does not have command line args
except (IndexError, psutil.NoSuchProcess):
pass
return False
def main(): def main():
initialize_config() initialize_config()
@ -261,6 +278,7 @@ def main():
logging.basicConfig(format='%(asctime)s [%(levelname)s]:[%(threadName)s] %(message)s', filename=log_file_path, filemode='w', level=logging.INFO) logging.basicConfig(format='%(asctime)s [%(levelname)s]:[%(threadName)s] %(message)s', filename=log_file_path, filemode='w', level=logging.INFO)
logging.info("Starting Safe Eyes") logging.info("Starting Safe Eyes")
if not running():
validate_config() validate_config()
global break_screen global break_screen
@ -284,5 +302,9 @@ def main():
handle_system_suspend() handle_system_suspend()
Gtk.main() Gtk.main()
else:
logging.info('SafeEyes is already running')
sys.exit(0)
main() if __name__ == '__main__':
main()