Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions dodo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@
:func:`~dodo.settings.html_confirm_open_links` is True.
"""

"""Force the HTML view to use dark mode

By default the HTML view of an email will use black text on a white background, which might
clash hard with your selected theme. This toggle forces the use of the engine's dark mode
instead.
"""
html_dark_mode = False

# visual
theme = themes.nord
"""The GUI theme
Expand Down
15 changes: 14 additions & 1 deletion dodo/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ def __init__(self, a: app.Dodo, thread_id: str, search_query: str, parent: Optio
self.message_profile.installUrlSchemeHandler(b'message', self.message_handler)
self.message_profile.settings().setAttribute(
QWebEngineSettings.WebAttribute.JavascriptEnabled, False)
self.message_profile.settings().setAttribute(
QWebEngineSettings.WebAttribute.ForceDarkMode, settings.html_dark_mode)

# The interceptor must not be garbage collected, so keep a reference
self.url_interceptor = RemoteBlockingUrlRequestInterceptor()
Expand All @@ -558,7 +560,7 @@ def __init__(self, a: app.Dodo, thread_id: str, search_query: str, parent: Optio
page = MessagePage(self.app, self.message_profile, self.message_view)
self.message_view.setPage(page)
self.message_view.setZoomFactor(1.2)
self.message_view.page().setBackgroundColor(QColor(settings.theme['bg']))
self._update_background()

self.layout_panel()

Expand All @@ -569,6 +571,16 @@ def _get_collapsed(self) -> set[str]:
collapsed.add(self.model.message_at(idx)['id'])
return collapsed

def _update_background(self):
if self.html_mode:
if settings.html_dark_mode:
color = 0
else:
color = 0xFFFFFF
else:
color = QColor(settings.theme['bg'])
self.message_view.page().setBackgroundColor(color)

def _restore_collapsed(self, collapsed: set[str]):
self.thread_list.expandAll()
for idx in self.model.iterate_indices():
Expand Down Expand Up @@ -802,6 +814,7 @@ def toggle_html(self) -> None:
"""Toggle between HTML and plain text message view"""

self.html_mode = not self.html_mode
self._update_background()
self.refresh_content()

def reply(self, to_all: bool=True) -> None:
Expand Down