Skip to content

Commit ffb5837

Browse files
committed
Add timer to automatically change theme
1 parent 508b167 commit ffb5837

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

yin_yang/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,30 @@
55
from argparse import ArgumentParser
66
from logging.handlers import RotatingFileHandler
77
from pathlib import Path
8+
from threading import Timer
89

910
from PySide6 import QtWidgets
1011
from PySide6.QtCore import QTranslator, QLibraryInfo, QLocale, QObject
1112
from PySide6.QtGui import QIcon
1213
from PySide6.QtWidgets import QSystemTrayIcon, QMenu
1314
from systemd import journal
1415

16+
from yin_yang.helpers import is_flatpak
1517
from yin_yang.notification_handler import NotificationHandler
1618
from yin_yang import daemon_handler
1719
from yin_yang.meta import ConfigEvent
1820
from yin_yang import theme_switcher
1921
from yin_yang.config import config, Modes
22+
from yin_yang.repeat_timer import RepeatTimer
2023
from yin_yang.ui import main_window_connector
2124

2225
logger = logging.getLogger()
26+
timer = RepeatTimer(45, theme_switcher.set_desired_theme)
27+
28+
if is_flatpak():
29+
timer.daemon = True
30+
timer.name = "Yin-Yang Timer"
31+
timer.start()
2332

2433

2534
def setup_logger(use_systemd_journal: bool):

yin_yang/repeat_timer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from threading import Timer
2+
3+
4+
class RepeatTimer(Timer):
5+
def run(self):
6+
while not self.finished.wait(self.interval):
7+
self.function(*self.args, **self.kwargs)

0 commit comments

Comments
 (0)