Skip to content

Commit

Permalink
Improve speed test result
Browse files Browse the repository at this point in the history
Signed-off-by: Loren Eteval <loren.eteval@proton.me>
  • Loading branch information
LorenEteval committed Oct 15, 2023
1 parent 7ff7244 commit 78c5dda
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions Furious/Widget/EditConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 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 Furious.Core.Core import XrayCore, Hysteria1, Hysteria2
from Furious.Core.Core import Core, XrayCore, Hysteria1, Hysteria2
from Furious.Core.TorRelay import TorRelay
from Furious.Core.Configuration import Configuration
from Furious.Core.Intellisense import Intellisense
Expand Down Expand Up @@ -1399,7 +1399,7 @@ def run(self):

return

self.serverObj['speedResult'] = '0.00 M/s'
self.serverObj['speedResult'] = 'Starting'
self.updateResult()

try:
Expand All @@ -1413,15 +1413,16 @@ def run(self):
return

def coreExitCallback(exitcode):
self.serverObj['speedResult'] = 'Canceled'
if exitcode == Core.ExitCode.ConfigurationError:
self.serverObj['speedResult'] = 'Invalid'
elif exitcode == Core.ExitCode.ServerStartFailure:
self.serverObj['speedResult'] = 'Start failed'
else:
self.serverObj['speedResult'] = 'Canceled'

self.updateResult()

if coreType == XrayCore.name():
coreJSON['log'] = {
'access': '',
'error': '',
'loglevel': 'warning',
}
# Force redirect
coreJSON['inbounds'] = [
{
Expand Down Expand Up @@ -1512,33 +1513,54 @@ def coreExitCallback(exitcode):

@QtCore.Slot()
def handleReadyRead(self):
self.totalBytes += self.networkReply.readAll().length()
if self.core.isAlive():
self.totalBytes += self.networkReply.readAll().length()

# Convert to seconds
elapsedSecond = self.elapsedTimer.elapsed() / 1000
downloadSpeed = self.totalBytes / elapsedSecond / 1024 / 1024
# Convert to seconds
elapsedSecond = self.elapsedTimer.elapsed() / 1000
downloadSpeed = self.totalBytes / elapsedSecond / 1024 / 1024

# Has speed value
self.speedValue = True
self.serverObj['speedResult'] = f'{downloadSpeed:.2f} M/s'
self.updateResult()
# Has speed value
self.speedValue = True
self.serverObj['speedResult'] = f'{downloadSpeed:.2f} M/s'
self.updateResult()

@QtCore.Slot()
def handleFinished(self):
self.core.stop()

if self.networkReply.error() != QNetworkReply.NetworkError.NoError:
if not self.speedValue:
self.serverObj['speedResult'] = 'Canceled'
if self.core.isAlive():
if (
self.networkReply.error()
== QNetworkReply.NetworkError.OperationCanceledError
):
# Canceled by application
self.serverObj['speedResult'] = 'Canceled'
else:
errorString = self.networkReply.error().name

if errorString.endswith('Error'):
self.serverObj['speedResult'] = errorString[:-5]
else:
self.serverObj['speedResult'] = errorString
else:
# Core ExitCallback has been called
self.testFinished = True

return
else:
self.totalBytes += self.networkReply.readAll().length()
if self.core.isAlive():
self.totalBytes += self.networkReply.readAll().length()

# Convert to seconds
elapsedSecond = self.elapsedTimer.elapsed() / 1000
downloadSpeed = self.totalBytes / elapsedSecond / 1024 / 1024
# Convert to seconds
elapsedSecond = self.elapsedTimer.elapsed() / 1000
downloadSpeed = self.totalBytes / elapsedSecond / 1024 / 1024

self.serverObj['speedResult'] = f'{downloadSpeed:.2f} M/s'
self.serverObj['speedResult'] = f'{downloadSpeed:.2f} M/s'
else:
self.serverObj['speedResult'] = 'Start failed'

self.core.stop()
self.updateResult()
self.testFinished = True

Expand Down

0 comments on commit 78c5dda

Please sign in to comment.