mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +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)
|
download_path.setText(state.download_path)
|
||||||
dialog.layout().addWidget(download_path_container)
|
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 #
|
# SAVE/CANCEL #
|
||||||
###############
|
###############
|
||||||
@@ -204,7 +222,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
save_btn = QPushButton("Save")
|
save_btn = QPushButton("Save")
|
||||||
cancel_btn = QPushButton("Cancel")
|
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)
|
cancel_btn.clicked.connect(dialog.reject)
|
||||||
@@ -251,5 +269,3 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
def update_progress(self):
|
def update_progress(self):
|
||||||
progress = dlprogress()
|
progress = dlprogress()
|
||||||
self.progressbar.setValue(progress)
|
self.progressbar.setValue(progress)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ def run_aria2p():
|
|||||||
|
|
||||||
def aria2server():
|
def aria2server():
|
||||||
download_path = state.download_path
|
download_path = state.download_path
|
||||||
|
speed_limit = state.speed_limit
|
||||||
|
|
||||||
cmd = [
|
cmd = [
|
||||||
"aria2c",
|
"aria2c",
|
||||||
@@ -26,12 +27,11 @@ def aria2server():
|
|||||||
"--rpc-listen-all",
|
"--rpc-listen-all",
|
||||||
"--rpc-listen-port=6800",
|
"--rpc-listen-port=6800",
|
||||||
f"--dir={download_path}",
|
f"--dir={download_path}",
|
||||||
|
f"--max-download-limit={speed_limit * 1024}",
|
||||||
"-x", str(state.aria2_threads),
|
"-x", str(state.aria2_threads),
|
||||||
"-s", str(state.aria2_threads),
|
"-s", str(state.aria2_threads),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
aria2server = subprocess.Popen(cmd)
|
aria2server = subprocess.Popen(cmd)
|
||||||
return aria2server
|
return aria2server
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from core.utils.data.state import state
|
|||||||
def create_config():
|
def create_config():
|
||||||
config = configparser.ConfigParser()
|
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":
|
if platform.system() == "Windows":
|
||||||
config_dir = os.environ.get("APPDATA", os.path.expanduser("~\\AppData\\Roaming"))
|
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.api_url = config.get("General", "api_url")
|
||||||
state.aria2_threads = config.getint("General", "aria2_threads")
|
state.aria2_threads = config.getint("General", "aria2_threads")
|
||||||
state.download_path = config.get("General", "download_path")
|
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 core.utils.data.state import state
|
||||||
from .config import create_config
|
from .config import create_config
|
||||||
import os
|
|
||||||
|
|
||||||
def restart_aria2c():
|
def restart_aria2c():
|
||||||
import main # had to do this because of circle import :(
|
import main # had to do this because of circle import :(
|
||||||
@@ -13,10 +12,11 @@ def restart_aria2c():
|
|||||||
atexit.unregister(main.kill_aria2server)
|
atexit.unregister(main.kill_aria2server)
|
||||||
atexit.register(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.aria2_threads = thread_count
|
||||||
state.api_url = apiurl
|
state.api_url = apiurl
|
||||||
state.download_path = download_path
|
state.download_path = download_path
|
||||||
|
state.speed_limit = speed_limit
|
||||||
|
|
||||||
create_config()
|
create_config()
|
||||||
restart_aria2c()
|
restart_aria2c()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class AppState:
|
|||||||
tracker: str = "rutracker"
|
tracker: str = "rutracker"
|
||||||
api_url: str = "https://api.michijackson.xyz"
|
api_url: str = "https://api.michijackson.xyz"
|
||||||
download_path: str = str(Path.home() / "Downloads")
|
download_path: str = str(Path.home() / "Downloads")
|
||||||
|
speed_limit: int = 0
|
||||||
aria2process: Optional[Any] = None
|
aria2process: Optional[Any] = None
|
||||||
aria2_threads: int = 4
|
aria2_threads: int = 4
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user