2021-02-04 10:07:34 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
"""Platform-specific functionality."""
|
|
|
|
|
|
|
|
import os
|
2021-10-28 10:46:45 +02:00
|
|
|
import sys
|
2021-02-04 10:07:34 +01:00
|
|
|
from ctypes import CDLL
|
|
|
|
|
|
|
|
import aqt.utils
|
|
|
|
from anki.utils import isMac
|
|
|
|
|
|
|
|
|
|
|
|
def set_dark_mode(enabled: bool) -> bool:
|
|
|
|
"True if setting successful."
|
|
|
|
if not isMac:
|
|
|
|
return False
|
|
|
|
try:
|
|
|
|
_set_dark_mode(enabled)
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
|
|
# swallow exceptions, as library will fail on macOS 10.13
|
|
|
|
print(e)
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def _set_dark_mode(enabled: bool) -> None:
|
2021-10-28 10:46:45 +02:00
|
|
|
if getattr(sys, "frozen", False):
|
|
|
|
path = os.path.join(sys.prefix, "libankihelper.dylib")
|
|
|
|
else:
|
|
|
|
path = os.path.join(aqt.utils.aqt_data_folder(), "lib", "libankihelper.dylib")
|
2021-02-04 10:07:34 +01:00
|
|
|
CDLL(path).set_darkmode_enabled(enabled)
|