diff --git a/safeeyes/SafeEyes.py b/safeeyes/SafeEyes.py index a5eaa70..3c89aed 100644 --- a/safeeyes/SafeEyes.py +++ b/safeeyes/SafeEyes.py @@ -79,13 +79,15 @@ class SafeEyes(object): self.plugins_manager = PluginManager(self.context, self.config) self.safe_eyes_core = SafeEyesCore(self.context) self.safe_eyes_core.on_pre_break += self.plugins_manager.pre_break - self.safe_eyes_core.on_start_break += self.start_break + self.safe_eyes_core.on_start_break += self.on_start_break + self.safe_eyes_core.start_break += self.start_break self.safe_eyes_core.on_count_down += self.countdown self.safe_eyes_core.on_stop_break += self.stop_break self.safe_eyes_core.on_update_next_break += self.update_next_break self.safe_eyes_core.initialize(self.config) self.context['api']['take_break'] = lambda: Utility.execute_main_thread(self.safe_eyes_core.take_break) self.context['api']['has_breaks'] = self.safe_eyes_core.has_breaks + self.context['api']['postpone'] = self.safe_eyes_core.postpone self.plugins_manager.init(self.context, self.config) atexit.register(self.persist_session) self.rpc_server = RPCServer(self.config.get('rpc_port'), self.context) @@ -223,16 +225,21 @@ class SafeEyes(object): status = _('Disabled until restart') self._status = status - def start_break(self, break_obj): + def on_start_break(self, break_obj): """ - Pass the break information to plugins and break screen. + Pass the break information to plugins. """ if not self.plugins_manager.start_break(break_obj): return False + return True + + def start_break(self, break_obj): + """ + Pass the break information to break screen. + """ # Get the HTML widgets content from plugins widget = self.plugins_manager.get_break_screen_widgets(break_obj) self.break_screen.show_message(break_obj, widget) - return True def countdown(self, countdown, seconds): """ @@ -270,7 +277,7 @@ class SafeEyes(object): Return the status of Safe Eyes. """ return self._status - + def persist_session(self): """ Save the session object to the session file. diff --git a/safeeyes/SafeEyesCore.py b/safeeyes/SafeEyesCore.py index 660d843..0d3319d 100644 --- a/safeeyes/SafeEyesCore.py +++ b/safeeyes/SafeEyesCore.py @@ -47,15 +47,19 @@ class SafeEyesCore(object): self.long_break_duration = 0 self.next_break_index = context['session'].get('next_break_index', 0) self.postpone_duration = 0 + self.default_postpone_duration = 0 self.pre_break_warning_time = 0 self.running = False self.short_break_duration = 0 - self.scheduled_next_break_time = -1 + self.scheduled_next_break_timestamp = -1 + self.scheduled_next_break_time = None self.paused_time = -1 # This event is fired before for a break self.on_pre_break = EventHook() - # This event is fired at the start of a break + # This event is fired just before the start of a break self.on_start_break = EventHook() + # This event is fired at the start of a break + self.start_break = EventHook() # This event is fired during every count down self.on_count_down = EventHook() # This event is fired at the end of a break @@ -79,8 +83,9 @@ class SafeEyesCore(object): self.pre_break_warning_time = config.get('pre_break_warning_time') self.long_break_duration = config.get('long_break_duration') self.short_break_duration = config.get('short_break_duration') - self.break_interval = config.get('break_interval') * 60 # Convert to seconds - self.postpone_duration = config.get('postpone_duration') * 60 # Convert to seconds + self.break_interval = config.get('break_interval') * 60 # Convert to seconds + self.default_postpone_duration = config.get('postpone_duration') * 60 # Convert to seconds + self.postpone_duration = self.default_postpone_duration self.__init_breaks(BreakType.SHORT_BREAK, config.get('short_breaks'), config.get('no_of_short_breaks_per_long_break')) self.__init_breaks(BreakType.LONG_BREAK, config.get('long_breaks'), config.get('no_of_short_breaks_per_long_break')) @@ -101,7 +106,7 @@ class SafeEyesCore(object): if not self.running: logging.info("Start Safe Eyes core") self.running = True - self.scheduled_next_break_time = int(next_break_time) + self.scheduled_next_break_timestamp = int(next_break_time) Utility.start_thread(self.__scheduler_job) def stop(self): @@ -128,10 +133,15 @@ class SafeEyesCore(object): """ self.context['skipped'] = True - def postpone(self): + def postpone(self, duration=-1): """ User postponed the break using Postpone button """ + if duration > 0: + self.postpone_duration = duration + else: + self.postpone_duration = self.default_postpone_duration + logging.debug("Postpone the break for %d seconds", self.postpone_duration) self.context['postponed'] = True def take_break(self): @@ -199,13 +209,13 @@ class SafeEyesCore(object): logging.info('Skip next long break due to the pause longer than break duration') # Skip the next long break self.__select_next_break() - - if current_timestamp < self.scheduled_next_break_time: - time_to_wait = round(self.scheduled_next_break_time - current_timestamp) - self.scheduled_next_break_time = -1 - next_break_time = current_time + datetime.timedelta(seconds=time_to_wait) - Utility.execute_main_thread(self.__fire_on_update_next_break, next_break_time) + if current_timestamp < self.scheduled_next_break_timestamp: + time_to_wait = round(self.scheduled_next_break_timestamp - current_timestamp) + self.scheduled_next_break_timestamp = -1 + + self.scheduled_next_break_time = current_time + datetime.timedelta(seconds=time_to_wait) + Utility.execute_main_thread(self.__fire_on_update_next_break, self.scheduled_next_break_time) if self.__is_long_break(): self.context['break_type'] = 'long' @@ -249,13 +259,27 @@ class SafeEyesCore(object): return Utility.execute_main_thread(self.__fire_start_break) + def __postpone_break(self): + self.__wait_for(self.postpone_duration) + Utility.execute_main_thread(self.__fire_start_break) + def __fire_start_break(self): # Show the break screen if not self.on_start_break.fire(self.breaks[self.next_break_index]): - # Plugins wanted to ignore this break + # Plugins want to ignore this break self.__start_next_break() return - Utility.start_thread(self.__start_break) + if self.context['postponed']: + # Plugins want to postpone this break + self.context['postponed'] = False + # Update the next break time + self.scheduled_next_break_time = self.scheduled_next_break_time + datetime.timedelta(seconds=self.postpone_duration) + self.__fire_on_update_next_break(self.scheduled_next_break_time) + # Wait in user thread + Utility.start_thread(self.__postpone_break) + else: + self.start_break.fire(self.breaks[self.next_break_index]) + Utility.start_thread(self.__start_break) def __start_break(self): """ diff --git a/safeeyes/config/locale/ar/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/ar/LC_MESSAGES/safeeyes.po index 4e2fc4f..0d2a7c8 100644 --- a/safeeyes/config/locale/ar/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/ar/LC_MESSAGES/safeeyes.po @@ -335,6 +335,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/bg/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/bg/LC_MESSAGES/safeeyes.po index ec9bb36..a928976 100644 --- a/safeeyes/config/locale/bg/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/bg/LC_MESSAGES/safeeyes.po @@ -333,6 +333,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/ca/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/ca/LC_MESSAGES/safeeyes.po index f849d9c..7046e52 100644 --- a/safeeyes/config/locale/ca/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/ca/LC_MESSAGES/safeeyes.po @@ -337,6 +337,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/cs/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/cs/LC_MESSAGES/safeeyes.po index 9f19bbc..c1b2a70 100644 --- a/safeeyes/config/locale/cs/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/cs/LC_MESSAGES/safeeyes.po @@ -339,6 +339,10 @@ msgstr "" "Považovat čas nečinnosti trvající stejně, jako nadcházející přestávka, za " "přestávku" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Oznamovací oblast" diff --git a/safeeyes/config/locale/da/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/da/LC_MESSAGES/safeeyes.po index d3eefcf..9e72ae5 100644 --- a/safeeyes/config/locale/da/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/da/LC_MESSAGES/safeeyes.po @@ -349,6 +349,10 @@ msgstr "Mindste tomgangstid for at pause Safe Eyes (i sekunder)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Fortolk inaktiv tid svarende til kommende pause varighed som en pause" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon #, fuzzy msgid "Tray Icon" diff --git a/safeeyes/config/locale/de/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/de/LC_MESSAGES/safeeyes.po index e640a66..e7a3590 100644 --- a/safeeyes/config/locale/de/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/de/LC_MESSAGES/safeeyes.po @@ -337,6 +337,10 @@ msgstr "Maximaldauer Leerlauf zum Pausieren (in Sekunden)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Mit Pausendauer gleiche Leerlaufdauer als Pause interpretieren" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Symbol im Tray" diff --git a/safeeyes/config/locale/en_US/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/en_US/LC_MESSAGES/safeeyes.po index 4111869..04ddd53 100644 --- a/safeeyes/config/locale/en_US/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/en_US/LC_MESSAGES/safeeyes.po @@ -337,6 +337,10 @@ msgstr "Minimum idle time to pause Safe Eyes (in seconds)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Interpret idle time equivalent to upcoming break duration as a break" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Tray Icon" diff --git a/safeeyes/config/locale/es/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/es/LC_MESSAGES/safeeyes.po index 62d7296..1f5b577 100644 --- a/safeeyes/config/locale/es/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/es/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "Tiempo minimo inactivo para pausar Safe Eyes (en segundos)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Icono de bandeja" diff --git a/safeeyes/config/locale/et/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/et/LC_MESSAGES/safeeyes.po index 7609bae..6c07a73 100644 --- a/safeeyes/config/locale/et/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/et/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "Minimaalne süsteemi jõudeoleku aeg programmi peatamiseks (sekundites)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Arvesta järgmise pausi aja sisse sellele eelnenud puhkeaeg" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Paneeliikoon" diff --git a/safeeyes/config/locale/fa/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/fa/LC_MESSAGES/safeeyes.po index 3d97421..c5dd4f8 100644 --- a/safeeyes/config/locale/fa/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/fa/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/fr/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/fr/LC_MESSAGES/safeeyes.po index d8d0dd1..71571d3 100644 --- a/safeeyes/config/locale/fr/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/fr/LC_MESSAGES/safeeyes.po @@ -345,6 +345,10 @@ msgstr "" "Interpréter le temps d’inactivité équivalent à la pause à venir comme une " "pause" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Icône de notification" diff --git a/safeeyes/config/locale/hi/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/hi/LC_MESSAGES/safeeyes.po index 22067a8..074fa1a 100644 --- a/safeeyes/config/locale/hi/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/hi/LC_MESSAGES/safeeyes.po @@ -334,6 +334,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/hu/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/hu/LC_MESSAGES/safeeyes.po index 6fcbf37..eedc118 100644 --- a/safeeyes/config/locale/hu/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/hu/LC_MESSAGES/safeeyes.po @@ -335,6 +335,10 @@ msgstr "Minimális üresjárati idő a Safe Eyes felfüggesztéséhez (mp)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Tálca Ikon" diff --git a/safeeyes/config/locale/id/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/id/LC_MESSAGES/safeeyes.po index 5bd3d30..ceada1c 100644 --- a/safeeyes/config/locale/id/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/id/LC_MESSAGES/safeeyes.po @@ -333,6 +333,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/it/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/it/LC_MESSAGES/safeeyes.po index 3a14c90..14b1fa8 100644 --- a/safeeyes/config/locale/it/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/it/LC_MESSAGES/safeeyes.po @@ -342,6 +342,10 @@ msgstr "" "Considera il tempo di inattività del computer equivalente alla durata della " "prossima pausa" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Icona" diff --git a/safeeyes/config/locale/lt/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/lt/LC_MESSAGES/safeeyes.po index afd8b2c..9ef1bce 100644 --- a/safeeyes/config/locale/lt/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/lt/LC_MESSAGES/safeeyes.po @@ -342,6 +342,10 @@ msgstr "" "Laikyti neveiklumo laiką, kuris lygus būsimos pertraukos trukmei, kaip " "pertrauką" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Dėklo piktograma" diff --git a/safeeyes/config/locale/mk/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/mk/LC_MESSAGES/safeeyes.po index 831afa4..621bb87 100644 --- a/safeeyes/config/locale/mk/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/mk/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/nb/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/nb/LC_MESSAGES/safeeyes.po index 9664e8d..8a3fc06 100644 --- a/safeeyes/config/locale/nb/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/nb/LC_MESSAGES/safeeyes.po @@ -8,8 +8,8 @@ msgstr "" "POT-Creation-Date: \n" "PO-Revision-Date: 2018-06-22 23:16+0000\n" "Last-Translator: Allan Nordhøy \n" -"Language-Team: Norwegian Bokmål \n" +"Language-Team: Norwegian Bokmål \n" "Language: nb\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -334,6 +334,10 @@ msgstr "Minimal lediggang å pause Øyetrygg etter (i sekunder)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Tolk lediggang som leder opp mot en pause som pause" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Systemkurvisikon" diff --git a/safeeyes/config/locale/nl/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/nl/LC_MESSAGES/safeeyes.po index e45526d..46c621c 100644 --- a/safeeyes/config/locale/nl/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/nl/LC_MESSAGES/safeeyes.po @@ -340,6 +340,10 @@ msgstr "Minimale tijd dat systeem inactief moet zijn (in seconden)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Inactief opvatten als aankomende pauzeduur" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Systeemvakpictogram" diff --git a/safeeyes/config/locale/pl/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/pl/LC_MESSAGES/safeeyes.po index 8441af3..4a33709 100644 --- a/safeeyes/config/locale/pl/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/pl/LC_MESSAGES/safeeyes.po @@ -339,6 +339,10 @@ msgstr "" "Interpretuj czas bezczynności odpowiadający zbliżonemu czasowi trwania " "przerwy jako przerwę" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Ikona w zasobniku" diff --git a/safeeyes/config/locale/pt/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/pt/LC_MESSAGES/safeeyes.po index e132b0e..ea755c8 100644 --- a/safeeyes/config/locale/pt/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/pt/LC_MESSAGES/safeeyes.po @@ -341,6 +341,10 @@ msgstr "" "Interprete o tempo ocioso equivalente à duração da próxima parada como uma " "parada" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Ícone de bandeja" diff --git a/safeeyes/config/locale/ru/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/ru/LC_MESSAGES/safeeyes.po index 4357832..33fce10 100644 --- a/safeeyes/config/locale/ru/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/ru/LC_MESSAGES/safeeyes.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=" -"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" "X-Generator: Weblate 3.1-dev\n" # Short break @@ -337,6 +337,10 @@ msgstr "" "Интерпретировать время простоя равное продолжительности предстоящего " "перерыва как перерыв" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Иконка в трее" diff --git a/safeeyes/config/locale/safeeyes.pot b/safeeyes/config/locale/safeeyes.pot index c1aa0fc..0792e93 100644 --- a/safeeyes/config/locale/safeeyes.pot +++ b/safeeyes/config/locale/safeeyes.pot @@ -322,6 +322,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/sk/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/sk/LC_MESSAGES/safeeyes.po index 27d2213..9917726 100644 --- a/safeeyes/config/locale/sk/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/sk/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "Pozastaviť Safe Eyes pri nečinnost dlhšej ako (v sekundách)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "Započítaj čas, kedy počítač nie je používaný, do prestávky" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Ikona na paneli" diff --git a/safeeyes/config/locale/sv/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/sv/LC_MESSAGES/safeeyes.po index b846b71..1cca76e 100644 --- a/safeeyes/config/locale/sv/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/sv/LC_MESSAGES/safeeyes.po @@ -333,6 +333,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/ta/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/ta/LC_MESSAGES/safeeyes.po index cdfffb7..c92da74 100644 --- a/safeeyes/config/locale/ta/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/ta/LC_MESSAGES/safeeyes.po @@ -340,6 +340,10 @@ msgstr "Safe Eyesஐ இடைநிறுத்துவதற்கான க msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "அடுத்த இடைவேளையின் காலத்திற்கு சமனான செயலற்ற நேரத்தை இடைவேளையாக கருதுக" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "கணினி செயலற்ற நிலைக்கு வரும் வரை அடுத்த இடைவேளையை தாமதப்படுத்தவும்" + #: plugins/trayicon msgid "Tray Icon" msgstr "Safe Eyes சின்னம்" diff --git a/safeeyes/config/locale/tr/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/tr/LC_MESSAGES/safeeyes.po index 10ca3fe..fba8be4 100644 --- a/safeeyes/config/locale/tr/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/tr/LC_MESSAGES/safeeyes.po @@ -340,6 +340,10 @@ msgstr "" "Sıradaki mola süresine eşit miktarda boşta zaman geçtiyse bunu mola olarak " "değerlendir" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Tepsi simgesi" diff --git a/safeeyes/config/locale/ug/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/ug/LC_MESSAGES/safeeyes.po index 4e1df4b..ad55e82 100644 --- a/safeeyes/config/locale/ug/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/ug/LC_MESSAGES/safeeyes.po @@ -333,6 +333,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/config/locale/uk/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/uk/LC_MESSAGES/safeeyes.po index 8f9ff74..e88fed5 100644 --- a/safeeyes/config/locale/uk/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/uk/LC_MESSAGES/safeeyes.po @@ -14,8 +14,8 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=" -"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" "X-Generator: Weblate 3.1-dev\n" # Short break @@ -342,6 +342,10 @@ msgstr "" "Інтерпретувати час простою, що дорівнює часу до найближчої перерви, як " "перерву" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Значок в лотку" diff --git a/safeeyes/config/locale/vi/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/vi/LC_MESSAGES/safeeyes.po index f7487d8..c212009 100644 --- a/safeeyes/config/locale/vi/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/vi/LC_MESSAGES/safeeyes.po @@ -340,6 +340,10 @@ msgstr "" "Diễn tả thời gian rỗi tương đương với thời gian nghỉ sắp tới như là một giờ " "nghỉ" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "Biểu tượng khay" diff --git a/safeeyes/config/locale/zh_CN/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/zh_CN/LC_MESSAGES/safeeyes.po index f33b597..1532b5c 100644 --- a/safeeyes/config/locale/zh_CN/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/zh_CN/LC_MESSAGES/safeeyes.po @@ -336,6 +336,10 @@ msgstr "暂停 Safe Eyes 的最短时间(秒)" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "将系统空闲时间作为下次休息时长来对待" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "托盘图标" diff --git a/safeeyes/config/locale/zh_TW/LC_MESSAGES/safeeyes.po b/safeeyes/config/locale/zh_TW/LC_MESSAGES/safeeyes.po index 134c7a6..11fddb3 100644 --- a/safeeyes/config/locale/zh_TW/LC_MESSAGES/safeeyes.po +++ b/safeeyes/config/locale/zh_TW/LC_MESSAGES/safeeyes.po @@ -334,6 +334,10 @@ msgstr "" msgid "Interpret idle time equivalent to upcoming break duration as a break" msgstr "" +# plugin/smartpause +msgid "Postpone the next break until the system becomes idle" +msgstr "" + #: plugins/trayicon msgid "Tray Icon" msgstr "" diff --git a/safeeyes/plugins/smartpause/config.json b/safeeyes/plugins/smartpause/config.json index 963eac5..fbefb56 100644 --- a/safeeyes/plugins/smartpause/config.json +++ b/safeeyes/plugins/smartpause/config.json @@ -2,7 +2,7 @@ "meta": { "name": "Smart Pause", "description": "Pause Safe Eyes if the system is idle", - "version": "0.0.2" + "version": "0.0.3" }, "dependencies": { "python_modules": [], @@ -25,6 +25,12 @@ "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", + "type": "BOOL", + "default": false } ] } \ No newline at end of file diff --git a/safeeyes/plugins/smartpause/plugin.py b/safeeyes/plugins/smartpause/plugin.py index acded0d..d13cf28 100644 --- a/safeeyes/plugins/smartpause/plugin.py +++ b/safeeyes/plugins/smartpause/plugin.py @@ -50,7 +50,7 @@ def __system_idle_time(): Return the idle time if xprintidle is available, otherwise return 0. """ try: - return int(subprocess.check_output(['xprintidle']).decode('utf-8')) / 1000 # Convert to seconds + return int(subprocess.check_output(['xprintidle']).decode('utf-8')) / 1000 # Convert to seconds except BaseException: return 0 @@ -81,18 +81,22 @@ def init(ctx, safeeyes_config, plugin_config): global context global enable_safe_eyes global disable_safe_eyes + global postpone global idle_time global break_interval global waiting_time global interpret_idle_as_break + global postpone_if_active logging.debug('Initialize Smart Pause plugin') context = ctx enable_safe_eyes = context['api']['enable_safeeyes'] disable_safe_eyes = 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'] break_interval = safeeyes_config.get('break_interval') * 60 # Convert to seconds - waiting_time = min(2, idle_time) # If idle time is 1 sec, wait only 1 sec + waiting_time = min(2, idle_time) # If idle time is 1 sec, wait only 1 sec def __start_idle_monitor(): @@ -169,3 +173,14 @@ def update_next_break(break_obj, dateTime): global next_break_duration next_break_time = dateTime next_break_duration = break_obj.time + + +def on_start_break(break_obj): + """ + Lifecycle method executes just before the break. + """ + if postpone_if_active: + # Postpone this break if the user is active + system_idle_time = __system_idle_time() + if system_idle_time < 2: + postpone(2) # Postpone for 2 seconds diff --git a/update-po.sh b/update-po.sh new file mode 100755 index 0000000..9e04d07 --- /dev/null +++ b/update-po.sh @@ -0,0 +1,8 @@ +#!/bin/bash +for filename in safeeyes/config/locale/*/LC_MESSAGES/safeeyes.po; do + echo "$filename" + msgmerge -U "$filename" safeeyes/config/locale/safeeyes.pot + if [ -f "$filename~" ] ; then + rm "$filename~" + fi +done \ No newline at end of file