From 80fbefdecd79ffe9977b24c6535489e951cde9a3 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Tue, 2 Dec 2025 15:34:31 +0800 Subject: [PATCH] Added reconnect option under "direct rules not allowed in TUN mode" Signed-off-by: Loren Eteval --- Furious/Core/CoreManager.py | 18 ++-------- Furious/Externals/GenTranslation.py | 14 ++++++-- Furious/Qt/QtWidgets.py | 52 +++++++++++++++++++++++++++++ Furious/TrayActions/Routing.py | 4 +++ 4 files changed, 69 insertions(+), 19 deletions(-) diff --git a/Furious/Core/CoreManager.py b/Furious/Core/CoreManager.py index d08a8ca..40a5e28 100644 --- a/Furious/Core/CoreManager.py +++ b/Furious/Core/CoreManager.py @@ -158,14 +158,7 @@ class CoreManager(Mixins.CleanupOnExit): if routing == 'Bypass Mainland China': # TUN Mode handling if not proxyModeOnly and SystemRuntime.isTUNMode(): - mbox = AppQMessageBox(icon=AppQMessageBox.Icon.Critical) - mbox.setWindowTitle(_('Unable to connect')) - mbox.setText( - _('Routing option with direct rules is not allowed in TUN mode') - ) - - # Show the MessageBox asynchronously - mbox.open() + showDirectRulesNotAllowedMBox() return None, False @@ -235,14 +228,7 @@ class CoreManager(Mixins.CleanupOnExit): if routing == 'Bypass Mainland China': # TUN Mode handling if not proxyModeOnly and SystemRuntime.isTUNMode(): - mbox = AppQMessageBox(icon=AppQMessageBox.Icon.Critical) - mbox.setWindowTitle(_('Unable to connect')) - mbox.setText( - _('Routing option with direct rules is not allowed in TUN mode') - ) - - # Show the MessageBox asynchronously - mbox.open() + showDirectRulesNotAllowedMBox() return None, False diff --git a/Furious/Externals/GenTranslation.py b/Furious/Externals/GenTranslation.py index e85d680..0b649ec 100644 --- a/Furious/Externals/GenTranslation.py +++ b/Furious/Externals/GenTranslation.py @@ -956,7 +956,7 @@ TRANSLATION = { }, "Unable to connect": { "source": [ - "Furious.Core.CoreManager", + "Furious.Qt.QtWidgets", "Furious.TrayActions.Connect" ], "RU": "Не удается подключиться", @@ -1191,7 +1191,7 @@ TRANSLATION = { "source": [ "Furious.TrayActions.Routing" ], - "RU": "Весь трафик", + "RU": "глобальный режим", "ZH": "全球", "isReviewed": "True" }, @@ -1380,12 +1380,20 @@ TRANSLATION = { }, "Routing option with direct rules is not allowed in TUN mode": { "source": [ - "Furious.Core.CoreManager" + "Furious.Qt.QtWidgets" ], "RU": "Опция маршрутизации с прямыми правилами не разрешена в режиме TUN", "ZH": "TUN模式下不允许使用直接规则的路由选项", "isReviewed": "True" }, + "Switch to global and reconnect?": { + "source": [ + "Furious.Qt.QtWidgets" + ], + "RU": "Переключиться в глобальный режим и переподключиться?", + "ZH": "切换到全局模式并重新连接?", + "isReviewed": "True" + }, "Select and press Enter to activate configuration and connect": { "source": [ "Furious.TrayActions.Connect" diff --git a/Furious/Qt/QtWidgets.py b/Furious/Qt/QtWidgets.py index 8a07f32..279838c 100644 --- a/Furious/Qt/QtWidgets.py +++ b/Furious/Qt/QtWidgets.py @@ -50,6 +50,8 @@ __all__ = [ 'QuestionDeleteMBox', 'NewChangesNextTimeMBox', 'showNewChangesNextTimeMBox', + 'DirectRulesNotAllowedMBox', + 'showDirectRulesNotAllowedMBox', 'UnrecognizedConfigMBox', 'showUnrecognizedConfigMBox', ] @@ -695,6 +697,56 @@ def showNewChangesNextTimeMBox(**kwargs): pass +class DirectRulesNotAllowedMBox(AppQMessageBox): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.setWindowTitle(_('Unable to connect')) + self.setIcon(AppQMessageBox.Icon.Critical) + self.setStandardButtons( + AppQMessageBox.StandardButton.Yes | AppQMessageBox.StandardButton.No + ) + self.setText(self.customText()) + + @staticmethod + def customText() -> str: + return ( + _('Routing option with direct rules is not allowed in TUN mode') + + '\n\n' + + _('Switch to global and reconnect?') + ) + + def retranslate(self): + self.setWindowTitle(_(self.windowTitle())) + self.setText(self.customText()) + + # Ignore informative text, buttons + + self.moveToCenter() + + +def showDirectRulesNotAllowedMBox(**kwargs): + @QtCore.Slot(int) + def handleResultCode(code): + if code == PySide6Legacy.enumValueWrapper(AppQMessageBox.StandardButton.Yes): + APP().systemTray.RoutingAction.getGlobalAction().trigger() + APP().systemTray.ConnectAction.trigger() + else: + # Do nothing + pass + + mbox = DirectRulesNotAllowedMBox(**kwargs) + mbox.finished.connect(handleResultCode) + + if isinstance(mbox.parent(), QMainWindow): + mbox.setWindowModality(QtCore.Qt.WindowModality.WindowModal) + else: + mbox.setWindowModality(QtCore.Qt.WindowModality.ApplicationModal) + + # Show the MessageBox asynchronously + mbox.open() + + class UnrecognizedConfigMBox(AppQMessageBox): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/Furious/TrayActions/Routing.py b/Furious/TrayActions/Routing.py index 1094973..f06a0e3 100644 --- a/Furious/TrayActions/Routing.py +++ b/Furious/TrayActions/Routing.py @@ -68,3 +68,7 @@ class RoutingAction(AppQAction): ), **kwargs, ) + + def getGlobalAction(self): + # 2nd action + return self._menu.actions()[1]