mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-07 22:38:21 +03:00
Switch to enum implementation for routing and proxy mode
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
This commit is contained in:
@@ -155,7 +155,7 @@ class CoreManager(Mixins.CleanupOnExit):
|
||||
for attr in ['access', 'error']:
|
||||
fixLogObjectPath(config, attr, logRedirectValue, log)
|
||||
|
||||
if routing == 'Bypass Mainland China':
|
||||
if routing == AppBuiltinRouting.BypassMainlandChina.value:
|
||||
# TUN Mode handling
|
||||
if not proxyModeOnly and SystemRuntime.isTUNMode():
|
||||
showMBoxDirectRulesNotAllowed()
|
||||
@@ -195,9 +195,9 @@ class CoreManager(Mixins.CleanupOnExit):
|
||||
},
|
||||
],
|
||||
}
|
||||
elif routing == 'Global':
|
||||
elif routing == AppBuiltinRouting.Global.value:
|
||||
routingObject = {}
|
||||
elif routing == 'Custom':
|
||||
elif routing == AppBuiltinRouting.Custom.value:
|
||||
routingObject = config.get('routing', {})
|
||||
else:
|
||||
routingObject = {}
|
||||
@@ -225,7 +225,7 @@ class CoreManager(Mixins.CleanupOnExit):
|
||||
log=True,
|
||||
**kwargs,
|
||||
):
|
||||
if routing == 'Bypass Mainland China':
|
||||
if routing == AppBuiltinRouting.BypassMainlandChina.value:
|
||||
# TUN Mode handling
|
||||
if not proxyModeOnly and SystemRuntime.isTUNMode():
|
||||
showMBoxDirectRulesNotAllowed()
|
||||
@@ -236,12 +236,12 @@ class CoreManager(Mixins.CleanupOnExit):
|
||||
'rule': DATA_DIR / 'hysteria' / 'bypass-mainland-China.acl',
|
||||
'mmdb': DATA_DIR / 'hysteria' / 'country.mmdb',
|
||||
}
|
||||
elif routing == 'Global':
|
||||
elif routing == AppBuiltinRouting.Global.value:
|
||||
routingObject = {
|
||||
'rule': '',
|
||||
'mmdb': '',
|
||||
}
|
||||
elif routing == 'Custom':
|
||||
elif routing == AppBuiltinRouting.Custom.value:
|
||||
routingObject = {
|
||||
'rule': config.get('acl', ''),
|
||||
'mmdb': config.get('mmdb', ''),
|
||||
|
||||
@@ -19,9 +19,24 @@ from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
|
||||
__all__ = ['AppCommands']
|
||||
__all__ = [
|
||||
'AppBuiltinCommand',
|
||||
'AppBuiltinRouting',
|
||||
'AppBuiltinProxyMode',
|
||||
]
|
||||
|
||||
|
||||
class AppCommands(Enum):
|
||||
class AppBuiltinCommand(Enum):
|
||||
Empty = 'empty'
|
||||
RunAs = 'runas'
|
||||
|
||||
|
||||
class AppBuiltinRouting(Enum):
|
||||
BypassMainlandChina = 'Bypass Mainland China'
|
||||
Global = 'Global'
|
||||
Custom = 'Custom'
|
||||
|
||||
|
||||
class AppBuiltinProxyMode(Enum):
|
||||
Auto = 'Auto'
|
||||
NoChanges = 'NoChanges'
|
||||
@@ -19,10 +19,10 @@ from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib.Constants import *
|
||||
|
||||
from enum import Enum
|
||||
from typing import AnyStr, Tuple
|
||||
|
||||
import os
|
||||
import enum
|
||||
import time
|
||||
import pathlib
|
||||
import operator
|
||||
@@ -43,7 +43,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class Protocol(enum.Enum):
|
||||
class Protocol(Enum):
|
||||
Unknown = 'Unknown'
|
||||
VMess = 'VMess'
|
||||
VLESS = 'VLESS'
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from .AppCommands import *
|
||||
from .AppSettings import *
|
||||
from .Constants import *
|
||||
from .Enum import *
|
||||
from .Globals import *
|
||||
from .Mixins import *
|
||||
from .PySide6Legacy import *
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Library import *
|
||||
from Furious.Qt import *
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
__all__ = ['RoutingAction']
|
||||
|
||||
BUILTIN_ROUTING = ['Bypass Mainland China', 'Global', 'Custom']
|
||||
|
||||
registerAppSettings('Routing', validRange=BUILTIN_ROUTING)
|
||||
registerAppSettings(
|
||||
'Routing', validRange=list(routing.value for routing in AppBuiltinRouting)
|
||||
)
|
||||
|
||||
# ALL BUILTIN ROUTING VALUE
|
||||
_TRANSLATABLE_BUILTIN_ROUTING = [
|
||||
@@ -51,7 +53,7 @@ class RoutingAction(AppQAction):
|
||||
def __init__(self, **kwargs):
|
||||
if AppSettings.get('Routing') == 'Bypass':
|
||||
# Update value for backward compatibility
|
||||
AppSettings.set('Routing', 'Bypass Mainland China')
|
||||
AppSettings.set('Routing', AppBuiltinRouting.BypassMainlandChina.value)
|
||||
|
||||
super().__init__(
|
||||
_('Routing'),
|
||||
@@ -59,11 +61,11 @@ class RoutingAction(AppQAction):
|
||||
menu=AppQMenu(
|
||||
*list(
|
||||
RoutingChildAction(
|
||||
_(routing),
|
||||
_(routing.value),
|
||||
checkable=True,
|
||||
checked=AppSettings.get('Routing') == routing,
|
||||
checked=AppSettings.get('Routing') == routing.value,
|
||||
)
|
||||
for routing in BUILTIN_ROUTING
|
||||
for routing in AppBuiltinRouting
|
||||
),
|
||||
),
|
||||
**kwargs,
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from Furious.Frozenlib import *
|
||||
from Furious.Qt import *
|
||||
from Furious.Qt import gettext as _
|
||||
|
||||
__all__ = ['SystemProxyAction']
|
||||
|
||||
BUILTIN_PROXY_MODE = ['Auto', 'NoChanges']
|
||||
|
||||
registerAppSettings('SystemProxyMode', validRange=BUILTIN_PROXY_MODE)
|
||||
registerAppSettings(
|
||||
'SystemProxyMode', validRange=list(mode.value for mode in AppBuiltinProxyMode)
|
||||
)
|
||||
|
||||
|
||||
class SystemProxyChildAction(AppQAction):
|
||||
@@ -32,9 +34,9 @@ class SystemProxyChildAction(AppQAction):
|
||||
|
||||
def triggeredCallback(self, checked):
|
||||
if self.textCompare('Automatically Configure System Proxy'):
|
||||
AppSettings.set('SystemProxyMode', 'Auto')
|
||||
AppSettings.set('SystemProxyMode', AppBuiltinProxyMode.Auto.value)
|
||||
elif self.textCompare('Do Not Change System Proxy'):
|
||||
AppSettings.set('SystemProxyMode', 'NoChanges')
|
||||
AppSettings.set('SystemProxyMode', AppBuiltinProxyMode.NoChanges.value)
|
||||
|
||||
|
||||
class SystemProxyAction(AppQAction):
|
||||
@@ -46,12 +48,14 @@ class SystemProxyAction(AppQAction):
|
||||
SystemProxyChildAction(
|
||||
_('Automatically Configure System Proxy'),
|
||||
checkable=True,
|
||||
checked=AppSettings.get('SystemProxyMode') == 'Auto',
|
||||
checked=AppSettings.get('SystemProxyMode')
|
||||
== AppBuiltinProxyMode.Auto.value,
|
||||
),
|
||||
SystemProxyChildAction(
|
||||
_('Do Not Change System Proxy'),
|
||||
checkable=True,
|
||||
checked=AppSettings.get('SystemProxyMode') == 'NoChanges',
|
||||
checked=AppSettings.get('SystemProxyMode')
|
||||
== AppBuiltinProxyMode.NoChanges.value,
|
||||
),
|
||||
),
|
||||
**kwargs,
|
||||
|
||||
@@ -29,7 +29,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def handleAppSystemProxyMode() -> bool:
|
||||
try:
|
||||
if AppSettings.get('SystemProxyMode') == 'Auto':
|
||||
if AppSettings.get('SystemProxyMode') == AppBuiltinProxyMode.Auto.value:
|
||||
# Automatically configure
|
||||
return True
|
||||
else:
|
||||
|
||||
@@ -89,17 +89,17 @@ class SingletonApplication(ApplicationExitHelper):
|
||||
|
||||
if self.socket.waitForConnected(1000):
|
||||
if len(sys.argv) == 1:
|
||||
command = AppCommands.Empty.value
|
||||
command = AppBuiltinCommand.Empty.value
|
||||
else:
|
||||
command = sys.argv[1]
|
||||
|
||||
self.socket.write(command.encode())
|
||||
self.socket.flush()
|
||||
|
||||
if command == AppCommands.Empty.value:
|
||||
if command == AppBuiltinCommand.Empty.value:
|
||||
# Show tray message in the started instance. Do not start
|
||||
return True
|
||||
elif command == AppCommands.RunAs.value:
|
||||
elif command == AppBuiltinCommand.RunAs.value:
|
||||
if self.socket.waitForDisconnected(3000):
|
||||
# The other instance have been exited. Start
|
||||
return False
|
||||
@@ -198,7 +198,7 @@ class Application(ApplicationFactory, SingletonApplication):
|
||||
else:
|
||||
datastr = str(data)
|
||||
|
||||
if datastr == AppCommands.Empty.value:
|
||||
if datastr == AppBuiltinCommand.Empty.value:
|
||||
if isinstance(self.systemTray, SystemTrayIcon):
|
||||
logger.info('attempting to start multiple instance. Show tray message')
|
||||
|
||||
@@ -206,7 +206,7 @@ class Application(ApplicationFactory, SingletonApplication):
|
||||
else:
|
||||
# The tray hasn't been initialized. Do nothing
|
||||
pass
|
||||
elif datastr == AppCommands.RunAs.value:
|
||||
elif datastr == AppBuiltinCommand.RunAs.value:
|
||||
logger.info('detected requests to start as admin in new instance. Exiting')
|
||||
|
||||
self.exit()
|
||||
@@ -301,7 +301,7 @@ class Application(ApplicationFactory, SingletonApplication):
|
||||
def cleanup():
|
||||
Mixins.CleanupOnExit.cleanupAll()
|
||||
|
||||
if AppSettings.get('SystemProxyMode') == 'Auto':
|
||||
if AppSettings.get('SystemProxyMode') == AppBuiltinProxyMode.Auto.value:
|
||||
# Automatically configure
|
||||
SystemProxy.off()
|
||||
SystemProxy.daemonOff()
|
||||
@@ -452,7 +452,7 @@ class Application(ApplicationFactory, SingletonApplication):
|
||||
Win32Session.set(Application.cleanup)
|
||||
Win32Session.run()
|
||||
|
||||
if AppSettings.get('SystemProxyMode') == 'Auto':
|
||||
if AppSettings.get('SystemProxyMode') == AppBuiltinProxyMode.Auto.value:
|
||||
# Automatically configure
|
||||
SystemProxy.off()
|
||||
SystemProxy.daemonOn_()
|
||||
|
||||
@@ -527,7 +527,7 @@ class TestDownloadSpeedWorker(WebGETManager):
|
||||
|
||||
self.coreManager.start(
|
||||
configcopy,
|
||||
'Global',
|
||||
AppBuiltinRouting.Global.value,
|
||||
self.coreExitCallback,
|
||||
msgCallbackCore=self.coreMsgCallback,
|
||||
deepcopy=False,
|
||||
@@ -555,7 +555,7 @@ class TestDownloadSpeedWorker(WebGETManager):
|
||||
|
||||
self.coreManager.start(
|
||||
configcopy,
|
||||
'Global',
|
||||
AppBuiltinRouting.Global.value,
|
||||
self.coreExitCallback,
|
||||
msgCallbackCore=self.coreMsgCallback,
|
||||
deepcopy=False,
|
||||
|
||||
@@ -502,7 +502,7 @@ class AppMainWindow(AppQMainWindow):
|
||||
arguments=[
|
||||
'-Command',
|
||||
f'Start-Process \'{APP().applicationFilePath()}\' '
|
||||
f'\'{AppCommands.RunAs.value}\' -Verb runAs',
|
||||
f'\'{AppBuiltinCommand.RunAs.value}\' -Verb runAs',
|
||||
],
|
||||
)
|
||||
elif PLATFORM == 'Darwin':
|
||||
@@ -511,7 +511,7 @@ class AppMainWindow(AppQMainWindow):
|
||||
arguments=[
|
||||
'-e',
|
||||
f'do shell script \"{APP().applicationFilePath()} '
|
||||
f'{AppCommands.RunAs.value}\" with administrator privileges',
|
||||
f'{AppBuiltinCommand.RunAs.value}\" with administrator privileges',
|
||||
],
|
||||
)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user