Fixing apscheduler version issue
This commit is contained in:
parent
6ea7380efb
commit
dff6104187
|
@ -1,4 +1,6 @@
|
||||||
safeeyes (1.0.0-1) xenial; urgency=medium
|
safeeyes (1.0.2-1) xenial; urgency=medium
|
||||||
|
|
||||||
|
* Fixing apscheduler version mismatch
|
||||||
|
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,12 @@
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('Gdk', '3.0')
|
gi.require_version('Gdk', '3.0')
|
||||||
from gi.repository import Gdk, Gio, GLib
|
from gi.repository import Gdk, Gio, GLib
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.scheduler import Scheduler
|
||||||
from apscheduler.schedulers.base import BaseScheduler
|
|
||||||
import time, threading, sys, subprocess, logging
|
import time, threading, sys, subprocess, logging
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
|
|
||||||
class SafeEyesCore:
|
class SafeEyesCore:
|
||||||
scheduler_job_id = "safe_eyes_scheduler"
|
|
||||||
break_count = 0
|
break_count = 0
|
||||||
long_break_message_index = 0
|
long_break_message_index = 0
|
||||||
short_break_message_index = 0
|
short_break_message_index = 0
|
||||||
|
@ -59,16 +57,19 @@ class SafeEyesCore:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Pause the scheduler until the break
|
# Pause the scheduler until the break
|
||||||
if self.scheduler:
|
if self.scheduler and self.scheduled_job:
|
||||||
self.scheduler.pause_job(self.scheduler_job_id)
|
self.scheduler.unschedule_job(self.scheduled_job)
|
||||||
|
self.scheduled_job = None
|
||||||
|
|
||||||
GLib.idle_add(lambda: self.process_job())
|
GLib.idle_add(lambda: self.process_job())
|
||||||
|
|
||||||
|
|
||||||
def process_job(self):
|
def process_job(self):
|
||||||
if self.is_full_screen_app_found():
|
if self.is_full_screen_app_found():
|
||||||
|
# If full screen app found, do not show break screen.
|
||||||
|
# Resume the scheduler
|
||||||
if self.scheduler:
|
if self.scheduler:
|
||||||
self.scheduler.resume_job(self.scheduler_job_id)
|
self.scheduled_job = self.scheduler.add_interval_job(self.scheduler_job, minutes=self.break_interval)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.break_count = ((self.break_count + 1) % self.no_of_short_breaks_per_long_break)
|
self.break_count = ((self.break_count + 1) % self.no_of_short_breaks_per_long_break)
|
||||||
|
@ -83,6 +84,7 @@ class SafeEyesCore:
|
||||||
# Wait for the pre break warning period
|
# Wait for the pre break warning period
|
||||||
time.sleep(self.pre_break_warning_time)
|
time.sleep(self.pre_break_warning_time)
|
||||||
|
|
||||||
|
# User can disable SafeEyes during notification
|
||||||
if self.active:
|
if self.active:
|
||||||
message = ""
|
message = ""
|
||||||
if self.is_long_break():
|
if self.is_long_break():
|
||||||
|
@ -114,14 +116,14 @@ class SafeEyesCore:
|
||||||
time.sleep(1) # Sleep for 1 second
|
time.sleep(1) # Sleep for 1 second
|
||||||
seconds -= 1
|
seconds -= 1
|
||||||
|
|
||||||
# Timeout -> Close the break alert
|
# Loop terminated because of timeout (not skipped) -> Close the break alert
|
||||||
if not self.skipped:
|
if not self.skipped:
|
||||||
self.end_break()
|
self.end_break()
|
||||||
|
|
||||||
# Resume the scheduler
|
# Resume the scheduler
|
||||||
if self.active:
|
if self.active:
|
||||||
if self.scheduler:
|
if self.scheduler:
|
||||||
self.scheduler.resume_job(self.scheduler_job_id)
|
self.scheduled_job = self.scheduler.add_interval_job(self.scheduler_job, minutes=self.break_interval)
|
||||||
|
|
||||||
self.skipped = False
|
self.skipped = False
|
||||||
|
|
||||||
|
@ -131,6 +133,7 @@ class SafeEyesCore:
|
||||||
def is_long_break(self):
|
def is_long_break(self):
|
||||||
return self.break_count == self.no_of_short_breaks_per_long_break - 1
|
return self.break_count == self.no_of_short_breaks_per_long_break - 1
|
||||||
|
|
||||||
|
# User skipped the break using Skip button
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.skipped = True
|
self.skipped = True
|
||||||
|
|
||||||
|
@ -141,7 +144,7 @@ class SafeEyesCore:
|
||||||
if not self.active:
|
if not self.active:
|
||||||
self.active = True
|
self.active = True
|
||||||
if self.scheduler:
|
if self.scheduler:
|
||||||
self.scheduler.resume_job(self.scheduler_job_id)
|
self.scheduled_job = self.scheduler.add_interval_job(self.scheduler_job, minutes=self.break_interval)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Pause the timer
|
Pause the timer
|
||||||
|
@ -149,13 +152,16 @@ class SafeEyesCore:
|
||||||
def pause(self):
|
def pause(self):
|
||||||
if self.active:
|
if self.active:
|
||||||
self.active = False
|
self.active = False
|
||||||
if self.scheduler:
|
if self.scheduler and self.scheduled_job:
|
||||||
self.scheduler.pause_job(self.scheduler_job_id)
|
self.scheduler.unschedule_job(self.scheduled_job)
|
||||||
|
self.scheduled_job = None
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.scheduler:
|
if self.scheduler:
|
||||||
self.active = False
|
self.active = False
|
||||||
self.scheduler.pause_job(self.scheduler_job_id)
|
if self.scheduled_job:
|
||||||
|
self.scheduler.unschedule_job(self.scheduled_job)
|
||||||
|
self.scheduled_job = None
|
||||||
self.scheduler.shutdown(wait=False)
|
self.scheduler.shutdown(wait=False)
|
||||||
self.scheduler = None
|
self.scheduler = None
|
||||||
|
|
||||||
|
@ -165,8 +171,8 @@ class SafeEyesCore:
|
||||||
def start(self):
|
def start(self):
|
||||||
self.active = True
|
self.active = True
|
||||||
if not self.scheduler:
|
if not self.scheduler:
|
||||||
self.scheduler = BackgroundScheduler()
|
self.scheduler = Scheduler()
|
||||||
self.scheduler.add_job(self.scheduler_job, 'interval', minutes=self.break_interval, id=self.scheduler_job_id)
|
self.scheduled_job = self.scheduler.add_interval_job(self.scheduler_job, minutes=self.break_interval)
|
||||||
self.scheduler.start()
|
self.scheduler.start()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -100,7 +100,7 @@ def disable_safeeyes():
|
||||||
|
|
||||||
def prepare_local_config_dir():
|
def prepare_local_config_dir():
|
||||||
config_dir_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/style')
|
config_dir_path = os.path.join(os.path.expanduser('~'), '.config/safeeyes/style')
|
||||||
startup_file_path = os.path.join(os.path.expanduser('~'), '.config/autostart/safeeyes.desktop')
|
startup_dir_path = os.path.join(os.path.expanduser('~'), '.config/autostart')
|
||||||
try:
|
try:
|
||||||
os.makedirs(config_dir_path)
|
os.makedirs(config_dir_path)
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
|
@ -111,8 +111,17 @@ def prepare_local_config_dir():
|
||||||
|
|
||||||
if not os.path.isfile(config_file_path):
|
if not os.path.isfile(config_file_path):
|
||||||
shutil.copy2(system_config_file_path, config_file_path)
|
shutil.copy2(system_config_file_path, config_file_path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(startup_dir_path)
|
||||||
|
except OSError as exc:
|
||||||
|
if exc.errno == errno.EEXIST and os.path.isdir(startup_dir_path):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise
|
||||||
|
|
||||||
# Add to startup for the first time only
|
# Add to startup for the first time only
|
||||||
shutil.copy2(desktop_file, startup_file_path)
|
shutil.copy2(desktop_file, (startup_dir_path + "/safeeyes.desktop"))
|
||||||
|
|
||||||
if not os.path.isfile(style_sheet_path):
|
if not os.path.isfile(style_sheet_path):
|
||||||
shutil.copy2(system_style_sheet_path, style_sheet_path)
|
shutil.copy2(system_style_sheet_path, style_sheet_path)
|
||||||
|
|
Loading…
Reference in New Issue