Update to 0.1.7-alpha

Add custom game directory and launch log controls

CoreLib update to 0.1.9
This commit is contained in:
wei committed 2026-11-14 17:10:33 +08:00
1 parent fea979fb6f
commit ad38cf726e
24 files changed
+542 -124

No files matched your search

+103 -4
View File
@@ -10,7 +10,7 @@ from manager.game import LaunchManager, LaunchResult
from core_lib.game.version_info import LATEST_VERSION_ALIASES
from manager.profile import ProfileSummary, LaunchProfile, ProfileManager, _profile_icon
from manager.widgets import AskForRequest, WidgetManager
from manager.settings_models import AppearanceSettings
from manager.settings_models import AppearanceSettings, GameSettings
from pages.process_log import ProcessLogWindow
@@ -197,7 +197,7 @@ class LaunchProfilePage(QWidget):
self.status_label.setObjectName("launchStatus")
self.status_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
# Profile button (just like the official launcher look like)
# Profile button (just like the official launcher looks like)
self.profile_button = ProfileButton(self.app)
self.profile_button.setMinimumWidth(260)
self.profile_button.setMaximumWidth(360)
@@ -217,6 +217,20 @@ class LaunchProfilePage(QWidget):
)
launch_button.clicked.connect(self.launch_profile)
self.log_button = QPushButton("≡", self)
self.log_button.setObjectName("logButton")
self.log_button.setFocusPolicy(Qt.FocusPolicy.TabFocus)
self.log_button.setToolTip(self.app.tr_text("Show game log"))
self.log_button.setFixedWidth(36)
self.log_button.setMinimumHeight(42)
self.log_button.setMaximumHeight(64)
self.log_button.setSizePolicy(
QSizePolicy.Policy.Fixed,
QSizePolicy.Policy.Expanding,
)
self.log_button.clicked.connect(self.show_selected_profile_log)
self.log_button.hide()
# Profile overlay
self.profile_frame = self.ProfileBackgroundFrame(
parent=self,
@@ -260,7 +274,13 @@ class LaunchProfilePage(QWidget):
self.bottom_layout.addStretch()
self.bottom_layout.addWidget(self.status_label)
self.bottom_layout.addStretch()
self.bottom_layout.addWidget(launch_button)
launch_actions = QHBoxLayout()
launch_actions.setContentsMargins(0, 0, 0, 0)
launch_actions.setSpacing(4)
launch_actions.setAlignment(Qt.AlignmentFlag.AlignRight)
launch_actions.addWidget(launch_button)
self.launch_actions = launch_actions
self.bottom_layout.addLayout(launch_actions)
self.layout.addWidget(self.profile_frame, 1)
self.layout.addLayout(self.bottom_layout)
@@ -355,13 +375,52 @@ class LaunchProfilePage(QWidget):
)
self.process_log_windows.append(log_window)
log_window.show()
self._update_log_button()
settings = self.app.settings_manager.get("game", GameSettings)
if settings.open_log_view_when_launch:
log_window.show()
self.status_label.setText(self.app.tr_text("Launched!"))
# Cleanup for status label
self.status_label_cleanup()
main_window = self.app.main_window
if settings.action_after_launch == "close":
main_window.close()
elif settings.action_after_launch == "minimize":
main_window.showMinimized()
def _selected_profile_log(self) -> ProcessLogWindow | None:
profile_id = self.profile_button.property("profile_id")
if profile_id is None:
return None
return next(
(window for window in reversed(self.process_log_windows)
if window.profile_id == profile_id),
None,
)
def _update_log_button(self) -> None:
if self._selected_profile_log() is not None:
if self.launch_actions.indexOf(self.log_button) == -1:
self.launch_actions.addWidget(self.log_button)
self.log_button.show()
else:
self.log_button.hide()
self.launch_actions.removeWidget(self.log_button)
def show_selected_profile_log(self) -> None:
# Release the button's visual state before activating another window.
self.log_button.setDown(False)
self.log_button.clearFocus()
self.log_button.update()
window = self._selected_profile_log()
if window is not None:
window.showNormal()
window.raise_()
window.activateWindow()
def status_label_cleanup(self):
timer = QTimer(self)
timer.setSingleShot(True)
@@ -378,6 +437,7 @@ class LaunchProfilePage(QWidget):
self.profile_button.setProperty("profile_id", None)
self.profile_button.name_label.setText(self.app.tr_text("No profiles available"))
self.profile_button.version_label.clear()
self._update_log_button()
return
selected_id = self.profile_button.property("profile_id")
@@ -445,6 +505,7 @@ class LaunchProfilePage(QWidget):
def select_profile(self, profile: ProfileSummary) -> None:
# Update select profile id
self.profile_button.set_profile(profile)
self._update_log_button()
self.profile_popup.hide()
self.profile_button.set_popup_open(False)
@@ -486,3 +547,41 @@ class LaunchProfilePage(QWidget):
self.launch_manager.start_launch_task(launch_profile)
# The log view window creation process has been moved to the method self.launch_finished, move to there!
def show_profile_launch_log_view(self, profile_id: str):
"""
Show processLogView that related to the provided profile id
:param profile_id:
:return:
"""
profile = self.profile_manager.get_profile(profile_id)
if not profile:
return
if profile_id not in [window.profile_id for window in self.process_log_windows]:
return
related_windows = [window for window in self.process_log_windows if window.profile_id == profile_id]
if len(related_windows) > 1:
request = AskForRequest(
self.app.tr_text("Launch Request"),
self.app.tr_text(
"Multiple log views (among {count} windows) are running for profile {profile}. Are you sure you want to open all log view?",
profile=profile.name,
count=len(related_windows),
),
)
if not request.wait(60):
self.widget_mgr.signal.show_error_message.emit(
self.app.tr_text("Time out waiting for request for open window.")
)
return
if not request.result() is True:
return
for window in related_windows:
window.show()
+11 -8
View File
@@ -523,10 +523,12 @@ class ManageProfilePage(QWidget):
)
def duplicate_profile(self, profile: ProfileSummary | None=None) -> None:
if self.selected_profile_id is None and profile is None:
return
profile_id = self.selected_profile_id
if isinstance(profile, ProfileSummary):
profile_id = profile.id
if profile_id is None:
return
new_id = self.profile_manager.duplicate_profile(profile_id)
@@ -535,10 +537,12 @@ class ManageProfilePage(QWidget):
self.load_profiles()
def delete_profile(self, profile: ProfileSummary | None=None) -> None:
if self.selected_profile_id is None and profile is None:
return
profile_id = self.selected_profile_id
if isinstance(profile, ProfileSummary):
profile_id = profile.id
if profile_id is None:
return
answer = QMessageBox.question(
self,
@@ -548,8 +552,7 @@ class ManageProfilePage(QWidget):
QMessageBox.StandardButton.No,
)
if answer == QMessageBox.StandardButton.Yes:
if self.profile_manager.remove_profile(profile_id):
self.selected_profile_id = None
self.profile_manager.remove_profile(profile_id)
def add_page(self, page_name: str, page: QScrollArea) -> Callable[[], None]:
"""Add a plugin tab and return an idempotent cleanup callback."""
+18 -15
View File
@@ -38,7 +38,7 @@ class _ProcessSignals(QObject):
output = Signal(str, object)
# Windows may return an unsigned 32-bit exit code (for example
# 0xFFFFFFFF), which does not fit in Qt's signed Signal(int).
finished = Signal(object)
finished = Signal(object, bool)
read_failed = Signal(str)
@@ -51,13 +51,14 @@ class ProcessLogWindow(QMainWindow):
LOG_TRIM_LINES = 10_000
def __init__(self, app, process: subprocess.Popen, profile_id: str, title: str = "Game Log",
parent: QWidget | None = None, finished_callback: Callable[[str, int], None]=None) -> None:
parent: QWidget | None = None, finished_callback: Callable[[str, int], None] | None = None) -> None:
super().__init__(parent)
self.app = app
self.process = process
self.profile_id = profile_id
self._signals = _ProcessSignals(self)
self._last_error_message: str | None = None
self._killed_by_user = False
self.lines: list[tuple[str, str]] = [] # type, message
self._trimmed_line_count = 0
self._stderr_lines: deque[str] = deque(maxlen=500)
@@ -240,7 +241,7 @@ class ProcessLogWindow(QMainWindow):
exit_code = self._normalize_exit_code(self.process.wait())
self._stdout_reader.join()
self._stderr_reader.join()
self._signals.finished.emit(exit_code)
self._signals.finished.emit(exit_code, self._killed_by_user)
@staticmethod
def _normalize_exit_code(exit_code: int) -> int:
@@ -251,17 +252,17 @@ class ProcessLogWindow(QMainWindow):
def kill_process(self) -> None:
if self.process.poll() is not None:
self._process_finished(
self._normalize_exit_code(self.process.returncode or 0)
)
# The waiter reports completion after both output streams are drained.
return
self.kill_button.setEnabled(False)
self.status_label.setText(self.app.tr_text("Killing process..."))
try:
self._killed_by_user = True
self.process.kill()
except Exception as exc:
self._killed_by_user = False
self.kill_button.setEnabled(True)
self.status_label.setText(self.app.tr_text("Unable to kill process"))
self.append_message(f"[launcher] Unable to kill process: {exc}")
@@ -303,7 +304,8 @@ class ProcessLogWindow(QMainWindow):
self.app.tr_text("Unable to save log file: {error}", error=exc),
)
def _process_finished(self, exit_code: int) -> None:
@Slot(object, bool)
def _process_finished(self, exit_code: int, killed_by_user: bool = False) -> None:
self.kill_button.setEnabled(False)
self.status_label.setText(self.app.tr_text(
"Process exited with code {exit_code}", exit_code=exit_code
@@ -311,11 +313,16 @@ class ProcessLogWindow(QMainWindow):
self.append_message(f"[launcher] Process exited with code {exit_code}.")
if exit_code != 0 and self._last_error_message:
self.append_message(
f"[launcher] Last error: {self._last_error_message}"
)
if not killed_by_user:
self.append_message(
f"[launcher] Last error: {self._last_error_message}"
)
else:
self.append_message(
"[launcher] " + self.app.tr_text("Process interrupted by user")
)
if exit_code != 0:
if exit_code != 0 and not killed_by_user:
error_content = "\n".join(self._stderr_lines)
if not error_content:
error_content = (
@@ -337,10 +344,6 @@ class ProcessLogWindow(QMainWindow):
def _read_failed(self, message: str) -> None:
self.append_message(f"[launcher] Unable to read process output: {message}")
if self.process.poll() is not None:
self._process_finished(
self._normalize_exit_code(self.process.returncode or 0)
)
def closeEvent(self, event: QCloseEvent) -> None:
# Closing the log window must not stop the game. The process remains
+161 -34
View File
@@ -19,17 +19,32 @@ from PySide6.QtWidgets import (
from constant import LAUNCHER_NAME, LAUNCHER_VERSION, LAUNCHER_DESCRIPTION_KEYWORD, \
LAUNCHER_DESCRIPTION_MARKDOWN, LAUNCHER_DESCRIPTION_MARKDOWN_KEYWORD
from core_lib.qt import messagebox
from manager.settings_models import AccountSettings, AppearanceSettings, GeneralSettings, GameSettings
from manager.settings_models import AccountSettings, AppearanceSettings, GeneralSettings, GameSettings, PageBarSettings
from pages.plugins import PluginsDialog
LANGUAGE_LABELS = {
"en": "English",
"zh-TW": "Chinese (Traditional)",
}
POSITION_LABELS = {
"left": "Left",
"right": "Right",
"top": "Top",
"bottom": "Bottom",
}
CREDENTIALS_SAVE_METHODS = {
"system-keyring": "Use system keyring",
"file": "Save as a regular file",
}
COMPATIBILITY_MODE_LABELS = {
"none": "Disabled",
"official-launcher": "Minecraft Launcher",
}
LAUNCH_ACTION_LABELS = {
"close": "Close launcher window",
"stay-open": "Keep launcher open",
"minimize": "Minimize launcher window",
}
class SettingsItem(QPushButton):
@@ -79,7 +94,6 @@ class SettingsSubPage(QWidget):
header_layout.addStretch()
self.content_layout = QVBoxLayout()
self.content_layout.setSpacing(12)
main_layout.addLayout(header_layout)
self.content_layout.setContentsMargins(0, 0, 0, 0)
self.content_layout.setSpacing(6)
@@ -89,6 +103,17 @@ class SettingsSubPage(QWidget):
main_layout.addLayout(self.content_layout)
main_layout.addStretch()
def add_section_title(self, title: str) -> None:
if self.content_layout.count():
self.content_layout.addSpacing(16)
label = QLabel(title)
label.setObjectName("settingsSectionTitle")
font = label.font()
font.setPointSize(12)
font.setBold(True)
label.setFont(font)
self.content_layout.addWidget(label)
class SettingsPage(QWidget):
def __init__(self, app, parent=None) -> None:
@@ -194,7 +219,7 @@ class SettingsPage(QWidget):
pages = (
(tr("General"), tr("Language and launcher directories"), "general_page"),
(tr("Game"), tr("Game file hash verification"), "game_page"),
(tr("Game"), tr("Game downloading and launching configuration"), "game_page"),
(tr("Appearance"), tr("Launcher theme"), "appearance_page"),
(tr("Account"), tr("Microsoft authentication settings"), "account_page"),
(tr("About"), tr("Version and project information"), "about_page"),
@@ -226,7 +251,9 @@ class SettingsPage(QWidget):
tr = self.app.tr_text
page = SettingsSubPage(tr("General"), self._go_back)
current = self.settings.get("general", GeneralSettings)
pagebar_setting = self.settings.get("page-bar", PageBarSettings)
page.add_section_title(tr("Environment Information"))
page.content_layout.addWidget(QLabel(tr("Current launcher working directory")))
launcher_dir = QLineEdit(self.app.work_dir.as_posix())
launcher_dir.setReadOnly(True)
@@ -237,25 +264,75 @@ class SettingsPage(QWidget):
program_dir.setReadOnly(True)
page.content_layout.addWidget(program_dir)
page.content_layout.addSpacing(8)
page.content_layout.addWidget(QLabel(tr("Language")))
page.content_layout.addWidget(QLabel(tr("Current game directory")))
program_dir = QLineEdit(self.app.game_dir.as_posix())
program_dir.setReadOnly(True)
page.content_layout.addWidget(program_dir)
page.add_section_title(tr("Language"))
self.language_combo = self._choice_combo(
"general", "language", LANGUAGE_LABELS, current.language
)
page.content_layout.addWidget(self.language_combo)
page.add_section_title(tr("PageBar"))
self.reset_to_last_used_page = QCheckBox(tr("Reset to last used page"))
self.reset_to_last_used_page.setChecked(pagebar_setting.focus_at_after_restart)
self.reset_to_last_used_page.toggled.connect(
self._mark_settings_dirty
)
page.content_layout.addWidget(self.reset_to_last_used_page)
page.content_layout.addSpacing(2)
page.content_layout.addWidget(QLabel(tr("Position")))
self.pagebar_position_combo = self._choice_combo(
"page-bar", "page_bar_position", POSITION_LABELS, pagebar_setting.page_bar_position
)
self.pagebar_position_combo.currentIndexChanged.connect(
self._mark_settings_dirty
)
page.content_layout.addWidget(self.pagebar_position_combo)
page.content_layout.addSpacing(2)
page.add_section_title(tr("Compatibility Mode"))
self.compatibility_mode_combo = self._choice_combo(
"general", "compatibility_mode", COMPATIBILITY_MODE_LABELS, current.compatibility_mode
)
self.compatibility_mode_combo.currentIndexChanged.connect(
self._mark_settings_dirty
)
page.content_layout.addWidget(self.compatibility_mode_combo)
page.content_layout.addSpacing(2)
return page
def _create_game_page(self) -> QWidget:
tr = self.app.tr_text
page = SettingsSubPage(tr("Game"), self._go_back)
current = self.settings.get("game", GameSettings)
page.add_section_title(tr("Download"))
self.verify_hash_on_download = QCheckBox(tr("Verify file hashes when downloading"))
self.verify_hash_on_download.setChecked(current.verify_hash_on_download)
self.verify_hash_on_download.toggled.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.verify_hash_on_download)
page.add_section_title(tr("Game Launching"))
self.verify_hash_on_launch = QCheckBox(tr("Verify library hashes before launch"))
self.verify_hash_on_launch.setChecked(current.verify_hash_on_launch)
for checkbox in (self.verify_hash_on_download, self.verify_hash_on_launch):
checkbox.toggled.connect(self._mark_settings_dirty)
page.content_layout.addWidget(checkbox)
self.verify_hash_on_launch.toggled.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.verify_hash_on_launch)
self.open_log_view_when_launch = QCheckBox(tr("Open game log when launching"))
self.open_log_view_when_launch.setChecked(current.open_log_view_when_launch)
self.open_log_view_when_launch.toggled.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.open_log_view_when_launch)
page.content_layout.addWidget(QLabel(tr("After game launch")))
self.action_after_launch = self._choice_combo(
"game", "action_after_launch", LAUNCH_ACTION_LABELS, current.action_after_launch
)
self.action_after_launch.currentIndexChanged.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.action_after_launch)
return page
def _create_appearance_page(self) -> QWidget:
@@ -263,7 +340,8 @@ class SettingsPage(QWidget):
page = SettingsSubPage(tr("Appearance"), self._go_back)
current = self.settings.get("appearance", AppearanceSettings)
page.content_layout.addWidget(QLabel(tr("Theme")))
# Theme
page.add_section_title(tr("Theme"))
self.theme_combo = QComboBox()
for theme_id, name in self.app.available_themes().items():
self.theme_combo.addItem(tr(name), theme_id)
@@ -279,7 +357,9 @@ class SettingsPage(QWidget):
help_label.setObjectName("settingsHelpText")
help_label.setWordWrap(True)
page.content_layout.addWidget(help_label)
page.content_layout.addWidget(QLabel(tr("Launch page background")))
# Launch game page background
page.add_section_title(tr("Launch page background"))
self.launch_background = current.launch_background
self.background_preview = QLabel()
self.background_preview.setFixedSize(320, 180)
@@ -345,6 +425,24 @@ class SettingsPage(QWidget):
page = SettingsSubPage(tr("Account"), self._go_back)
current = self.settings.get("account", AccountSettings)
# TokeUpdater
page.add_section_title(tr("TokenUpdater"))
self.enable_token_updater_checkbox = QCheckBox(tr("Enable token updater"))
page.content_layout.addWidget(self.enable_token_updater_checkbox)
page.content_layout.addWidget(QLabel(tr("Token refresh check interval")))
self.token_refresh_interval = QSpinBox()
self.token_refresh_interval.setRange(1, 1440) # minutes
self.token_refresh_interval.setSingleStep(1)
self.token_refresh_interval.setSuffix(
" " + tr("minutes")
)
self.token_refresh_interval.setValue(current.token_refresh_interval // 60)
self.token_refresh_interval.valueChanged.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.token_refresh_interval)
page.add_section_title(tr("Custom"))
page.content_layout.addWidget(QLabel(tr("Credentials save method")))
self.credentials_save_method = self._choice_combo(
"account", "credentials_save_method", CREDENTIALS_SAVE_METHODS,
@@ -372,22 +470,6 @@ class SettingsPage(QWidget):
))
help_label.setObjectName("settingsHelpText")
help_label.setWordWrap(True)
page.content_layout.addWidget(
QLabel(tr("Token refresh check interval"))
)
self.token_refresh_interval = QSpinBox()
self.token_refresh_interval.setRange(1, 1440) # minutes
self.token_refresh_interval.setSingleStep(1)
self.token_refresh_interval.setSuffix(
" " + tr("minutes")
)
self.token_refresh_interval.setValue(current.token_refresh_interval // 60)
self.token_refresh_interval.valueChanged.connect(self._mark_settings_dirty)
page.content_layout.addWidget(self.token_refresh_interval)
page.content_layout.addWidget(help_label)
return page
@@ -455,7 +537,7 @@ class SettingsPage(QWidget):
previous_credentials_method = (
self.settings
.get("account", AccountSettings)
.credentials_save_method # sec
.credentials_save_method # sec
)
previous_token_refresh_interval = (
@@ -463,22 +545,45 @@ class SettingsPage(QWidget):
.token_refresh_interval
)
previous_page_bar_position = (
self.settings.get("page-bar", PageBarSettings)
.page_bar_position
)
previous_compatibility_mode = (
self.settings.get("general", GeneralSettings)
.compatibility_mode
)
current_token_refresh_interval = (
self.token_refresh_interval.value() * 60 # minutes to seconds
self.token_refresh_interval.value() * 60 # minutes to seconds
)
selected_credentials_method = (
self.credentials_save_method.currentData()
)
current_page_bar_position = self.pagebar_position_combo.currentData()
current_compatibility_mode = self.compatibility_mode_combo.currentData()
credentials_method_changed = (
previous_credentials_method
!= selected_credentials_method
)
token_refresh_interval_changed = (
previous_token_refresh_interval
!= current_token_refresh_interval
previous_token_refresh_interval
!= current_token_refresh_interval
)
previous_page_bar_position_changed = (
previous_page_bar_position
!= current_page_bar_position
)
compatibility_mode_changed = (
previous_compatibility_mode
!= current_compatibility_mode
)
client_id = self.client_id_edit.text().strip()
@@ -502,9 +607,16 @@ class SettingsPage(QWidget):
old_theme = self.settings.get("appearance", AppearanceSettings).theme
data = {
"general": {"language": self.language_combo.currentData()},
"general": {"language": self.language_combo.currentData(),
"compatibility_mode": current_compatibility_mode},
"page-bar": {
"page_bar_position": current_page_bar_position,
"focus_at_after_restart": self.reset_to_last_used_page.isChecked()
},
"game": {"verify_hash_on_download": self.verify_hash_on_download.isChecked(),
"verify_hash_on_launch": self.verify_hash_on_launch.isChecked()},
"verify_hash_on_launch": self.verify_hash_on_launch.isChecked(),
"open_log_view_when_launch": self.open_log_view_when_launch.isChecked(),
"action_after_launch": self.action_after_launch.currentData()},
"appearance": {"theme": self.theme_combo.currentData(),
"launch_background": self.launch_background},
"account": {"custom_client_id": client_id if client_id else None,
@@ -557,10 +669,25 @@ class SettingsPage(QWidget):
QMessageBox.critical(self, self.app.tr_text("Settings error"), str(error))
return False
if old_theme !=self.settings.get("appearance", AppearanceSettings).theme:
if old_theme != self.settings.get("appearance", AppearanceSettings).theme:
messagebox.info(None, "Launcher",
self.app.tr_text("To make all page apply new theme."
" Is recommend to restart the launcher after change it."))
" Is recommend to restart the launcher after change it."))
if previous_page_bar_position_changed:
main_window = getattr(self.app, "main_window")
if main_window:
main_window.apply_page_bar_settings()
if compatibility_mode_changed:
messagebox.info(
None,
"Launcher",
self.app.tr_text(
"Compatibility mode changed. Please restart the launcher to apply the changes."
)
)
self._settings_dirty = False
selected_language = data["general"]["language"]