Skip to content
7 changes: 2 additions & 5 deletions safeeyes/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,13 @@ def initialize(self, config: Config):

self.postpone_duration = self.default_postpone_duration

def start(self, next_break_time=-1, reset_breaks=False) -> None:
def start(self, next_break_time=-1) -> None:
"""Start Safe Eyes is it is not running already."""
if self._break_queue is None:
logging.info("No breaks defined, not starting the core")
return
if not self.running:
logging.info("Start Safe Eyes core")
if reset_breaks:
logging.info("Reset breaks to start from the beginning")
self._break_queue.reset()

self.running = True
self.scheduled_next_break_timestamp = int(next_break_time)
Expand Down Expand Up @@ -204,7 +201,7 @@ def __scheduler_job(self) -> None:
paused_duration,
)
# Skip the next long break
self._break_queue.reset()
self._break_queue.skip_long_break()

if self.context["postponed"]:
# Previous break was postponed
Expand Down
25 changes: 17 additions & 8 deletions safeeyes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,23 @@ def __set_next_break(self, break_type: typing.Optional[BreakType] = None) -> Non
self.__current_break = break_obj
self.context["session"]["break"] = self.__current_break.name

def reset(self) -> None:
if self.__short_queue:
for break_object in self.__short_queue:
break_object.time = self.__short_break_time

if self.__long_queue:
for break_object in self.__long_queue:
break_object.time = self.__long_break_time
def skip_long_break(self) -> None:
if not (self.__short_queue and self.__long_queue):
return

for break_object in self.__short_queue:
break_object.time = self.__short_break_time

for break_object in self.__long_queue:
break_object.time = self.__long_break_time

if self.__current_break.type == BreakType.LONG_BREAK:
# Note: this skips the long break, meaning the following long break
# won't be the current one, but the next one after
# we could decrement the __current_long counter, but then we'd need to
# handle wraparound and possibly randomizing, which seems complicated
self.__current_break = self.__next_short()
self.context["session"]["break"] = self.__current_break.name

def is_empty(self, break_type: BreakType) -> bool:
"""Check if the given break type is empty or not."""
Expand Down
8 changes: 4 additions & 4 deletions safeeyes/safeeyes.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def do_startup(self):
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
lambda next_break_time=-1: utility.execute_main_thread(
self.enable_safeeyes, next_break_time
)
)
self.context["api"]["disable_safeeyes"] = (
Expand Down Expand Up @@ -494,15 +494,15 @@ def restart(self, config, set_active=False):
self.safe_eyes_core.start()
self.plugins_manager.start()

def enable_safeeyes(self, scheduled_next_break_time=-1, reset_breaks=False):
def enable_safeeyes(self, scheduled_next_break_time=-1):
"""Listen to tray icon enable action and send the signal to core."""
if (
not self.required_plugin_dialog_active
and not self.active
and self.safe_eyes_core.has_breaks()
):
self.active = True
self.safe_eyes_core.start(scheduled_next_break_time, reset_breaks)
self.safe_eyes_core.start(scheduled_next_break_time)
self.plugins_manager.start()

def disable_safeeyes(self, status=None, is_resting=False):
Expand Down
Loading