mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-03 17:39:42 +02:00
add download speed limit setting
This commit is contained in:
+19
-3
@@ -196,6 +196,24 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
download_path.setText(state.download_path)
|
||||
dialog.layout().addWidget(download_path_container)
|
||||
|
||||
#################
|
||||
# SPEED LIMITING #
|
||||
##################
|
||||
|
||||
speed_limit_container = QWidget()
|
||||
speed_limit_layout = QHBoxLayout()
|
||||
|
||||
speed_limit_layout.addWidget(QLabel("Max Download Speed (KiB, 0 for unlimited): "))
|
||||
speed_limit = QSpinBox()
|
||||
speed_limit.setMinimum(0)
|
||||
speed_limit.setMaximum(10000000)
|
||||
speed_limit.setValue(state.speed_limit)
|
||||
speed_limit_container.setLayout(speed_limit_layout)
|
||||
speed_limit_layout.addWidget(speed_limit)
|
||||
speed_limit.setFixedWidth(180)
|
||||
speed_limit.setFixedHeight(30)
|
||||
dialog.layout().addWidget(speed_limit_container)
|
||||
|
||||
###############
|
||||
# SAVE/CANCEL #
|
||||
###############
|
||||
@@ -204,7 +222,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
|
||||
save_btn = QPushButton("Save")
|
||||
cancel_btn = QPushButton("Cancel")
|
||||
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.toPlainText(), download_path.toPlainText()))
|
||||
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.toPlainText(), download_path.toPlainText(), speed_limit.value()))
|
||||
|
||||
|
||||
cancel_btn.clicked.connect(dialog.reject)
|
||||
@@ -251,5 +269,3 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
||||
def update_progress(self):
|
||||
progress = dlprogress()
|
||||
self.progressbar.setValue(progress)
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ def run_aria2p():
|
||||
|
||||
def aria2server():
|
||||
download_path = state.download_path
|
||||
speed_limit = state.speed_limit
|
||||
|
||||
cmd = [
|
||||
"aria2c",
|
||||
@@ -26,11 +27,10 @@ def aria2server():
|
||||
"--rpc-listen-all",
|
||||
"--rpc-listen-port=6800",
|
||||
f"--dir={download_path}",
|
||||
f"--max-download-limit={speed_limit * 1024}",
|
||||
"-x", str(state.aria2_threads),
|
||||
"-s", str(state.aria2_threads),
|
||||
]
|
||||
|
||||
|
||||
|
||||
aria2server = subprocess.Popen(cmd)
|
||||
return aria2server
|
||||
|
||||
@@ -7,7 +7,7 @@ from core.utils.data.state import state
|
||||
def create_config():
|
||||
config = configparser.ConfigParser()
|
||||
|
||||
config["General"] = {"debug": True, "api_url": f"{state.api_url}", "aria2_threads": f"{state.aria2_threads}", "download_path": f"{state.download_path}"}
|
||||
config["General"] = {"debug": True, "api_url": f"{state.api_url}", "aria2_threads": f"{state.aria2_threads}", "download_path": f"{state.download_path}", f"speed_limit": f"{state.speed_limit}"}
|
||||
|
||||
if platform.system() == "Windows":
|
||||
config_dir = os.environ.get("APPDATA", os.path.expanduser("~\\AppData\\Roaming"))
|
||||
@@ -41,4 +41,5 @@ def read_config():
|
||||
state.api_url = config.get("General", "api_url")
|
||||
state.aria2_threads = config.getint("General", "aria2_threads")
|
||||
state.download_path = config.get("General", "download_path")
|
||||
state.speed_limit = config.getint("General", "speed_limit")
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from core.utils.data.state import state
|
||||
from .config import create_config
|
||||
import os
|
||||
|
||||
def restart_aria2c():
|
||||
import main # had to do this because of circle import :(
|
||||
@@ -13,10 +12,11 @@ def restart_aria2c():
|
||||
atexit.unregister(main.kill_aria2server)
|
||||
atexit.register(main.kill_aria2server)
|
||||
|
||||
def save_settings(thread_count, close, apiurl, download_path):
|
||||
def save_settings(thread_count, close, apiurl, download_path, speed_limit):
|
||||
state.aria2_threads = thread_count
|
||||
state.api_url = apiurl
|
||||
state.download_path = download_path
|
||||
state.speed_limit = speed_limit
|
||||
|
||||
create_config()
|
||||
restart_aria2c()
|
||||
|
||||
@@ -11,6 +11,7 @@ class AppState:
|
||||
tracker: str = "rutracker"
|
||||
api_url: str = "https://api.michijackson.xyz"
|
||||
download_path: str = str(Path.home() / "Downloads")
|
||||
speed_limit: int = 0
|
||||
aria2process: Optional[Any] = None
|
||||
aria2_threads: int = 4
|
||||
|
||||
|
||||
Reference in New Issue
Block a user