mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
refactor: consolidate aria2 process management into state and remove global variables
This commit is contained in:
@@ -37,13 +37,6 @@ def state_debug(setting):
|
|||||||
state.debug = False
|
state.debug = False
|
||||||
|
|
||||||
|
|
||||||
def pass_aria(aria):
|
|
||||||
global aria2process
|
|
||||||
aria2process = aria
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_tab(title, searchbar, software_list, tabs):
|
def create_tab(title, searchbar, software_list, tabs):
|
||||||
tab = QWidget()
|
tab = QWidget()
|
||||||
layout = QVBoxLayout()
|
layout = QVBoxLayout()
|
||||||
@@ -162,7 +155,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
thread_box = QSpinBox()
|
thread_box = QSpinBox()
|
||||||
thread_box.setMinimum(1)
|
thread_box.setMinimum(1)
|
||||||
thread_box.setMaximum(16)
|
thread_box.setMaximum(16)
|
||||||
thread_box.setValue(4)
|
thread_box.setValue(state.aria2_threads)
|
||||||
|
|
||||||
|
|
||||||
# container for tight space
|
# container for tight space
|
||||||
@@ -202,7 +195,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, text_edit.toPlainText(), aria2process))
|
save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, text_edit.toPlainText()))
|
||||||
|
|
||||||
|
|
||||||
cancel_btn.clicked.connect(dialog.reject)
|
cancel_btn.clicked.connect(dialog.reject)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import aria2p
|
import aria2p
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from core.utils.state import state
|
||||||
|
|
||||||
def run_aria2p():
|
def run_aria2p():
|
||||||
global aria2
|
global aria2
|
||||||
@@ -15,11 +16,7 @@ def run_aria2p():
|
|||||||
|
|
||||||
return aria2
|
return aria2
|
||||||
|
|
||||||
t = 4 # default value
|
|
||||||
|
|
||||||
def set_threads(threads):
|
|
||||||
global t
|
|
||||||
t = threads
|
|
||||||
|
|
||||||
|
|
||||||
def aria2server():
|
def aria2server():
|
||||||
@@ -32,8 +29,8 @@ def aria2server():
|
|||||||
"--rpc-listen-all",
|
"--rpc-listen-all",
|
||||||
"--rpc-listen-port=6800",
|
"--rpc-listen-port=6800",
|
||||||
f"--dir={downloads_dir}",
|
f"--dir={downloads_dir}",
|
||||||
"-x", str(t),
|
"-x", str(state.aria2_threads),
|
||||||
"-s", str(t),
|
"-s", str(state.aria2_threads),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-11
@@ -1,20 +1,19 @@
|
|||||||
from core.network.aria2_integration import set_threads
|
from core.utils.state import state
|
||||||
|
|
||||||
|
|
||||||
def restart_aria2c(aria2process):
|
def restart_aria2c():
|
||||||
import main # had to do this because of circle import :(
|
import main # had to do this because of circle import :(
|
||||||
import signal
|
import signal
|
||||||
import atexit
|
import atexit
|
||||||
main.kill_aria2server(aria2process)
|
main.kill_aria2server()
|
||||||
aria2process.wait()
|
state.aria2process.wait()
|
||||||
aria2process = main.run_aria2server()
|
state.aria2process = main.run_aria2server()
|
||||||
signal.signal(signal.SIGINT, main.keyboardinterrupthandler)
|
signal.signal(signal.SIGINT, main.keyboardinterrupthandler)
|
||||||
atexit.unregister(main.kill_aria2server)
|
atexit.unregister(main.kill_aria2server)
|
||||||
atexit.register(main.kill_aria2server, aria2process)
|
atexit.register(main.kill_aria2server)
|
||||||
|
|
||||||
def save_settings(thread_count, close, apiurl, aria2process):
|
def save_settings(thread_count, close, apiurl):
|
||||||
global api_url
|
state.aria2_threads = thread_count
|
||||||
set_threads(thread_count)
|
state.api_url = apiurl
|
||||||
api_url = apiurl
|
restart_aria2c()
|
||||||
restart_aria2c(aria2process)
|
|
||||||
close()
|
close()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from typing import Optional, Any
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -6,6 +7,8 @@ class AppState:
|
|||||||
debug: bool = False
|
debug: bool = False
|
||||||
tracker: str = "rutracker"
|
tracker: str = "rutracker"
|
||||||
api_url: str = "https://api.michijackson.xyz"
|
api_url: str = "https://api.michijackson.xyz"
|
||||||
|
aria2process: Optional[Any] = None
|
||||||
|
aria2_threads: int = 4
|
||||||
|
|
||||||
|
|
||||||
state = AppState()
|
state = AppState()
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from core.interface.gui import MainWindow
|
from core.interface.gui import MainWindow
|
||||||
from core.interface.gui import state_debug
|
from core.interface.gui import state_debug
|
||||||
from core.interface.gui import pass_aria
|
from core.utils.state import state
|
||||||
from core.network.aria2_integration import aria2server
|
from core.network.aria2_integration import aria2server
|
||||||
from PySide6 import QtWidgets
|
from PySide6 import QtWidgets
|
||||||
import qdarktheme
|
import qdarktheme
|
||||||
@@ -28,28 +28,25 @@ def run_aria2server():
|
|||||||
return aria2process
|
return aria2process
|
||||||
|
|
||||||
|
|
||||||
def kill_aria2server(aria2process):
|
def kill_aria2server():
|
||||||
if aria2process:
|
if state.aria2process:
|
||||||
aria2process.kill()
|
state.aria2process.kill()
|
||||||
if debug:
|
if debug:
|
||||||
print("\nKilled Aria2")
|
print("\nKilled Aria2")
|
||||||
|
|
||||||
|
|
||||||
def keyboardinterrupthandler(signum, frame):
|
def keyboardinterrupthandler(signum, frame):
|
||||||
global aria2process
|
kill_aria2server()
|
||||||
kill_aria2server(aria2process)
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if debug:
|
if debug:
|
||||||
print("Starting Aria2 Server")
|
print("Starting Aria2 Server")
|
||||||
aria2process = run_aria2server()
|
state.aria2process = run_aria2server()
|
||||||
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
signal.signal(signal.SIGINT, keyboardinterrupthandler)
|
||||||
atexit.register(kill_aria2server, aria2process)
|
atexit.register(kill_aria2server)
|
||||||
if debug:
|
if debug:
|
||||||
print("Launching GUI")
|
print("Launching GUI")
|
||||||
|
|
||||||
pass_aria(aria2process)
|
|
||||||
run_gui()
|
run_gui()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user