From 58f24ef64066fac3818d3985bd645dc3f05bbda2 Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Sun, 3 Sep 2023 10:05:58 +0800 Subject: [PATCH] Add SystemShuttingDown ErrorCode handling in core ExitCallback Signed-off-by: Loren Eteval --- Furious/Action/Connect.py | 12 ++++++++++-- Furious/Core/Core.py | 6 +++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Furious/Action/Connect.py b/Furious/Action/Connect.py index 6cb7032..941e57f 100644 --- a/Furious/Action/Connect.py +++ b/Furious/Action/Connect.py @@ -97,6 +97,10 @@ class ConnectAction(Action): assert self.coreRunning assert self.coreName == XrayCore.name() + if exitcode == XrayCore.ExitCode.SystemShuttingDown: + # System shutting down. Do nothing + return + if exitcode == XrayCore.ExitCode.ConfigurationError: if not self.isConnecting(): # Protect connecting action. Mandatory @@ -142,6 +146,10 @@ class ConnectAction(Action): assert self.coreRunning assert self.coreName == Hysteria.name() + if exitcode == Hysteria.ExitCode.SystemShuttingDown: + # System shutting down. Do nothing + return + if exitcode == Hysteria.ExitCode.ConfigurationError: if not self.isConnecting(): # Protect connecting action. Mandatory @@ -182,6 +190,8 @@ class ConnectAction(Action): ) def stopCore(self): + self.TorRelay.stop() + self.XrayCore.registerExitCallback(None) self.Hysteria.registerExitCallback(None) @@ -189,8 +199,6 @@ class ConnectAction(Action): self.XrayCore.stop() self.Hysteria.stop() - self.TorRelay.stop() - self.coreRunning = False def showConnectingProgressBar(self): diff --git a/Furious/Core/Core.py b/Furious/Core/Core.py index 3095a19..eea654a 100644 --- a/Furious/Core/Core.py +++ b/Furious/Core/Core.py @@ -1,4 +1,4 @@ -from Furious.Utility.Constants import PLATFORM, ROOT_DIR, DATA_DIR +from Furious.Utility.Constants import PLATFORM from Furious.Utility.Utility import getAbsolutePath from PySide6 import QtCore @@ -96,6 +96,8 @@ class XrayCore(Core): ConfigurationError = 23 # Windows: 4294967295. Darwin, Linux: 255 (-1) ServerStartFailure = 4294967295 if PLATFORM == 'Windows' else 255 + # Windows shutting down + SystemShuttingDown = 0x40010004 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -137,6 +139,8 @@ class Hysteria(Core): class ExitCode: ConfigurationError = 23 RemoteNetworkError = 3 + # Windows shutting down + SystemShuttingDown = 0x40010004 def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs)