From 763ae5303b0c8deb907832a570840ca029d882ef Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Wed, 24 Dec 2025 10:18:52 -0500 Subject: [PATCH] Fix for thunderbird. --- .../scripts/apps/Thunderbird/meson.build | 3 +- .../scripts/apps/Thunderbird/script.py | 8 ++ .../apps/Thunderbird/script_utilities.py | 97 +++++++++++++++++++ 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/cthulhu/scripts/apps/Thunderbird/script_utilities.py diff --git a/src/cthulhu/scripts/apps/Thunderbird/meson.build b/src/cthulhu/scripts/apps/Thunderbird/meson.build index e2166bb..56489ce 100644 --- a/src/cthulhu/scripts/apps/Thunderbird/meson.build +++ b/src/cthulhu/scripts/apps/Thunderbird/meson.build @@ -1,10 +1,11 @@ thunderbird_python_sources = files([ '__init__.py', 'script.py', + 'script_utilities.py', 'spellcheck.py', ]) python3.install_sources( thunderbird_python_sources, subdir: 'cthulhu/scripts/apps/Thunderbird' -) \ No newline at end of file +) diff --git a/src/cthulhu/scripts/apps/Thunderbird/script.py b/src/cthulhu/scripts/apps/Thunderbird/script.py index 482dc06..e192dff 100644 --- a/src/cthulhu/scripts/apps/Thunderbird/script.py +++ b/src/cthulhu/scripts/apps/Thunderbird/script.py @@ -43,6 +43,7 @@ from cthulhu.ax_object import AXObject from cthulhu.ax_utilities import AXUtilities from .spellcheck import SpellCheck +from .script_utilities import Utilities _settingsManager = settings_manager.getManager() @@ -97,6 +98,11 @@ class Script(Gecko.Script): return SpellCheck(self) + def getUtilities(self): + """Returns the utilities for this script.""" + + return Utilities(self) + def getAppPreferencesGUI(self): """Return a GtkGrid containing the application unique configuration GUI items for the current application.""" @@ -356,6 +362,8 @@ class Script(Gecko.Script): [obj, offset] = self.utilities.findFirstCaretContext(documentFrame, 0) self.utilities.setCaretPosition(obj, offset) self.updateBraille(obj) + if obj and self._navSuspended and self.utilities.inDocumentContent(obj): + self._setNavigationSuspended(False, "message content loaded") if _settingsManager.getSetting('pageSummaryOnLoad'): tokens = ["THUNDERBIRD: Getting page summary for obj", obj] diff --git a/src/cthulhu/scripts/apps/Thunderbird/script_utilities.py b/src/cthulhu/scripts/apps/Thunderbird/script_utilities.py new file mode 100644 index 0000000..90d7583 --- /dev/null +++ b/src/cthulhu/scripts/apps/Thunderbird/script_utilities.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Stormux +# Copyright (c) 2010-2012 The Orca Team +# Copyright (c) 2012 Igalia, S.L. +# Copyright (c) 2005-2010 Sun Microsystems Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., Franklin Street, Fifth Floor, +# Boston MA 02110-1301 USA. +# +# Fork of Orca Screen Reader (GNOME) +# Original source: https://gitlab.gnome.org/GNOME/orca + +"""Thunderbird-specific utility overrides.""" + +__id__ = "$Id$" +__version__ = "$Revision$" +__date__ = "$Date$" +__copyright__ = "Copyright (c) 2010 Joanmarie Diggs." +__license__ = "LGPL" + +import cthulhu.debug as debug +from cthulhu.ax_object import AXObject +from cthulhu.ax_utilities import AXUtilities +from cthulhu.scripts.toolkits.Gecko.script_utilities import Utilities as GeckoUtilities + + +class Utilities(GeckoUtilities): + + def __init__(self, script): + super().__init__(script) + + def getDocumentForObject(self, obj): + document = super().getDocumentForObject(obj) + if document: + return document + + documentFrame = self._messageDocumentFrameFor(obj) + if not documentFrame: + return None + + tokens = ["THUNDERBIRD: Treating document frame as document:", documentFrame] + debug.printTokens(debug.LEVEL_INFO, tokens, True) + return documentFrame + + def getTopLevelDocumentForObject(self, obj): + document = super().getTopLevelDocumentForObject(obj) + if document: + return document + + documentFrame = self._messageDocumentFrameFor(obj) + if not documentFrame: + return None + + tokens = ["THUNDERBIRD: Treating document frame as top-level document:", documentFrame] + debug.printTokens(debug.LEVEL_INFO, tokens, True) + return documentFrame + + def _messageDocumentFrameFor(self, obj): + if not obj: + return None + + if AXUtilities.is_document_frame(obj) and self._isMessageDocumentFrame(obj): + return obj + + documentFrame = AXObject.find_ancestor(obj, AXUtilities.is_document_frame) + if documentFrame and self._isMessageDocumentFrame(documentFrame): + return documentFrame + + return None + + def _isMessageDocumentFrame(self, obj): + if not obj or not AXUtilities.is_document_frame(obj): + return False + + uri = self.documentFrameURI(obj) + if uri: + for prefix in ("about:message", "mailbox:", "imap:", "imaps:", + "news:", "nntp:", "pop:", "pop3:", + "smtp:", "smtps:"): + if uri.startswith(prefix): + return True + + name = (AXObject.get_name(obj) or "").lower() + return "message" in name