From 27fc47b9c42c754ec65df02fe9a038b44b3270f9 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Wed, 12 Aug 2026 11:04:20 +0800 Subject: [PATCH] Expose application UI accessors Signed-off-by: Loren Eteval --- Furious/Actions/Connection.py | 8 +++++-- Furious/Actions/Home.py | 2 +- Furious/Actions/Import.py | 10 ++++---- Furious/Application/TrayIcon.py | 2 +- Furious/Controllers/SettingsController.py | 12 +++++----- Furious/Externals/GenTranslation.py | 28 ++++++++++++----------- Furious/Frozenlib/Globals.py | 6 +++++ Furious/Frozenlib/__init__.py | 4 ++++ Furious/Widget/SubscriptionTableView.py | 2 +- Furious/Window/TextEditorWindow.py | 2 +- 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Furious/Actions/Connection.py b/Furious/Actions/Connection.py index a40ad5ef..8d299cb9 100644 --- a/Furious/Actions/Connection.py +++ b/Furious/Actions/Connection.py @@ -23,7 +23,11 @@ from Furious.Controllers.ConnectionController import ( ConnectionError, ConnectionState, ) -from Furious.Frozenlib import APP, AppConnectionController, AppSettings +from Furious.Frozenlib import ( + AppConnectionController, + AppSettings, + AppSystemTray, +) from Furious.Qt import AppQAction, AppQMessageBox, bootstrapIcon from Furious.Qt import gettext as _ from Furious.Widget.ConnectionProgressWidget import ConnectionProgressWidget @@ -112,7 +116,7 @@ class ConnectAction(AppQAction): def showNotification(message: str): """Present a controller notification through the system tray.""" try: - APP().systemTray.showMessage(message) + AppSystemTray().showMessage(message) except (AttributeError, RuntimeError): pass diff --git a/Furious/Actions/Home.py b/Furious/Actions/Home.py index c2576849..0d5704cb 100644 --- a/Furious/Actions/Home.py +++ b/Furious/Actions/Home.py @@ -48,7 +48,7 @@ class ShowHomePageAction(AppQAction): def triggeredCallback(self, checked): """Handle activation of the action.""" - mainWindow = APP().mainWindow + mainWindow = AppMainWindow() if mainWindow.isMinimized(): mainWindow.showNormal() diff --git a/Furious/Actions/Import.py b/Furious/Actions/Import.py index b5cfc3a6..e0a915bc 100644 --- a/Furious/Actions/Import.py +++ b/Furious/Actions/Import.py @@ -75,7 +75,7 @@ def importURIFromClipboard(clipboard: str): if not factory.isValid(): showMBoxImportError(clipboard) else: - APP().mainWindow.appendNewItemByFactory(factory) + AppMainWindow().appendNewItemByFactory(factory) mbox = MBoxImportSuccess(icon=AppQMessageBox.Icon.Information) mbox.remark = factory.itemRemark @@ -91,7 +91,7 @@ def importURIs(*uris, failureCallback: Union[Callable[[], None], None] = None): dialog = ImportURIsProgressDialog( uris, failureCallback=failureCallback, - parent=getattr(APP(), 'mainWindow', None), + parent=AppMainWindow(), ) dialog.open() @@ -104,7 +104,7 @@ def importURIs(*uris, failureCallback: Union[Callable[[], None], None] = None): factory = profileFromAny(uri.strip()) if factory.isValid(): - APP().mainWindow.appendNewItemByFactory(factory) + AppMainWindow().appendNewItemByFactory(factory) imported.append(factory.itemRemark) @@ -252,7 +252,7 @@ class ImportURIsProgressDialog(AppQDialog): self.currentRemark = self.limitedRemark(remark) - APP().mainWindow.appendNewItemByFactory(factory) + AppMainWindow().appendNewItemByFactory(factory) self.imported.append(remark) else: @@ -432,7 +432,7 @@ class ImportFromFileAction(AppQAction): factory = profileFromAny(plainText, remark=os.path.basename(filename)) if factory.isValid(): - APP().mainWindow.appendNewItemByFactory(factory) + AppMainWindow().appendNewItemByFactory(factory) mbox = MBoxImportSuccess(icon=AppQMessageBox.Icon.Information) mbox.remark = factory.itemRemark diff --git a/Furious/Application/TrayIcon.py b/Furious/Application/TrayIcon.py index dc4bbdbc..84b1b917 100644 --- a/Furious/Application/TrayIcon.py +++ b/Furious/Application/TrayIcon.py @@ -238,7 +238,7 @@ class TrayIcon( def handleActivated(self, reason): """Handle activated.""" if reason == QSystemTrayIcon.ActivationReason.DoubleClick: - APP().mainWindow.show() + AppMainWindow().show() def setCustomToolTip(self): """Set custom tool tip.""" diff --git a/Furious/Controllers/SettingsController.py b/Furious/Controllers/SettingsController.py index 59ab5b6f..b543617f 100644 --- a/Furious/Controllers/SettingsController.py +++ b/Furious/Controllers/SettingsController.py @@ -111,11 +111,11 @@ class SettingsController: try: if enabled: - APP().systemTray.setMonochromeIcon() + AppSystemTray().setMonochromeIcon() elif AppConnectionController().isConnected(): - APP().systemTray.setConnectedIcon() + AppSystemTray().setConnectedIcon() else: - APP().systemTray.setDisconnectedIcon() + AppSystemTray().setDisconnectedIcon() except (AttributeError, RuntimeError): pass @@ -182,7 +182,7 @@ class SettingsController: cls._setBinary(METRICS_COLLECTION_SETTING, enabled) try: - APP().mainWindow.trafficStatsManager.setCollectionEnabled(enabled) + AppMainWindow().trafficStatsManager.setCollectionEnabled(enabled) except (AttributeError, RuntimeError): pass @@ -193,8 +193,8 @@ class SettingsController: try: if enabled: - APP().mainWindow.showTabAndSpaces() + AppMainWindow().showTabAndSpaces() else: - APP().mainWindow.hideTabAndSpaces() + AppMainWindow().hideTabAndSpaces() except (AttributeError, RuntimeError): pass diff --git a/Furious/Externals/GenTranslation.py b/Furious/Externals/GenTranslation.py index 0f16e285..b7e21bf8 100644 --- a/Furious/Externals/GenTranslation.py +++ b/Furious/Externals/GenTranslation.py @@ -424,7 +424,7 @@ TRANSLATION = { }, "Invalid server configuration": { "source": [ - "Furious.Actions.Connection", + "Furious.Controllers.ConnectionController", "Furious.Window.TextEditorWindow" ], "RU": "Неверная конфигурация сервера", @@ -867,7 +867,7 @@ TRANSLATION = { }, "Unable to connect": { "source": [ - "Furious.Actions.Connection", + "Furious.Controllers.ConnectionController", "Furious.Qt.QtWidgets" ], "RU": "Не удается подключиться", @@ -876,7 +876,7 @@ TRANSLATION = { }, "Server configuration empty. Please configure your server first": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Конфигурация сервера пуста. Пожалуйста, сначала настройте свой сервер", "ZH": "服务器配置为空。请先配置服务器", @@ -884,7 +884,7 @@ TRANSLATION = { }, "Connected": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Подключен", "ZH": "已连接", @@ -892,7 +892,7 @@ TRANSLATION = { }, "Unknown error": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Неизвестная ошибка", "ZH": "未知错误", @@ -900,7 +900,7 @@ TRANSLATION = { }, "Failed to start core": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Сбой при запуске ядра", "ZH": "内核启动失败", @@ -908,7 +908,7 @@ TRANSLATION = { }, "Core terminated unexpectedly": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Неожиданное завершение работы ядра", "ZH": "内核意外终止", @@ -916,7 +916,8 @@ TRANSLATION = { }, "Disconnected": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController", + "Furious.Widget.ServerTableView" ], "RU": "Отключен", "ZH": "已断开", @@ -932,7 +933,8 @@ TRANSLATION = { }, "Routing": { "source": [ - "Furious.Actions.Routing" + "Furious.Actions.Routing", + "Furious.Widget.RoutingSelector" ], "RU": "Маршрутизация", "ZH": "路由", @@ -1117,7 +1119,7 @@ TRANSLATION = { }, "Furious cannot find any valid http proxy endpoint in the configuration": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Я не могу найти ни одной допустимой конечной точки http-прокси в конфигурации", "ZH": "Furious在配置中无法找到任何有效的http代理端点", @@ -1125,7 +1127,7 @@ TRANSLATION = { }, "Please complete your server configuration": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Пожалуйста, завершите настройку вашего сервера", "ZH": "请完善服务器配置", @@ -1255,7 +1257,7 @@ TRANSLATION = { }, "Select and press Enter to activate configuration and connect": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "Выберите конфигурацию и нажмите Enter, чтобы активировать ее и подключиться", "ZH": "选择并按下Enter键以激活配置并连接", @@ -1293,7 +1295,7 @@ TRANSLATION = { }, "is available to download": { "source": [ - "Furious.Actions.Connection" + "Furious.Controllers.ConnectionController" ], "RU": "доступен для скачивания", "ZH": "可供下载", diff --git a/Furious/Frozenlib/Globals.py b/Furious/Frozenlib/Globals.py index 664b5d0a..c2678b0e 100644 --- a/Furious/Frozenlib/Globals.py +++ b/Furious/Frozenlib/Globals.py @@ -29,8 +29,10 @@ __all__ = [ 'AppFontName', 'AppLogManager', 'AppLogPage', + 'AppMainWindow', 'AppRoutingController', 'AppSettingsController', + 'AppSystemTray', 'AppThreadPool', ] @@ -47,15 +49,19 @@ def getAppAttributes(name: str): AppFontName, AppLogManager, AppLogPage, + AppMainWindow, AppRoutingController, AppSettingsController, + AppSystemTray, AppThreadPool, ) = ( functools.partial(getAppAttributes, 'connectionController'), functools.partial(getAppAttributes, 'customFontName'), functools.partial(getAppAttributes, 'logManager'), functools.partial(getAppAttributes, 'logPage'), + functools.partial(getAppAttributes, 'mainWindow'), functools.partial(getAppAttributes, 'routingController'), functools.partial(getAppAttributes, 'settingsController'), + functools.partial(getAppAttributes, 'systemTray'), functools.partial(getAppAttributes, 'threadPool'), ) diff --git a/Furious/Frozenlib/__init__.py b/Furious/Frozenlib/__init__.py index 713cca64..b19303e5 100644 --- a/Furious/Frozenlib/__init__.py +++ b/Furious/Frozenlib/__init__.py @@ -73,8 +73,10 @@ from .Globals import ( AppFontName, AppLogManager, AppLogPage, + AppMainWindow, AppRoutingController, AppSettingsController, + AppSystemTray, AppThreadPool, ) from .Mixins import Mixins @@ -123,10 +125,12 @@ __all__ = [ 'AppFontName', 'AppLogManager', 'AppLogPage', + 'AppMainWindow', 'AppResources', 'AppSettings', 'AppRoutingController', 'AppSettingsController', + 'AppSystemTray', 'AppThreadPool', 'CORE_CHECK_ALIVE_INTERVAL', 'CRASH_LOG_DIR', diff --git a/Furious/Widget/SubscriptionTableView.py b/Furious/Widget/SubscriptionTableView.py index 797b05d9..2bc2648c 100644 --- a/Furious/Widget/SubscriptionTableView.py +++ b/Furious/Widget/SubscriptionTableView.py @@ -913,7 +913,7 @@ class SubscriptionTableView(Mixins.QTranslatable, AppQTableView): else: realHttpProxy = httpProxy - APP().mainWindow.updateSubsByUnique( + AppMainWindow().updateSubsByUnique( unique, realHttpProxy, showMessageBox=showMessageBox, **kwargs ) diff --git a/Furious/Window/TextEditorWindow.py b/Furious/Window/TextEditorWindow.py index f4e98588..1926cac6 100644 --- a/Furious/Window/TextEditorWindow.py +++ b/Furious/Window/TextEditorWindow.py @@ -304,7 +304,7 @@ class TextEditorWindow(AppQMainWindow): Storage.UserServers()[index] = new try: - APP().mainWindow.flushRow(index, new) + AppMainWindow().flushRow(index, new) except Exception: # Any non-exit exceptions