77from aqt .webview import AnkiWebView
88from aqt .theme import theme_manager
99from aqt .qt import QColor , QPalette , Qt
10+ from anki .utils import is_mac
1011
1112from .ankiaddonconfig import ConfigManager
1213
@@ -111,7 +112,7 @@ def wrap_style(css: str) -> str:
111112 return f"<style>{ css } </style>"
112113
113114
114- def get_theme_css () -> Tuple [str , str ]:
115+ def get_theme_css () -> Tuple [str , str , str ]:
115116 conf .load ()
116117 colors_config = conf ["colors" ]
117118
@@ -126,17 +127,31 @@ def get_theme_css() -> Tuple[str, str]:
126127 light_mode_css += f"{ css_name } : { entry [1 ]} ;\n "
127128 dark_mode_css += f"{ css_name } : { entry [2 ]} ;\n "
128129
129- return (light_mode_css , dark_mode_css )
130+ extra_css = """
131+ .isMac button {
132+ background: var(--button-bg);
133+ }
134+ .night-mode .isMac button {
135+ --canvas: %s;
136+ --fg: %s;
137+ }
138+ """ % (
139+ conf ["colors.button-bg.2" ],
140+ conf ["colors.fg.2" ],
141+ )
142+
143+ return (light_mode_css , dark_mode_css , extra_css )
130144
131145
132146def inject_web (web_content : aqt .webview .WebContent , context : Optional [Any ]) -> None :
133- (light_mode_css , dark_mode_css ) = get_theme_css ()
147+ (light_mode_css , dark_mode_css , extra_css ) = get_theme_css ()
134148 web_content .head += (
135149 "<style id='recolor-light'>body { \n %s }</style>" % light_mode_css
136150 )
137151 web_content .head += (
138152 "<style id='recolor-dark'>body.night_mode { \n %s }</style>" % dark_mode_css
139153 )
154+ web_content .head += "<style id='recolor-extra'>%s</style>" % extra_css
140155
141156
142157webviews : List [AnkiWebView ] = []
@@ -149,7 +164,7 @@ def recolor_web() -> None:
149164
150165
151166def update_webview_css (webview : AnkiWebView ) -> None :
152- (light_mode_css , dark_mode_css ) = get_theme_css ()
167+ (light_mode_css , dark_mode_css , extra_css ) = get_theme_css ()
153168 webview .eval (
154169 "document.getElementById('recolor-light').innerHTML = `body { \n %s }`"
155170 % light_mode_css
@@ -158,6 +173,9 @@ def update_webview_css(webview: AnkiWebView) -> None:
158173 "document.getElementById('recolor-dark').innerHTML = `body.night_mode { \n %s }`"
159174 % dark_mode_css
160175 )
176+ webview .eval (
177+ "document.getElementById('recolor-extra').innerHTML = `%s`" % extra_css
178+ )
161179
162180
163181def on_webview_init (webview : AnkiWebView , * args : Any , ** kwargs : Any ) -> None :
0 commit comments