mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b77867b111 | |||
| bf20625832 | |||
| 8d218443bf |
+75
-31
@@ -205,11 +205,9 @@ def _download_update(assets):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def windowCloseHelper():
|
def windowCloseHelper():
|
||||||
QGuiApplication.quit()
|
QGuiApplication.quit()
|
||||||
|
|
||||||
|
|
||||||
class ElidedItemDelegate(QStyledItemDelegate):
|
class ElidedItemDelegate(QStyledItemDelegate):
|
||||||
def __init__(self, get_hovered_row, parent=None):
|
def __init__(self, get_hovered_row, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -274,13 +272,13 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
state.version = build_info.get("version")
|
state.version = build_info.get("version")
|
||||||
|
|
||||||
if state.ignore_updates is False and platform.system() == "Windows":
|
if state.ignore_updates is False and platform.system() == "Windows":
|
||||||
assets = get_updates()
|
assets, latest = get_updates()
|
||||||
if assets != None:
|
if assets != None:
|
||||||
msg = QMessageBox()
|
msg = QMessageBox()
|
||||||
msg.setIcon(QMessageBox.Icon.Information)
|
msg.setIcon(QMessageBox.Icon.Information)
|
||||||
msg.setWindowTitle("Update Available")
|
msg.setWindowTitle("Update Available")
|
||||||
msg.setText("A new version is available.")
|
msg.setText(f"A new version is available\n({latest})")
|
||||||
msg.setInformativeText("Press Ok to download the update.")
|
msg.setInformativeText("Press Ok to download.")
|
||||||
msg.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Ignore)
|
msg.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Ignore)
|
||||||
response = msg.exec_()
|
response = msg.exec_()
|
||||||
if response == QMessageBox.StandardButton.Ok:
|
if response == QMessageBox.StandardButton.Ok:
|
||||||
@@ -488,10 +486,19 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
button = editor.findChild(QtWidgets.QPushButton)
|
button = editor.findChild(QtWidgets.QPushButton)
|
||||||
magnet_link = list(state.active_downloads.keys())[index.row()]
|
if not button:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
with state.downloads_lock:
|
||||||
|
keys = list(state.active_downloads.keys())
|
||||||
|
if index.row() >= len(keys):
|
||||||
|
return
|
||||||
|
magnet_link = keys[index.row()]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
if button:
|
except (RuntimeError, IndexError, KeyError):
|
||||||
|
return
|
||||||
|
|
||||||
if status.state == lt.torrent_status.seeding:
|
if status.state == lt.torrent_status.seeding:
|
||||||
button.setIcon(svg_icon(SVG_FOLDER, 18))
|
button.setIcon(svg_icon(SVG_FOLDER, 18))
|
||||||
button.setText("")
|
button.setText("")
|
||||||
@@ -500,10 +507,19 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
button.setIcon(svg_icon(SVG_PLAY if is_user_paused else SVG_PAUSE, 18))
|
button.setIcon(svg_icon(SVG_PLAY if is_user_paused else SVG_PAUSE, 18))
|
||||||
button.setText("")
|
button.setText("")
|
||||||
|
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
magnet_link = list(state.active_downloads.keys())[index.row()]
|
try:
|
||||||
|
with state.downloads_lock:
|
||||||
|
keys = list(state.active_downloads.keys())
|
||||||
|
if index.row() >= len(keys):
|
||||||
|
return QWidget(parent)
|
||||||
|
magnet_link = keys[index.row()]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
|
except (RuntimeError, IndexError, KeyError):
|
||||||
|
return QWidget(parent)
|
||||||
|
|
||||||
widget = QWidget(parent)
|
widget = QWidget(parent)
|
||||||
widget.setStyleSheet("border: none; background: transparent;")
|
widget.setStyleSheet("border: none; background: transparent;")
|
||||||
layout = QHBoxLayout(widget)
|
layout = QHBoxLayout(widget)
|
||||||
@@ -526,6 +542,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
|
|
||||||
def editorEvent(self, event, model, option, index):
|
def editorEvent(self, event, model, option, index):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -846,10 +863,14 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
editor = self.downloadList.indexWidget(idx)
|
editor = self.downloadList.indexWidget(idx)
|
||||||
if editor and delegate:
|
if editor and delegate:
|
||||||
|
try:
|
||||||
delegate.setEditorData(editor, idx)
|
delegate.setEditorData(editor, idx)
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
self._update_speed_label()
|
self._update_speed_label()
|
||||||
|
|
||||||
|
|
||||||
def _update_speed_label(self):
|
def _update_speed_label(self):
|
||||||
total_down = 0
|
total_down = 0
|
||||||
total_up = 0
|
total_up = 0
|
||||||
@@ -991,63 +1012,86 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if not hasattr(self, '_context_menu_row'):
|
if not hasattr(self, '_context_menu_row'):
|
||||||
return
|
return
|
||||||
row = self._context_menu_row
|
row = self._context_menu_row
|
||||||
|
with state.downloads_lock:
|
||||||
if row < 0 or row >= len(state.active_downloads):
|
if row < 0 or row >= len(state.active_downloads):
|
||||||
return
|
return
|
||||||
magnet_link = list(state.active_downloads.keys())[row]
|
magnet_link = list(state.active_downloads.keys())[row]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
confirm = QMessageBox.question(self, "Cancel Download", f"Are you sure you want to cancel the download of '{magnetdl.status().name}'?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
|
||||||
|
# Cache the name BEFORE removing from session
|
||||||
|
try:
|
||||||
|
torrent_name = magnetdl.status().name
|
||||||
|
except RuntimeError:
|
||||||
|
torrent_name = "Unknown"
|
||||||
|
|
||||||
|
confirm = QMessageBox.question(
|
||||||
|
self, "Cancel Download",
|
||||||
|
f"Are you sure you want to cancel the download of '{torrent_name}'?",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
if confirm == QMessageBox.StandardButton.Yes:
|
if confirm == QMessageBox.StandardButton.Yes:
|
||||||
if hasattr(magnetdl, 'stop'):
|
with state.downloads_lock:
|
||||||
magnetdl.stop()
|
state.active_downloads.pop(magnet_link, None)
|
||||||
elif state.dl_session:
|
remove_download_log(magnet_link)
|
||||||
|
|
||||||
|
if state.dl_session:
|
||||||
try:
|
try:
|
||||||
state.dl_session.remove_torrent(magnetdl)
|
state.dl_session.remove_torrent(magnetdl)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
del state.active_downloads[magnet_link]
|
|
||||||
remove_download_log(magnet_link)
|
consoleLog(f"Cancelled download: {torrent_name}", True)
|
||||||
try:
|
|
||||||
consoleLog(f"Cancelled download: {magnetdl.status().name}", True)
|
|
||||||
except RuntimeError:
|
|
||||||
consoleLog(f"Cancelled download")
|
|
||||||
|
|
||||||
def deleteFileAction(self):
|
def deleteFileAction(self):
|
||||||
if not hasattr(self, '_context_menu_row'):
|
if not hasattr(self, '_context_menu_row'):
|
||||||
return
|
return
|
||||||
row = self._context_menu_row
|
row = self._context_menu_row
|
||||||
|
with state.downloads_lock:
|
||||||
if row < 0 or row >= len(state.active_downloads):
|
if row < 0 or row >= len(state.active_downloads):
|
||||||
return
|
return
|
||||||
magnet_link = list(state.active_downloads.keys())[row]
|
magnet_link = list(state.active_downloads.keys())[row]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
|
|
||||||
|
try:
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
save_path = status.save_path
|
save_path = status.save_path
|
||||||
torrent_name = status.name
|
torrent_name = status.name
|
||||||
|
except RuntimeError:
|
||||||
|
consoleLog("Error: torrent handle already invalid", True)
|
||||||
|
with state.downloads_lock:
|
||||||
|
state.active_downloads.pop(magnet_link, None)
|
||||||
|
remove_download_log(magnet_link)
|
||||||
|
return
|
||||||
|
|
||||||
download_path = os.path.join(save_path, torrent_name)
|
download_path = os.path.join(save_path, torrent_name)
|
||||||
confirm = QMessageBox.question(self, "Delete Files", f"Are you sure you want to delete the downloaded files of '{magnetdl.status().name}'? This action cannot be undone.", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
|
||||||
|
confirm = QMessageBox.question(
|
||||||
|
self, "Delete Files",
|
||||||
|
f"Are you sure you want to delete the downloaded files of '{torrent_name}'? This action cannot be undone.",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
if confirm == QMessageBox.StandardButton.Yes:
|
if confirm == QMessageBox.StandardButton.Yes:
|
||||||
if hasattr(magnetdl, 'stop'):
|
with state.downloads_lock:
|
||||||
magnetdl.stop()
|
state.active_downloads.pop(magnet_link, None)
|
||||||
elif state.dl_session:
|
remove_download_log(magnet_link)
|
||||||
|
|
||||||
|
if state.dl_session:
|
||||||
try:
|
try:
|
||||||
state.dl_session.remove_torrent(magnetdl)
|
state.dl_session.remove_torrent(magnetdl)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if download_path and os.path.exists(download_path):
|
if download_path and os.path.exists(download_path):
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(download_path):
|
if os.path.isfile(download_path):
|
||||||
remove_download_log(magnet_link)
|
|
||||||
os.remove(download_path)
|
os.remove(download_path)
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Deleted files for: {torrent_name}", True)
|
||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
|
||||||
else:
|
else:
|
||||||
import shutil
|
import shutil
|
||||||
remove_download_log(magnet_link)
|
|
||||||
shutil.rmtree(download_path)
|
shutil.rmtree(download_path)
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Deleted files for: {torrent_name}", True)
|
||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
consoleLog(f"Error deleting files: {e}", True)
|
consoleLog(f"Error deleting files: {e}", True)
|
||||||
else:
|
else:
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Removed entry (files not found): {torrent_name}", True)
|
||||||
remove_download_log(magnet_link)
|
|
||||||
consoleLog(f"Removed entry (files not found): {magnetdl.status().name}", True)
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def add_download(magnet_uri):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
params = lt.parse_magnet_uri(magnet_uri)
|
params = lt.parse_magnet_uri(magnet_uri)
|
||||||
params.save_path = "."
|
params.save_path = state.download_path
|
||||||
|
|
||||||
handle = state.dl_session.add_torrent(params)
|
handle = state.dl_session.add_torrent(params)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from core.utils.logging.logs import consoleLog
|
|||||||
|
|
||||||
def get_updates():
|
def get_updates():
|
||||||
url = f"https://api.github.com/repos/KeksPirates/SoftwareManager/releases/latest"
|
url = f"https://api.github.com/repos/KeksPirates/SoftwareManager/releases/latest"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, timeout=15)
|
response = requests.get(url, timeout=15)
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
@@ -33,9 +32,9 @@ def get_updates():
|
|||||||
url=asset['browser_download_url'],
|
url=asset['browser_download_url'],
|
||||||
hash=asset.get('digest')
|
hash=asset.get('digest')
|
||||||
))
|
))
|
||||||
return release_assets
|
return release_assets, latest_version
|
||||||
else:
|
else:
|
||||||
return None
|
return None, None
|
||||||
else:
|
else:
|
||||||
consoleLog("Already up-to-date.")
|
consoleLog("Already up-to-date.")
|
||||||
return None
|
return None, None
|
||||||
|
|||||||
Reference in New Issue
Block a user