diff --git a/core/interface/gui.py b/core/interface/gui.py index 2e838d1..9209022 100644 --- a/core/interface/gui.py +++ b/core/interface/gui.py @@ -38,17 +38,18 @@ from core.utils.general.wrappers import run_thread from core.utils.data.state import state from core.utils.network.download import download_selected from core.utils.network.update_checker import check_for_updates -from core.utils.general.shutdown import closehelper from core.interface.utils.tabhelper import create_tab from core.interface.utils.searchhelper import return_pressed from core.interface.dialogs.settings import settings_dialog +from core.network.libtorrent_misc import cleanup_session +from core.utils.general.shutdown import closehelper def download_update(latest_version): new_filename = f"SoftwareManager-dev-{latest_version.replace('-dev', '')}-windows.exe" url = f"https://github.com/KeksPirates/SoftwareManager/releases/latest/download/SoftwareManager-dev-{latest_version.replace('-dev', '')}-windows.exe" - consoleLog("Downloading update...", True) + print("Downloading update...", True) response = r.get(url, allow_redirects=True) with open(new_filename, "wb") as f: f.write(response.content) @@ -459,7 +460,3 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): super().resizeEvent(event) table_width = self.qtablewidget.viewport().width() self.qtablewidget.setColumnWidth(1, int(table_width * 0.3)) - - - - diff --git a/core/network/libtorrent_misc.py b/core/network/libtorrent_misc.py index ca9e978..87f3e92 100644 --- a/core/network/libtorrent_misc.py +++ b/core/network/libtorrent_misc.py @@ -1,12 +1,21 @@ -import aria2p -import subprocess from core.utils.data.state import state from core.utils.general.logs import update_download_completed_by_hash from core.utils.general.logs import consoleLog from plyer import notification -import socket import time -import sys + + +def cleanup_session(): + if state.dl_session is not None: + for magnetdl in state.active_downloads.values(): + if hasattr(magnetdl, 'pause'): # Check it's a handle + magnetdl.pause() + + del state.dl_session + state.dl_session = None + state.active_downloads.clear() + + def send_notification(shutdown_event): diff --git a/core/utils/general/shutdown.py b/core/utils/general/shutdown.py index f157aa1..28ab513 100644 --- a/core/utils/general/shutdown.py +++ b/core/utils/general/shutdown.py @@ -1,30 +1,9 @@ -from core.utils.data.state import state -from core.utils.general.logs import consoleLog import threading -import psutil -import sys - +from core.network.libtorrent_misc import cleanup_session +from core.utils.general.wrappers import run_thread shutdown_event = threading.Event() -def kill_aria2server(): - if sys.platform.startswith("win"): - process = "aria2c.exe" - else: - process = "aria2c" - - if state.aria2process: - state.aria2process.kill() - consoleLog("Killed Aria2") - - try: - for proc in psutil.process_iter(): - if proc.name() == process: - proc.kill() - consoleLog(f"Killed Aria2c (PID {proc.pid})") - except psutil.NoSuchProcess: - pass - def closehelper(): - shutdown_event.set() - kill_aria2server() \ No newline at end of file + run_thread(threading.Thread(target=cleanup_session)) + shutdown_event.set() \ No newline at end of file