def __on_screen_saver_active_changed(self, connection: Gio.DBusConnection, sender_name: str, object_path: str, interface_name: str, signal_name: str, parameters: GLib.Variant) -> None: is_activated, = parameters self.is_lock_screen_activated = is_activated now = datetime.now() if self.is_lock_screen_activated: current_activity = Value.get_or_raise(self.current_activity, 'current_activity') self.previous_wm_class = current_activity.wm_class self.previous_active_window_name = current_activity.window_name wm_class = SpecialWmClass.LOCK_SCREEN.value window_name = '' else: if self.is_work_time: self.last_lock_screen_time = now wm_class = Value.get_or_raise(self.previous_wm_class, 'previous_wm_class') window_name = Value.get_or_raise(self.previous_active_window_name, 'previous_active_window_name') self.on_open_window(wm_class, window_name, now)
def distracting_app_timer_handler(self) -> None: # TODO: ⚡️ run this timer only if work started if not self.is_work_time: return if self.has_distracting_app_overtime_notification_shown: return current_activity = Value.get_or_raise(self.current_activity, 'current_activity') application_info = current_activity.application_info if application_info is None: # NOTE: It is None if detailed/distracting lists do not contain such activity # See more in ApplicationInfoMatcher.set_if_matched() return if not application_info.is_distracting: return now = datetime.now() current_stats = self.holder[application_info.title] total_distracting_time = now - current_activity.start_time + current_stats.work_time if total_distracting_time.total_seconds( ) < self.user_distracting_apps_mins * 60: return self.event.emit(ApplicationEvent.DISTRACTING_APP_OVERTIME.value, application_info.title, total_distracting_time) self.has_distracting_app_overtime_notification_shown = True
def __need_to_show_overtime_notification(self) -> bool: if not self.is_work_time: return False if self.is_lock_screen_activated: return False now = datetime.now() current_activity = Value.get_or_raise(self.current_activity, 'current_activity') seconds_in_current_activity = ( now - current_activity.start_time).total_seconds() total_work_time_seconds = seconds_in_current_activity + self.holder.total_work_time.total_seconds( ) is_overtime_started = total_work_time_seconds >= self.user_work_time_hour_limit * 60 * 60 if not is_overtime_started: return False if self.last_overtime_notification is None: return True if self.last_overtime_notification.last_shown is None: return True if not self.is_overtime_notification_allowed_to_show: return False seconds_from_last_notification = ( now - self.last_overtime_notification.last_shown).total_seconds() interval_seconds = 15 * 60 return seconds_from_last_notification >= interval_seconds
def set_work_time_state(self, value: bool) -> None: if value == self.is_work_time: self.logger.debug( 'Trying to change is_work_time to the same value') return self.is_work_time = value current_activity = Value.get_or_raise(self.current_activity, 'current_activity') now = datetime.now() new_activity = Activity(current_activity.wm_class, current_activity.window_name, now, self.is_work_time) self.__on_activity_changed(current_activity, new_activity) self.is_work_time_update_time = now self.logger.debug(f'Set Work Time to [{self.is_work_time}]') icon = self.active_icon if self.is_work_time else self.disabled_icon self.tray_icon.set_icon_if_exist(icon) if self.is_work_time: self.last_lock_screen_time = now self.last_break_notification = None self.last_overtime_notification = None
def on_name_changed(self, window: Wnck.Window) -> None: now = datetime.now() current_activity = Value.get_or_raise(self.current_activity, 'current_activity') window_name = get_window_name(window) new_activity = Activity(current_activity.wm_class, window_name, now, current_activity.is_work_time) self.__on_activity_changed(current_activity, new_activity)