From ffb5837c538c1d2952fa7e7372c9481cbc2b8eaa Mon Sep 17 00:00:00 2001 From: Chase Christiansen Date: Sun, 12 Jan 2025 13:02:25 -0600 Subject: [PATCH] Add timer to automatically change theme --- yin_yang/__main__.py | 9 +++++++++ yin_yang/repeat_timer.py | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 yin_yang/repeat_timer.py diff --git a/yin_yang/__main__.py b/yin_yang/__main__.py index c5b6bcb..9209776 100755 --- a/yin_yang/__main__.py +++ b/yin_yang/__main__.py @@ -5,6 +5,7 @@ from argparse import ArgumentParser from logging.handlers import RotatingFileHandler from pathlib import Path +from threading import Timer from PySide6 import QtWidgets from PySide6.QtCore import QTranslator, QLibraryInfo, QLocale, QObject @@ -12,14 +13,22 @@ from PySide6.QtWidgets import QSystemTrayIcon, QMenu from systemd import journal +from yin_yang.helpers import is_flatpak from yin_yang.notification_handler import NotificationHandler from yin_yang import daemon_handler from yin_yang.meta import ConfigEvent from yin_yang import theme_switcher from yin_yang.config import config, Modes +from yin_yang.repeat_timer import RepeatTimer from yin_yang.ui import main_window_connector logger = logging.getLogger() +timer = RepeatTimer(45, theme_switcher.set_desired_theme) + +if is_flatpak(): + timer.daemon = True + timer.name = "Yin-Yang Timer" + timer.start() def setup_logger(use_systemd_journal: bool): diff --git a/yin_yang/repeat_timer.py b/yin_yang/repeat_timer.py new file mode 100644 index 0000000..0b2a630 --- /dev/null +++ b/yin_yang/repeat_timer.py @@ -0,0 +1,7 @@ +from threading import Timer + + +class RepeatTimer(Timer): + def run(self): + while not self.finished.wait(self.interval): + self.function(*self.args, **self.kwargs)