From e2efcfc5a798dfda1d090e3700d25dc976962db7 Mon Sep 17 00:00:00 2001 From: Sebastian Volland Date: Tue, 22 Jan 2019 04:44:19 +0100 Subject: [PATCH] Programmatically detect theme color (for macOS) (#150) --- src/vorta/models.py | 4 +++- src/vorta/utils.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/vorta/models.py b/src/vorta/models.py index d79c306c..8f20238f 100644 --- a/src/vorta/models.py +++ b/src/vorta/models.py @@ -11,7 +11,7 @@ import peewee as pw from playhouse.migrate import SqliteMigrator, migrate from vorta.i18n import trans_late -from vorta.utils import slugify +from vorta.utils import slugify, uses_dark_mode SCHEMA_VERSION = 10 @@ -241,6 +241,8 @@ def init_db(con): # Create missing settings and update labels. Leave setting values untouched. for setting in get_misc_settings(): s, created = SettingsModel.get_or_create(key=setting['key'], defaults=setting) + if created and setting['key'] == "use_light_icon": + s.value = bool(uses_dark_mode()) s.label = setting['label'] s.save() diff --git a/src/vorta/utils.py b/src/vorta/utils.py index e70f51d8..2965a16a 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -209,6 +209,19 @@ def set_tray_icon(tray, active=False): tray.setIcon(icon) +def uses_dark_mode(): + """ + This function detects if we are running in dark mode (e.g. macOS dark mode). + + Returns None if the interface style cannot be determined, otherwise a boolean. + """ + if sys.platform == 'darwin': + from Foundation import NSUserDefaults + stdud = NSUserDefaults.standardUserDefaults() + return stdud.stringForKey_("AppleInterfaceStyle") == "Dark" + return None + + def open_app_at_startup(enabled=True): """ This function adds/removes the current app bundle from Login items in macOS