Add Deno version check and update UI
Introduces a Deno version checker and updater section to the updater tab, with localized strings in all supported languages. Adds backend functions for fetching the latest Deno version, comparing versions, and upgrading Deno, along with corresponding GUI logic for checking and updating Deno from the interface.
This commit is contained in:
@@ -29,6 +29,7 @@ from src.core.ytsage_utils import (
|
||||
update_auto_update_settings,
|
||||
)
|
||||
from src.core.ytsage_yt_dlp import get_yt_dlp_path
|
||||
from src.core.ytsage_deno import check_deno_update, upgrade_deno
|
||||
from src.gui.ytsage_gui_dialogs.ytsage_dialogs_update import YTDLPUpdateDialog
|
||||
from src.utils.ytsage_config_manager import ConfigManager
|
||||
from src.utils.ytsage_localization import _
|
||||
@@ -290,6 +291,116 @@ class UpdaterTabWidget(QWidget):
|
||||
|
||||
layout.addWidget(ffmpeg_group)
|
||||
|
||||
# === Deno Version Check & Update Section ===
|
||||
deno_group = QGroupBox(_('deno_updater.title'))
|
||||
deno_layout = QVBoxLayout(deno_group)
|
||||
|
||||
# Description
|
||||
deno_desc = QLabel(_('deno_updater.description'))
|
||||
deno_desc.setWordWrap(True)
|
||||
deno_desc.setStyleSheet("color: #999999; padding: 10px;")
|
||||
deno_layout.addWidget(deno_desc)
|
||||
|
||||
# Version information layout
|
||||
deno_version_layout = QVBoxLayout()
|
||||
|
||||
# Current version
|
||||
deno_current_layout = QHBoxLayout()
|
||||
deno_current_label = QLabel(_('deno_updater.current_version'))
|
||||
deno_current_label.setStyleSheet("font-weight: bold; color: #ffffff;")
|
||||
deno_current_layout.addWidget(deno_current_label)
|
||||
|
||||
self.deno_current_version_label = QLabel("...")
|
||||
self.deno_current_version_label.setStyleSheet("color: #cccccc;")
|
||||
deno_current_layout.addWidget(self.deno_current_version_label)
|
||||
deno_current_layout.addStretch()
|
||||
deno_version_layout.addLayout(deno_current_layout)
|
||||
|
||||
# Latest version
|
||||
deno_latest_layout = QHBoxLayout()
|
||||
deno_latest_label = QLabel(_('deno_updater.latest_version'))
|
||||
deno_latest_label.setStyleSheet("font-weight: bold; color: #ffffff;")
|
||||
deno_latest_layout.addWidget(deno_latest_label)
|
||||
|
||||
self.deno_latest_version_label = QLabel("...")
|
||||
self.deno_latest_version_label.setStyleSheet("color: #cccccc;")
|
||||
deno_latest_layout.addWidget(self.deno_latest_version_label)
|
||||
deno_latest_layout.addStretch()
|
||||
deno_version_layout.addLayout(deno_latest_layout)
|
||||
|
||||
deno_layout.addLayout(deno_version_layout)
|
||||
|
||||
# Status label
|
||||
self.deno_status_label = QLabel(_('deno_updater.status_idle'))
|
||||
self.deno_status_label.setWordWrap(True)
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #888888; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
deno_layout.addWidget(self.deno_status_label)
|
||||
|
||||
# Buttons layout
|
||||
deno_button_layout = QHBoxLayout()
|
||||
|
||||
# Check for updates button
|
||||
self.deno_check_button = QPushButton(_('deno_updater.check_updates'))
|
||||
self.deno_check_button.clicked.connect(self.check_deno_updates)
|
||||
self.deno_check_button.setStyleSheet(
|
||||
"""
|
||||
QPushButton {
|
||||
padding: 8px 15px;
|
||||
background-color: #444444;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
min-width: 120px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #555555;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
background-color: #2a2a2a;
|
||||
color: #666666;
|
||||
}
|
||||
"""
|
||||
)
|
||||
deno_button_layout.addWidget(self.deno_check_button)
|
||||
|
||||
# Update button (initially hidden)
|
||||
self.deno_update_button = QPushButton(_('deno_updater.update_now'))
|
||||
self.deno_update_button.clicked.connect(self.update_deno)
|
||||
self.deno_update_button.setVisible(False)
|
||||
self.deno_update_button.setStyleSheet(
|
||||
"""
|
||||
QPushButton {
|
||||
padding: 8px 15px;
|
||||
background-color: #c90000;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
min-width: 120px;
|
||||
}
|
||||
QPushButton:hover {
|
||||
background-color: #a50000;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #800000;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
background-color: #2a2a2a;
|
||||
color: #666666;
|
||||
}
|
||||
"""
|
||||
)
|
||||
deno_button_layout.addWidget(self.deno_update_button)
|
||||
|
||||
deno_button_layout.addStretch()
|
||||
deno_layout.addLayout(deno_button_layout)
|
||||
|
||||
layout.addWidget(deno_group)
|
||||
|
||||
# === yt-dlp Release Channel Section ===
|
||||
ytdlp_channel_group = QGroupBox(_("settings.ytdlp_channel"))
|
||||
ytdlp_channel_layout = QVBoxLayout()
|
||||
@@ -697,3 +808,116 @@ class UpdaterTabWidget(QWidget):
|
||||
"color: #ff6666; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
def check_deno_updates(self) -> None:
|
||||
"""Check for Deno updates."""
|
||||
self.deno_check_button.setEnabled(False)
|
||||
self.deno_update_button.setVisible(False)
|
||||
self.deno_status_label.setText(_('deno_updater.status_checking'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ffaa00; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
# Run check in background thread
|
||||
def check_thread():
|
||||
try:
|
||||
update_available, current_version, latest_version = check_deno_update()
|
||||
|
||||
# Update UI in main thread
|
||||
self.deno_check_button.setEnabled(True)
|
||||
self._update_deno_check_results(update_available, current_version, latest_version)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Error checking Deno version: {e}")
|
||||
self.deno_check_button.setEnabled(True)
|
||||
self._show_deno_check_error(str(e))
|
||||
|
||||
thread = threading.Thread(target=check_thread, daemon=True)
|
||||
thread.start()
|
||||
|
||||
def _update_deno_check_results(self, update_available: bool, current_version: str, latest_version: str) -> None:
|
||||
"""Handle completion of Deno version check."""
|
||||
# Update version labels
|
||||
self.deno_current_version_label.setText(current_version)
|
||||
self.deno_latest_version_label.setText(latest_version)
|
||||
|
||||
# Update status
|
||||
if current_version in ["Not found", "Error getting version"]:
|
||||
self.deno_status_label.setText(_('deno_updater.status_not_installed'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ff6666; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
elif update_available:
|
||||
self.deno_status_label.setText(_('deno_updater.status_update_available'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ffaa00; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
# Show update button
|
||||
self.deno_update_button.setVisible(True)
|
||||
else:
|
||||
self.deno_status_label.setText(_('deno_updater.status_up_to_date'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #00cc00; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
def _show_deno_check_error(self, error: str) -> None:
|
||||
"""Handle error during Deno version check."""
|
||||
self.deno_status_label.setText(_('deno_updater.check_failed'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ff6666; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
def update_deno(self) -> None:
|
||||
"""Update Deno to the latest version."""
|
||||
self.deno_check_button.setEnabled(False)
|
||||
self.deno_update_button.setEnabled(False)
|
||||
self.deno_status_label.setText(_('deno_updater.updating'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ffaa00; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
# Run update in background thread
|
||||
def update_thread():
|
||||
try:
|
||||
success, output = upgrade_deno()
|
||||
|
||||
# Update UI in main thread
|
||||
self.deno_check_button.setEnabled(True)
|
||||
self.deno_update_button.setEnabled(True)
|
||||
self._handle_deno_update_result(success, output)
|
||||
|
||||
except Exception as e:
|
||||
logger.exception(f"Error updating Deno: {e}")
|
||||
self.deno_check_button.setEnabled(True)
|
||||
self.deno_update_button.setEnabled(True)
|
||||
self._handle_deno_update_result(False, str(e))
|
||||
|
||||
thread = threading.Thread(target=update_thread, daemon=True)
|
||||
thread.start()
|
||||
|
||||
def _handle_deno_update_result(self, success: bool, output: str) -> None:
|
||||
"""Handle Deno update completion."""
|
||||
if success:
|
||||
self.deno_status_label.setText(_('deno_updater.update_success'))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #00cc00; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
self.deno_update_button.setVisible(False)
|
||||
|
||||
# Re-check version to update display
|
||||
self.check_deno_updates()
|
||||
else:
|
||||
# Extract meaningful error from output
|
||||
error_msg = output if output else "Unknown error"
|
||||
self.deno_status_label.setText(_('deno_updater.update_failed', error=error_msg))
|
||||
self.deno_status_label.setStyleSheet(
|
||||
"color: #ff6666; font-size: 12px; padding: 8px; "
|
||||
"background-color: #2a2d36; border-radius: 4px; margin: 5px 0;"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user