Add custom theme support, token refresh settings and check account login status.
Now launch log viewer has a new look. Fix an issue that causes credentials method option not working. Add log view to settings page.
This commit is contained in:
1 parent
6e29fe1d5c
commit
1bafc60d95
25 files changed
+1149
-199
No files matched your search
@@ -1,8 +1,15 @@
|
||||
import platform
|
||||
import sys
|
||||
import traceback
|
||||
from collections.abc import Mapping
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
try:
|
||||
import tomllib
|
||||
except ModuleNotFoundError: # Python 3.10
|
||||
import tomli as tomllib
|
||||
|
||||
from PySide6.QtCore import QSize
|
||||
from PySide6.QtGui import QIcon, QPixmap, QPalette, QColor
|
||||
from PySide6.QtWidgets import QApplication, QStyle, QToolButton
|
||||
@@ -21,13 +28,33 @@ from manager.settings_models import AccountSettings, AppearanceSettings, General
|
||||
from manager.widgets import WidgetManager
|
||||
from window import LauncherMainWindow
|
||||
|
||||
|
||||
PALETTE_ROLES = {
|
||||
"window": QPalette.ColorRole.Window,
|
||||
"window_text": QPalette.ColorRole.WindowText,
|
||||
"base": QPalette.ColorRole.Base,
|
||||
"alternate_base": QPalette.ColorRole.AlternateBase,
|
||||
"text": QPalette.ColorRole.Text,
|
||||
"button": QPalette.ColorRole.Button,
|
||||
"button_text": QPalette.ColorRole.ButtonText,
|
||||
"mid": QPalette.ColorRole.Mid,
|
||||
"midlight": QPalette.ColorRole.Midlight,
|
||||
"dark": QPalette.ColorRole.Dark,
|
||||
"highlight": QPalette.ColorRole.Highlight,
|
||||
"highlighted_text": QPalette.ColorRole.HighlightedText,
|
||||
"placeholder_text": QPalette.ColorRole.PlaceholderText,
|
||||
}
|
||||
|
||||
|
||||
class Launcher(QApplication, LauncherObject):
|
||||
def __init__(self, logger, debug: bool = False):
|
||||
def __init__(self, logger, log_capture_handler, debug: bool = False):
|
||||
super().__init__()
|
||||
self._system_palette = QPalette(self.palette()) # theme
|
||||
|
||||
# logger
|
||||
self.logger = logger
|
||||
self.log_capture_handler = log_capture_handler
|
||||
|
||||
self.debug = debug
|
||||
|
||||
# dirs
|
||||
@@ -42,7 +69,7 @@ class Launcher(QApplication, LauncherObject):
|
||||
self.settings_manager.register("appearance", AppearanceSettings)
|
||||
self.settings_manager.register("account", AccountSettings)
|
||||
if self.root_settings_dir.is_file():
|
||||
self.settings_manager.load()
|
||||
self.load_settings()
|
||||
else:
|
||||
self.settings_manager.load_defaults().save()
|
||||
|
||||
@@ -214,6 +241,14 @@ class Launcher(QApplication, LauncherObject):
|
||||
def styles_path(self):
|
||||
return self.resources_dir / "styles"
|
||||
|
||||
@property
|
||||
def built_in_themes_dir(self) -> Path:
|
||||
return self.resources_dir / "themes"
|
||||
|
||||
@property
|
||||
def user_themes_dir(self) -> Path:
|
||||
return self.data_dir / "themes"
|
||||
|
||||
def apply_qss(self, qss_relative_path: Path, apply_qss_callback: Callable[[str], None]) -> str:
|
||||
full_path = self.styles_path / qss_relative_path
|
||||
if not full_path.exists():
|
||||
@@ -243,20 +278,49 @@ class Launcher(QApplication, LauncherObject):
|
||||
def get_main_window(self):
|
||||
return self.main_window
|
||||
|
||||
def apply_theme(self, theme=None):
|
||||
def available_themes(self) -> dict[str, str]:
|
||||
"""Return valid theme IDs and their display names."""
|
||||
themes = {"system": "Follow system settings"}
|
||||
for theme_id, directory in self._theme_packages().items():
|
||||
try:
|
||||
name = self._read_theme_manifest(directory / "theme.toml")
|
||||
colors = self._read_palette(directory / "palette.toml")
|
||||
self._palette_from_colors(colors)
|
||||
except (OSError, ValueError, tomllib.TOMLDecodeError) as error:
|
||||
self.logger.warning("Ignoring invalid theme %s: %s", directory, error)
|
||||
continue
|
||||
themes[theme_id] = name
|
||||
return themes
|
||||
|
||||
def apply_theme(self, theme: str | None = None) -> None:
|
||||
if not theme:
|
||||
appearance = self.settings_manager.get("appearance", AppearanceSettings)
|
||||
|
||||
theme = appearance.theme
|
||||
|
||||
if theme == "system":
|
||||
palette = self._system_palette
|
||||
elif theme == "dark":
|
||||
palette = self._dark_palette()
|
||||
elif theme == "light":
|
||||
palette = self._light_palette()
|
||||
# Apply system palette
|
||||
palette = QPalette(self._system_palette)
|
||||
else:
|
||||
raise ValueError(f"Unsupported theme: {theme}")
|
||||
# Use custom theme pack palette
|
||||
directory = self._theme_packages().get(theme)
|
||||
if directory is None:
|
||||
self.logger.warning(
|
||||
"Theme %r was not found; using the system theme instead.",
|
||||
theme,
|
||||
)
|
||||
palette = QPalette(self._system_palette)
|
||||
else:
|
||||
try:
|
||||
self._read_theme_manifest(directory / "theme.toml")
|
||||
colors = self._read_palette(directory / "palette.toml")
|
||||
palette = self._palette_from_colors(colors)
|
||||
except (OSError, ValueError, tomllib.TOMLDecodeError) as error:
|
||||
self.logger.warning(
|
||||
"Unable to apply theme %s; using the system theme: %s",
|
||||
directory,
|
||||
error,
|
||||
)
|
||||
palette = QPalette(self._system_palette)
|
||||
|
||||
self.setPalette(palette)
|
||||
|
||||
@@ -269,47 +333,74 @@ class Launcher(QApplication, LauncherObject):
|
||||
self.reload_toolbutton_icons()
|
||||
self.main_window.toolbar.update_all()
|
||||
|
||||
def _theme_packages(self) -> dict[str, Path]:
|
||||
"""Discover theme package directories.
|
||||
|
||||
User theme packages override built-in packages with the same directory
|
||||
name. A valid package contains both ``theme.toml`` and ``palette.toml``.
|
||||
"""
|
||||
self.user_themes_dir.mkdir(parents=True, exist_ok=True)
|
||||
themes: dict[str, Path] = {}
|
||||
|
||||
for directory in (self.built_in_themes_dir, self.user_themes_dir):
|
||||
if not directory.is_dir():
|
||||
continue
|
||||
|
||||
for theme_dir in sorted(directory.iterdir()):
|
||||
if not theme_dir.is_dir() or theme_dir.name == "system":
|
||||
continue
|
||||
|
||||
themes[theme_dir.name] = theme_dir
|
||||
|
||||
return themes
|
||||
|
||||
@staticmethod
|
||||
def _light_palette() -> QPalette:
|
||||
palette = QPalette()
|
||||
def _read_theme_manifest(path: Path) -> str:
|
||||
with path.open("rb") as theme_file:
|
||||
data = tomllib.load(theme_file)
|
||||
|
||||
palette.setColor(QPalette.ColorRole.Window, QColor("#f5f5f5"))
|
||||
palette.setColor(QPalette.ColorRole.WindowText, QColor("#202020"))
|
||||
palette.setColor(QPalette.ColorRole.Base, QColor("#ffffff"))
|
||||
palette.setColor(QPalette.ColorRole.AlternateBase, QColor("#eeeeee"))
|
||||
palette.setColor(QPalette.ColorRole.Text, QColor("#202020"))
|
||||
palette.setColor(QPalette.ColorRole.Button, QColor("#ffffff"))
|
||||
palette.setColor(QPalette.ColorRole.ButtonText, QColor("#202020"))
|
||||
palette.setColor(QPalette.ColorRole.Mid, QColor("#c5c5c5"))
|
||||
palette.setColor(QPalette.ColorRole.Midlight, QColor("#e2e2e2"))
|
||||
palette.setColor(QPalette.ColorRole.Dark, QColor("#aaaaaa"))
|
||||
palette.setColor(QPalette.ColorRole.Highlight, QColor("#bf265e"))
|
||||
palette.setColor(QPalette.ColorRole.HighlightedText, QColor("#ffffff"))
|
||||
palette.setColor(
|
||||
QPalette.ColorRole.PlaceholderText,
|
||||
QColor("#707070"),
|
||||
)
|
||||
name = data.get("name", path.parent.name)
|
||||
if not isinstance(name, str) or not name.strip():
|
||||
raise ValueError("theme name must be a non-empty string")
|
||||
return name.strip()
|
||||
|
||||
return palette
|
||||
@staticmethod
|
||||
def _dark_palette() -> QPalette:
|
||||
def _read_palette(path: Path) -> Mapping[str, str]:
|
||||
with path.open("rb") as palette_file:
|
||||
data = tomllib.load(palette_file)
|
||||
|
||||
colors = data.get("palette")
|
||||
if not isinstance(colors, dict):
|
||||
raise ValueError("palette must contain a [palette] table")
|
||||
|
||||
missing = PALETTE_ROLES.keys() - colors.keys()
|
||||
if missing:
|
||||
raise ValueError(
|
||||
"palette file is missing palette colors: " + ", ".join(sorted(missing))
|
||||
)
|
||||
return colors
|
||||
|
||||
@staticmethod
|
||||
def _palette_from_colors(colors: Mapping[str, str]) -> QPalette:
|
||||
palette = QPalette()
|
||||
|
||||
palette.setColor(QPalette.ColorRole.Window, QColor("#202124"))
|
||||
palette.setColor(QPalette.ColorRole.WindowText, QColor("#f1f3f4"))
|
||||
palette.setColor(QPalette.ColorRole.Base, QColor("#17181a"))
|
||||
palette.setColor(QPalette.ColorRole.AlternateBase, QColor("#292a2d"))
|
||||
palette.setColor(QPalette.ColorRole.Text, QColor("#f1f3f4"))
|
||||
palette.setColor(QPalette.ColorRole.Button, QColor("#292a2d"))
|
||||
palette.setColor(QPalette.ColorRole.ButtonText, QColor("#f1f3f4"))
|
||||
palette.setColor(QPalette.ColorRole.Mid, QColor("#4a4c50"))
|
||||
palette.setColor(QPalette.ColorRole.Midlight, QColor("#383a3e"))
|
||||
palette.setColor(QPalette.ColorRole.Dark, QColor("#121315"))
|
||||
palette.setColor(QPalette.ColorRole.Highlight, QColor("#bf265e"))
|
||||
palette.setColor(QPalette.ColorRole.HighlightedText, QColor("#ffffff"))
|
||||
palette.setColor(
|
||||
QPalette.ColorRole.PlaceholderText,
|
||||
QColor("#a0a4aa"),
|
||||
)
|
||||
|
||||
for name, role in PALETTE_ROLES.items():
|
||||
value = colors[name]
|
||||
if not isinstance(value, str):
|
||||
raise ValueError(f"palette color {name!r} must be a string")
|
||||
color = QColor(value)
|
||||
if not color.isValid():
|
||||
raise ValueError(f"invalid palette color {name!r}: {value!r}")
|
||||
palette.setColor(role, color)
|
||||
return palette
|
||||
|
||||
def load_settings(self):
|
||||
if hasattr(self, "settings_manager"):
|
||||
try:
|
||||
self.settings_manager.load()
|
||||
except Exception as e:
|
||||
messagebox.error_with_plain_text(
|
||||
None,
|
||||
"Settings Error",
|
||||
"An unexpected error occurred while loading settings.",
|
||||
f"Below are the raw data of the error\n\nError: {str(e)}\n\nTraceback:\n{traceback.format_exc()}",
|
||||
)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
LAUNCHER_VERSION = "0.0.6-alpha"
|
||||
LAUNCHER_VERSION = "0.0.7-alpha"
|
||||
LAUNCHER_NAME = "TapLauncher"
|
||||
LAUNCHER_DIR_NAME = "TapLauncher"
|
||||
MAIN_REPO_URL = "https://repo.weispace.net/wei/Launcher/"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
__version__ = '0.1.0'
|
||||
__version__ = '0.1.1'
|
||||
__description__ = """
|
||||
The core library of the *Launcher*
|
||||
|
||||
|
||||
@@ -12,6 +12,15 @@ class LauncherException(Exception):
|
||||
if user_message is not None:
|
||||
self.user_message = user_message
|
||||
|
||||
class LauncherHTTPException(LauncherException):
|
||||
user_message = "Launcher error occurred."
|
||||
|
||||
def __init__(self, message=None, status_code=None,*, user_message=None):
|
||||
super().__init__(message or user_message or self.user_message)
|
||||
if user_message is not None:
|
||||
self.user_message = user_message
|
||||
self.status_code = status_code
|
||||
|
||||
class HashMismatchException(Exception):
|
||||
def __init__(self, hash_name, got_hash, expected_hash, filepath: str | Path):
|
||||
if type(filepath) == Path: filepath = Path(filepath).absolute().as_posix()
|
||||
@@ -109,7 +118,7 @@ class AuthenticationException(LauncherException):
|
||||
class AuthenticationConnectException(LauncherException):
|
||||
user_message = "An error occurred while connecting to authentication server."
|
||||
|
||||
class AuthenticationSessionException(LauncherException):
|
||||
class AuthenticationSessionException(LauncherHTTPException):
|
||||
user_message = "Authentication failed. Session may expire."
|
||||
|
||||
class ThirdPartyAPIException(LauncherException):
|
||||
|
||||
@@ -166,7 +166,7 @@ def _check_account(account: dict, account_id: str | None = None, fix_wrong: bool
|
||||
)
|
||||
|
||||
# Check all required key is exiting
|
||||
if any(not isinstance(account.get(key), str) or not account[key] for key in required_strings):
|
||||
if any(not isinstance(account.get(key), str) or key not in account for key in required_strings):
|
||||
return False
|
||||
|
||||
# Check account id is match as provided
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Store all function for microsoft authentication
|
||||
Store all function for Microsoft authentication
|
||||
|
||||
WARNING: This module is vibed! With code reviewed!
|
||||
"""
|
||||
@@ -11,7 +11,7 @@ from typing import Callable
|
||||
import requests
|
||||
|
||||
from core_lib.common.exception import AuthenticationSessionException, AuthenticationConnectException, \
|
||||
AuthenticationException
|
||||
AuthenticationException, LauncherHTTPException
|
||||
|
||||
MICROSOFT_DEVICE_CODE_URL = "https://login.microsoftonline.com/consumers/oauth2/v2.0/devicecode"
|
||||
MICROSOFT_TOKEN_URL = "https://login.microsoftonline.com/consumers/oauth2/v2.0/token"
|
||||
@@ -462,3 +462,39 @@ def refresh_microsoft_token(client_id: str, refresh_token: str) -> tuple[str, st
|
||||
result,
|
||||
)
|
||||
|
||||
def is_access_token_valid(minecraft_access_token: str) -> bool:
|
||||
"""
|
||||
Check if the access token is valid
|
||||
:param minecraft_access_token:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
response = requests.get(
|
||||
MINECRAFT_PROFILE_URL,
|
||||
headers={"Authorization": f"Bearer {minecraft_access_token}"},
|
||||
timeout=10,
|
||||
)
|
||||
except Exception as e:
|
||||
raise AuthenticationSessionException(
|
||||
status_code=None,
|
||||
user_message="An error occurred while connecting to Minecraft API.",
|
||||
) from e
|
||||
|
||||
status_code = response.status_code
|
||||
|
||||
if status_code == 400:
|
||||
raise AuthenticationException(
|
||||
user_message="Got bad request response from Minecraft API. Client request format may outdated.",
|
||||
)
|
||||
elif status_code == 401:
|
||||
# Session is invalid
|
||||
return False
|
||||
|
||||
if status_code != 200:
|
||||
raise AuthenticationSessionException(
|
||||
"Get HTTP status code {} while fetch profile data for verifying access token".format(status_code),
|
||||
status_code=response.status_code,
|
||||
user_message="Unable to verify access token. An server error occurred. ({})".format(status_code),
|
||||
)
|
||||
|
||||
return True
|
||||
@@ -490,3 +490,26 @@ def update_profile(profiles: dict, profile_id: str, profile_data: dict, fix_wron
|
||||
|
||||
return profiles, profile_id
|
||||
|
||||
def set_last_used_time(profiles: dict, profile_id: str, time: datetime.datetime):
|
||||
"""
|
||||
Set profile last used time.
|
||||
:param profiles: Profiles data
|
||||
:param profile_id: Target profile ID.
|
||||
:param time: The time to set
|
||||
:return:
|
||||
"""
|
||||
if not is_profile_exists(profiles, profile_id):
|
||||
raise ProfileException(
|
||||
"Specified profile id {} not found.".format(profile_id)
|
||||
)
|
||||
|
||||
profiles["profiles"][profile_id]["lastUsed"] = time.isoformat().replace("+00:00", "Z")
|
||||
|
||||
def set_last_used_time_to_current(profiles: dict, profile_id: str):
|
||||
"""
|
||||
Set profile last used time to the current time.
|
||||
:param profiles: Profiles data
|
||||
:param profile_id: Target profile ID.
|
||||
:return:
|
||||
"""
|
||||
set_last_used_time(profiles, profile_id, datetime.datetime.now(datetime.timezone.utc))
|
||||
+34
-1
@@ -1,6 +1,8 @@
|
||||
import logging
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from colorlog import ColoredFormatter
|
||||
|
||||
DEFAULT_FORMAT = '%(asctime)s:%(name)s:%(levelname)s: %(message)s'
|
||||
@@ -20,4 +22,35 @@ def get_colorful_handler():
|
||||
datefmt=DEFAULT_DATE_FORMAT
|
||||
)
|
||||
handler.setFormatter(formatter)
|
||||
return handler
|
||||
return handler
|
||||
|
||||
class LogEmitter(QObject):
|
||||
message_emitted = Signal(str)
|
||||
record_emitted = Signal(object)
|
||||
|
||||
|
||||
class LogCaptureHandler(logging.Handler):
|
||||
def __init__(self, max_messages: int = 5000):
|
||||
super().__init__()
|
||||
self.messages = deque(maxlen=max_messages)
|
||||
self.records = deque(maxlen=max_messages)
|
||||
self.emitter = LogEmitter()
|
||||
|
||||
def emit(self, record: logging.LogRecord) -> None:
|
||||
try:
|
||||
message = self.format(record)
|
||||
|
||||
self.records.append(record)
|
||||
self.messages.append(message)
|
||||
|
||||
self.emitter.message_emitted.emit(message)
|
||||
self.emitter.record_emitted.emit(record)
|
||||
except Exception:
|
||||
self.handleError(record)
|
||||
|
||||
def get_messages(self) -> list[str]:
|
||||
return list(self.messages)
|
||||
|
||||
def clear(self) -> None:
|
||||
self.messages.clear()
|
||||
self.records.clear()
|
||||
@@ -5,7 +5,7 @@
|
||||
# nuitka-project: --output-dir={MAIN_DIRECTORY}/build
|
||||
# nuitka-project: --output-filename=launcher
|
||||
# nuitka-project: --product-name=TapLauncher
|
||||
# nuitka-project: --file-description=A Minecraft Launcher
|
||||
# nuitka-project: --file-description=TapLauncher
|
||||
# nuitka-project: --copyright=Copyright (c) Wei's Garage
|
||||
# nuitka-project: --assume-yes-for-downloads
|
||||
# nuitka-project-if: {OS} == "Windows":
|
||||
@@ -29,7 +29,7 @@ from platformdirs import (
|
||||
from app import Launcher
|
||||
from constant import LAUNCHER_DIR_NAME
|
||||
|
||||
from core_lib.log.default import DEFAULT_FORMAT, DEFAULT_DATE_FORMAT, get_colorful_handler
|
||||
from core_lib.log.default import DEFAULT_FORMAT, DEFAULT_DATE_FORMAT, get_colorful_handler, LogCaptureHandler
|
||||
from core_lib.qt import messagebox
|
||||
|
||||
def show_error(message):
|
||||
@@ -92,11 +92,21 @@ def main():
|
||||
root_logger.setLevel(level)
|
||||
root_logger.addHandler(get_colorful_handler())
|
||||
|
||||
# log record handler
|
||||
capture_handler = LogCaptureHandler(max_messages=5000)
|
||||
capture_handler.setLevel(logging.DEBUG)
|
||||
capture_handler.setFormatter(logging.Formatter(
|
||||
DEFAULT_FORMAT,
|
||||
datefmt=DEFAULT_DATE_FORMAT,
|
||||
))
|
||||
|
||||
root_logger.addHandler(capture_handler)
|
||||
|
||||
# Logger configure
|
||||
logging.basicConfig(format=DEFAULT_FORMAT, datefmt=DEFAULT_DATE_FORMAT, level=level)
|
||||
|
||||
# Start (the real) launcher
|
||||
app = Launcher(logger, debug=debug)
|
||||
app = Launcher(logger, capture_handler, debug=debug)
|
||||
sys.exit(app.exec())
|
||||
|
||||
|
||||
|
||||
+347
-28
@@ -7,18 +7,19 @@ from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import queue
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
import keyring
|
||||
from PySide6.QtCore import QObject, Signal, QThread, QTimer, QSize, Qt
|
||||
from PySide6.QtCore import QObject, Signal, QThread, QTimer, QSize, Qt, Slot
|
||||
from PySide6.QtGui import QPixmap, QImage
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
from keyring.errors import KeyringError, PasswordDeleteError
|
||||
|
||||
from constant import LAUNCHER_NAME, CLIENT_ID, ACCESS_TOKEN_KEYWORD, REFRESH_TOKEN_KEYWORD, SYSTEM_KEYRING_KEYWORD
|
||||
from core_lib.common.exception import AccountException, AccountLoadException, AccountSaveException, LauncherException, \
|
||||
ThirdPartyAPIException
|
||||
ThirdPartyAPIException, AuthenticationSessionException, AuthenticationException
|
||||
from core_lib.game.account import (
|
||||
Account,
|
||||
convert_account_data_to_object,
|
||||
@@ -37,11 +38,11 @@ from core_lib.game.account import (
|
||||
)
|
||||
from core_lib.game.authentication import get_xbox_token_and_user_hash, get_microsoft_token, get_xsts_token, \
|
||||
get_minecraft_access_token, get_account_entitlements, get_minecraft_profile, has_minecraft_license, \
|
||||
get_device_code, refresh_microsoft_token
|
||||
get_device_code, refresh_microsoft_token, is_access_token_valid
|
||||
from core_lib.game.third_party import get_minecraft_head
|
||||
from core_lib.qt.hack import data_url_to_qt_image
|
||||
from manager.widgets import AskForRequest
|
||||
|
||||
from manager.settings_models import AccountSettings
|
||||
from manager.widgets import AskForRequest, SignalTransferItem
|
||||
|
||||
DEFAULT_ACCOUNT_RELATIVE_PATH = Path("accounts.json")
|
||||
SERVICE_NAME = f"{LAUNCHER_NAME} Account Manager"
|
||||
@@ -87,6 +88,11 @@ class _AccountUnsetType:
|
||||
|
||||
_UNSET = _AccountUnsetType()
|
||||
|
||||
@dataclass()
|
||||
class AccountLoginStatus:
|
||||
success: bool
|
||||
access_token_is_valid: bool
|
||||
error: str | None
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UpdateAccountRequest:
|
||||
@@ -128,6 +134,7 @@ class LoginSignal(QObject):
|
||||
login_succeeded = Signal(dict)
|
||||
login_failed = Signal(str)
|
||||
finished = Signal()
|
||||
progress_changed = Signal(int, str, bool)
|
||||
|
||||
|
||||
class HeadSignal(QObject):
|
||||
@@ -136,10 +143,16 @@ class HeadSignal(QObject):
|
||||
updated = Signal(str)
|
||||
failed = Signal(str, str)
|
||||
|
||||
class CheckLoginStatusRequest(SignalTransferItem):
|
||||
def __init__(self, account_id: str):
|
||||
super().__init__()
|
||||
self.account_id = account_id
|
||||
self.result_queue = queue.Queue(maxsize=1)
|
||||
|
||||
|
||||
class AccountManager(QObject):
|
||||
"""
|
||||
This manager pack up everything (or most) of the api that provided by core_lib. And make it more easily to use.
|
||||
This manager packs up everything (or most) of the api that provided by core_lib. And make it more easily to use.
|
||||
|
||||
A similar version of the Profile Manager!
|
||||
"""
|
||||
@@ -153,6 +166,11 @@ class AccountManager(QObject):
|
||||
replace_relative_path = Signal(str)
|
||||
token_refreshed = Signal(str)
|
||||
token_refresh_failed = Signal(str, str)
|
||||
token_refresh_started = Signal(str)
|
||||
token_refresh_queue_finished = Signal()
|
||||
check_login_status_requested = Signal(str)
|
||||
login_status_check_started = Signal(str)
|
||||
login_status_checked = Signal(str, object)
|
||||
|
||||
TOKEN_REFRESH_INTERVAL_MS = 5 * 60 * 1000
|
||||
TOKEN_REFRESH_MARGIN = datetime.timedelta(minutes=10)
|
||||
@@ -173,21 +191,23 @@ class AccountManager(QObject):
|
||||
|
||||
# Refresh expiring credentials without blocking the GUI thread.
|
||||
self._refresh_timer = QTimer(self)
|
||||
self._refresh_timer.setInterval(self.TOKEN_REFRESH_INTERVAL_MS)
|
||||
self._refresh_timer.setInterval(self.settings_token_refresh_interval * 1000)
|
||||
self._refresh_timer.timeout.connect(self.refresh_expiring_tokens)
|
||||
self._refresh_thread: QThread | None = None
|
||||
self._refresh_worker: TokenRefreshWorker | None = None
|
||||
self._refresh_account_id: str | None = None
|
||||
self._refresh_queue: list[str] = []
|
||||
self._refresh_queue_active = False
|
||||
|
||||
# Account head downloads. Keep thread and worker references alive until
|
||||
# QThread.finished so Qt does not destroy a running thread.
|
||||
self.head_signal = HeadSignal(self)
|
||||
self._head_jobs: dict[str, tuple[QThread, HeadWorker]] = {}
|
||||
self._login_status_jobs: dict[str, tuple[QThread, CheckLoginStatusWorker]] = {}
|
||||
self.check_login_status_requested.connect(self._start_login_status_check)
|
||||
|
||||
self.account_load.connect(self.load)
|
||||
|
||||
# Flags (For settings page)
|
||||
self.use_system_keyring = True
|
||||
|
||||
#
|
||||
# Account File (aka AccountData) Management
|
||||
#
|
||||
@@ -199,6 +219,24 @@ class AccountManager(QObject):
|
||||
self.error_occurred.emit(code, message)
|
||||
self.widget_manager.signal.show_error_message.emit(message)
|
||||
|
||||
@property
|
||||
def settings_use_system_keyring(self) -> bool:
|
||||
return self.account_settings.credentials_save_method == "system-keyring"
|
||||
|
||||
@property
|
||||
def settings_token_refresh_interval(self) -> int:
|
||||
return self.account_settings.token_refresh_interval
|
||||
|
||||
def set_token_refresh_interval(self, interval_seconds: int,) -> None:
|
||||
was_active = self._refresh_timer.isActive()
|
||||
|
||||
self._refresh_timer.setInterval(
|
||||
interval_seconds * 1000
|
||||
)
|
||||
|
||||
if was_active:
|
||||
self._refresh_timer.start()
|
||||
|
||||
# File lifetime
|
||||
def create_accounts(self, path: str | Path | None = None) -> bool:
|
||||
"""
|
||||
@@ -252,12 +290,19 @@ class AccountManager(QObject):
|
||||
self._show_error("Invalid account file.", "invalid_file")
|
||||
return False, None
|
||||
|
||||
if self.use_system_keyring:
|
||||
if self.settings_use_system_keyring:
|
||||
migrated = self._migrate_plaintext_tokens(result)
|
||||
if migrated is None:
|
||||
return False, None
|
||||
if migrated:
|
||||
create_or_save_account_file(result, path, create_backup=True)
|
||||
else:
|
||||
migrated = self._migrate_keyring_tokens(result)
|
||||
if migrated is None:
|
||||
return False, None
|
||||
|
||||
if migrated:
|
||||
create_or_save_account_file(result, path, create_backup=True)
|
||||
|
||||
self.accounts = result
|
||||
self._path = path
|
||||
@@ -284,7 +329,7 @@ class AccountManager(QObject):
|
||||
path = Path(path) if path is not None else self.path
|
||||
|
||||
try:
|
||||
if self.use_system_keyring and self._contains_plaintext_tokens(self.accounts):
|
||||
if self.settings_use_system_keyring and self._contains_plaintext_tokens(self.accounts):
|
||||
self._show_error(
|
||||
"Refusing to save account data containing plaintext tokens.",
|
||||
"plaintext_credentials",
|
||||
@@ -406,7 +451,7 @@ class AccountManager(QObject):
|
||||
updated = copy.deepcopy(self.accounts)
|
||||
|
||||
# Use system keyring
|
||||
if self.use_system_keyring:
|
||||
if self.settings_use_system_keyring:
|
||||
previous_tokens = self._credential_snapshot(request.account_id)
|
||||
if not self.save_token(request.account_id, ACCESS_TOKEN_KEYWORD, request.access_token):
|
||||
return None
|
||||
@@ -419,8 +464,8 @@ class AccountManager(QObject):
|
||||
account = Account(
|
||||
account_id=request.account_id,
|
||||
username=request.username,
|
||||
access_token=SYSTEM_KEYRING_KEYWORD if self.use_system_keyring else request.access_token,
|
||||
refresh_token=SYSTEM_KEYRING_KEYWORD if self.use_system_keyring else request.refresh_token,
|
||||
access_token=SYSTEM_KEYRING_KEYWORD if self.settings_use_system_keyring else request.access_token,
|
||||
refresh_token=SYSTEM_KEYRING_KEYWORD if self.settings_use_system_keyring else request.refresh_token,
|
||||
access_token_expires_at=request.access_token_expires_at,
|
||||
refresh_token_expires_at=request.refresh_token_expires_at, # Microsoft don't provide refresh token
|
||||
# expire time.
|
||||
@@ -487,7 +532,7 @@ class AccountManager(QObject):
|
||||
for attribute, key in field_map.items():
|
||||
value = getattr(changes, attribute)
|
||||
if value is not None:
|
||||
if key in ("accessToken", "refreshToken") and self.use_system_keyring:
|
||||
if key in ("accessToken", "refreshToken") and self.settings_use_system_keyring:
|
||||
if previous_tokens is None:
|
||||
previous_tokens = self._credential_snapshot(account_id)
|
||||
token_type = (
|
||||
@@ -625,7 +670,7 @@ class AccountManager(QObject):
|
||||
if account is None:
|
||||
return None
|
||||
|
||||
if account.access_token == SYSTEM_KEYRING_KEYWORD and self.use_system_keyring:
|
||||
if account.access_token == SYSTEM_KEYRING_KEYWORD and self.settings_use_system_keyring:
|
||||
access_token = self.get_token(
|
||||
account.id,
|
||||
ACCESS_TOKEN_KEYWORD,
|
||||
@@ -817,6 +862,26 @@ class AccountManager(QObject):
|
||||
|
||||
return None
|
||||
|
||||
def get_actual_token(self, token_type: str, raw_value: str, account_id: str) -> str | None:
|
||||
"""
|
||||
Get actual value of the token
|
||||
|
||||
If the token is stored in the system keyring, this function returns the value from keyring.
|
||||
Otherwise, it returns the raw value.
|
||||
:param token_type:
|
||||
:param raw_value:
|
||||
:param account_id:
|
||||
:return:
|
||||
Return None if the account does not exist.
|
||||
"""
|
||||
if not self.contains(account_id):
|
||||
return None
|
||||
|
||||
if raw_value == SYSTEM_KEYRING_KEYWORD:
|
||||
return self.get_token(account_id, token_type)
|
||||
|
||||
return raw_value or None
|
||||
|
||||
def delete_token(self, account_id: str, token_type: str, missing_ok: bool = False) -> bool:
|
||||
"""
|
||||
Delete account token from system keyring
|
||||
@@ -908,6 +973,45 @@ class AccountManager(QObject):
|
||||
|
||||
return changed
|
||||
|
||||
def _migrate_keyring_tokens(self, accounts: dict) -> bool | None:
|
||||
"""Move keyring credentials to legacy plaintext.
|
||||
|
||||
Is not recommended because saving token in plaintext is insecure.
|
||||
Use it at your own risk!
|
||||
:return: True if any credentials were migrated, False if no credentials were migrated, None if migration failed
|
||||
"""
|
||||
changed = False
|
||||
errors = []
|
||||
for account_id, raw in list_accounts_raw(accounts).items():
|
||||
tokens = {
|
||||
ACCESS_TOKEN_KEYWORD: raw.get(ACCESS_TOKEN_KEYWORD) == SYSTEM_KEYRING_KEYWORD,
|
||||
REFRESH_TOKEN_KEYWORD: raw.get(REFRESH_TOKEN_KEYWORD) == SYSTEM_KEYRING_KEYWORD
|
||||
}
|
||||
|
||||
for keyword, is_unmigrated in tokens.items():
|
||||
if not is_unmigrated: continue
|
||||
|
||||
full_name = self.get_token_full_name(account_id, keyword)
|
||||
token = keyring.get_password(SERVICE_NAME, full_name)
|
||||
|
||||
if token is None:
|
||||
errors.append(f"Token type {keyword} for account {account_id} is not found in keyring")
|
||||
continue
|
||||
|
||||
raw[keyword] = token
|
||||
# Delete token in keyring
|
||||
keyring.delete_password(SERVICE_NAME, full_name)
|
||||
if not changed: changed = True
|
||||
|
||||
if errors:
|
||||
self._show_error(
|
||||
"\n".join(errors),
|
||||
"credential_migration_failed",
|
||||
)
|
||||
return None
|
||||
|
||||
return changed
|
||||
|
||||
@property
|
||||
def path(self) -> Path:
|
||||
if self._path is None:
|
||||
@@ -948,30 +1052,94 @@ class AccountManager(QObject):
|
||||
self._refresh_timer.stop()
|
||||
|
||||
def refresh_expiring_tokens(self) -> bool:
|
||||
"""Refresh one expiring MSA account; later accounts run on following ticks."""
|
||||
if self._refresh_thread is not None or not self.is_loaded:
|
||||
"""Queue MSA accounts whose access tokens are near expiry."""
|
||||
if not self.is_loaded:
|
||||
return False
|
||||
|
||||
deadline = datetime.datetime.now(datetime.timezone.utc) + self.TOKEN_REFRESH_MARGIN
|
||||
account_ids = []
|
||||
for summary in self.list_accounts():
|
||||
if summary.account_type != "msa":
|
||||
continue
|
||||
|
||||
account = self.get_account(summary.id)
|
||||
if account is None:
|
||||
continue
|
||||
|
||||
expires_at = self._as_utc_datetime(account.access_token_expires_at)
|
||||
if expires_at is not None and expires_at > deadline:
|
||||
continue
|
||||
|
||||
refresh_token = account.refresh_token
|
||||
if refresh_token == SYSTEM_KEYRING_KEYWORD and self.use_system_keyring:
|
||||
refresh_token = self.get_token(account.id, REFRESH_TOKEN_KEYWORD)
|
||||
if not refresh_token or refresh_token == SYSTEM_KEYRING_KEYWORD:
|
||||
self.app.logger.warning("Cannot refresh account %s: refresh token is missing", account.id)
|
||||
account_ids.append(account.id)
|
||||
|
||||
return self._queue_token_refreshes(account_ids) > 0
|
||||
|
||||
def refresh_all_tokens(self) -> int:
|
||||
"""Queue a refresh attempt for every Microsoft account."""
|
||||
if not self.is_loaded:
|
||||
return 0
|
||||
|
||||
return self._queue_token_refreshes(
|
||||
summary.id
|
||||
for summary in self.list_accounts()
|
||||
if summary.account_type == "msa"
|
||||
)
|
||||
|
||||
def refresh_account_token(self, account_id: str) -> bool:
|
||||
"""Queue a refresh attempt for one Microsoft account."""
|
||||
if not self.contains(account_id):
|
||||
return False
|
||||
|
||||
account = self.get_account(account_id)
|
||||
if account is None or account.account_type != "msa":
|
||||
return False
|
||||
|
||||
return self._queue_token_refreshes((account_id,)) > 0
|
||||
|
||||
def _queue_token_refreshes(self, account_ids) -> int:
|
||||
queued_ids = set(self._refresh_queue)
|
||||
if self._refresh_account_id is not None:
|
||||
queued_ids.add(self._refresh_account_id)
|
||||
|
||||
added = 0
|
||||
for account_id in account_ids:
|
||||
if account_id in queued_ids:
|
||||
continue
|
||||
self._refresh_queue.append(account_id)
|
||||
queued_ids.add(account_id)
|
||||
added += 1
|
||||
|
||||
if added:
|
||||
self._refresh_queue_active = True
|
||||
self._start_next_token_refresh()
|
||||
|
||||
return added
|
||||
|
||||
def _start_next_token_refresh(self) -> None:
|
||||
if self._refresh_thread is not None:
|
||||
return
|
||||
|
||||
while self._refresh_queue:
|
||||
account_id = self._refresh_queue.pop(0)
|
||||
if not self.contains(account_id):
|
||||
continue
|
||||
|
||||
account = self.get_account(account_id)
|
||||
if account is None or account.account_type != "msa":
|
||||
continue
|
||||
|
||||
refresh_token = self.get_actual_token(
|
||||
REFRESH_TOKEN_KEYWORD,
|
||||
account.refresh_token,
|
||||
account_id,
|
||||
)
|
||||
if not refresh_token:
|
||||
self._token_refresh_failed(account_id, "Refresh token is missing")
|
||||
continue
|
||||
|
||||
self._refresh_account_id = account_id
|
||||
self._refresh_thread = QThread(self)
|
||||
self._refresh_worker = TokenRefreshWorker(account.id, refresh_token, CLIENT_ID)
|
||||
self._refresh_worker = TokenRefreshWorker(account_id, refresh_token, self.get_client_id())
|
||||
self._refresh_worker.moveToThread(self._refresh_thread)
|
||||
self._refresh_thread.started.connect(self._refresh_worker.run)
|
||||
self._refresh_worker.succeeded.connect(self._token_refresh_succeeded)
|
||||
@@ -979,9 +1147,13 @@ class AccountManager(QObject):
|
||||
self._refresh_worker.finished.connect(self._refresh_thread.quit)
|
||||
self._refresh_worker.finished.connect(self._refresh_worker.deleteLater)
|
||||
self._refresh_thread.finished.connect(self._token_refresh_finished)
|
||||
self.token_refresh_started.emit(account_id)
|
||||
self._refresh_thread.start()
|
||||
return True
|
||||
return False
|
||||
return
|
||||
|
||||
if self._refresh_queue_active:
|
||||
self._refresh_queue_active = False
|
||||
self.token_refresh_queue_finished.emit()
|
||||
|
||||
def _token_refresh_succeeded(self, account_id: str, result: dict) -> None:
|
||||
if not self.contains(account_id):
|
||||
@@ -1009,10 +1181,32 @@ class AccountManager(QObject):
|
||||
thread = self._refresh_thread
|
||||
self._refresh_worker = None
|
||||
self._refresh_thread = None
|
||||
self._refresh_account_id = None
|
||||
if thread is not None:
|
||||
thread.deleteLater()
|
||||
QTimer.singleShot(0, self._start_next_token_refresh)
|
||||
|
||||
@property
|
||||
def account_settings(self):
|
||||
return self.app.settings_manager.get("account", AccountSettings)
|
||||
|
||||
@property
|
||||
def settings_custom_client_id(self):
|
||||
return self.account_settings.custom_client_id
|
||||
|
||||
def get_client_id(self):
|
||||
if self.settings_custom_client_id:
|
||||
return self.settings_custom_client_id
|
||||
|
||||
return CLIENT_ID
|
||||
|
||||
def start_login(self):
|
||||
custom_client_id = self.get_client_id()
|
||||
|
||||
if custom_client_id:
|
||||
self.app.logger.debug("Using custom client ID: %s", custom_client_id)
|
||||
client_id = custom_client_id
|
||||
|
||||
def start_login(self, client_id: str = CLIENT_ID):
|
||||
if self.login_thread is not None:
|
||||
return False
|
||||
|
||||
@@ -1030,6 +1224,9 @@ class AccountManager(QObject):
|
||||
self.login_worker.login_failed.connect(
|
||||
self.login_signal.login_failed.emit
|
||||
)
|
||||
self.login_worker.progress_changed.connect(
|
||||
self.login_signal.progress_changed.emit
|
||||
)
|
||||
self.login_thread.started.connect(self.login_worker.run)
|
||||
self.login_worker.finished.connect(self.login_thread.quit)
|
||||
self.login_worker.finished.connect(self.login_worker.deleteLater)
|
||||
@@ -1108,6 +1305,82 @@ class AccountManager(QObject):
|
||||
if self.login_worker is not None:
|
||||
self.login_worker.cancel()
|
||||
|
||||
@Slot(str)
|
||||
def _start_login_status_check(self, account_id: str):
|
||||
if account_id in self._login_status_jobs:
|
||||
# ignore account already checking login status
|
||||
return
|
||||
|
||||
detail: AccountDetail | None = self.get_account(account_id)
|
||||
|
||||
if detail is None:
|
||||
self.login_status_checked.emit(
|
||||
account_id,
|
||||
AccountLoginStatus(
|
||||
success=False,
|
||||
access_token_is_valid=False,
|
||||
error="Account does not exist.",
|
||||
),
|
||||
)
|
||||
return
|
||||
|
||||
access_token = self.get_actual_token(ACCESS_TOKEN_KEYWORD, detail.access_token, account_id)
|
||||
|
||||
if access_token is None:
|
||||
self.login_status_checked.emit(
|
||||
account_id,
|
||||
AccountLoginStatus(
|
||||
success=False,
|
||||
access_token_is_valid=False,
|
||||
error="Unable to get access token for account with ID {}. Token is invalid.".format(account_id),
|
||||
),
|
||||
)
|
||||
return
|
||||
|
||||
# Start background thread
|
||||
thread = QThread(self)
|
||||
worker = CheckLoginStatusWorker(
|
||||
account_id,
|
||||
access_token,
|
||||
)
|
||||
worker.moveToThread(thread)
|
||||
|
||||
self._login_status_jobs[account_id] = (
|
||||
thread,
|
||||
worker,
|
||||
)
|
||||
|
||||
thread.started.connect(worker.run)
|
||||
|
||||
worker.completed.connect(
|
||||
self.login_status_checked.emit
|
||||
)
|
||||
|
||||
worker.finished.connect(thread.quit)
|
||||
worker.finished.connect(worker.deleteLater)
|
||||
|
||||
thread.finished.connect(
|
||||
lambda target_id=account_id:
|
||||
self._login_status_check_finished(
|
||||
target_id
|
||||
)
|
||||
)
|
||||
|
||||
self.login_status_check_started.emit(account_id)
|
||||
thread.start()
|
||||
|
||||
def _login_status_check_finished(self, account_id: str):
|
||||
job = self._login_status_jobs.pop(
|
||||
account_id,
|
||||
None,
|
||||
)
|
||||
|
||||
if job is None:
|
||||
return
|
||||
|
||||
thread, _worker = job
|
||||
thread.deleteLater()
|
||||
|
||||
#
|
||||
# Third Party
|
||||
#
|
||||
@@ -1241,6 +1514,7 @@ class LoginWorker(QObject):
|
||||
login_succeeded = Signal(dict)
|
||||
login_failed = Signal(str)
|
||||
finished = Signal()
|
||||
progress_changed = Signal(int, str, bool)
|
||||
|
||||
def __init__(self, client_id: str):
|
||||
super().__init__()
|
||||
@@ -1252,10 +1526,17 @@ class LoginWorker(QObject):
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
self.progress_changed.emit(
|
||||
5, "Requesting a Microsoft sign-in code...", False
|
||||
)
|
||||
# Get device code
|
||||
device_code, device = get_device_code(self.client_id)
|
||||
self.device_code_ready.emit(device)
|
||||
|
||||
self.progress_changed.emit(
|
||||
15, "Waiting for browser authentication...", True
|
||||
)
|
||||
|
||||
microsoft_access_token, refresh_token, microsoft = get_microsoft_token(
|
||||
self.client_id,
|
||||
device_code,
|
||||
@@ -1263,10 +1544,21 @@ class LoginWorker(QObject):
|
||||
expires_in=device.get("expires_in", 900),
|
||||
cancelled=lambda: self._cancelled,
|
||||
)
|
||||
self.progress_changed.emit(35, "Got microsoft token.", False)
|
||||
|
||||
self.progress_changed.emit(50, "Get xbox token...", False)
|
||||
xbox_token, user_hash, _ = get_xbox_token_and_user_hash(microsoft_access_token)
|
||||
|
||||
self.progress_changed.emit(65, "Getting XSTS token...", False)
|
||||
xsts_token, _ = get_xsts_token(xbox_token)
|
||||
|
||||
self.progress_changed.emit(75, "Getting minecraft access token...", False)
|
||||
minecraft_access_token, minecraft = get_minecraft_access_token(user_hash, xsts_token)
|
||||
|
||||
self.progress_changed.emit(80, "Fetching minecraft entitlements...", False)
|
||||
entitlements = get_account_entitlements(minecraft_access_token)
|
||||
|
||||
self.progress_changed.emit(90, "Fetching minecraft profile...", False)
|
||||
profile = get_minecraft_profile(minecraft_access_token)
|
||||
|
||||
# convert expire value
|
||||
@@ -1276,6 +1568,7 @@ class LoginWorker(QObject):
|
||||
except (TypeError, ValueError):
|
||||
access_expires_in = 86400
|
||||
|
||||
self.progress_changed.emit(95, "Completing login...", False)
|
||||
self.login_succeeded.emit({
|
||||
"id": profile["id"], # UUID
|
||||
"name": profile["name"],
|
||||
@@ -1287,6 +1580,7 @@ class LoginWorker(QObject):
|
||||
"refresh_token_expires_at": now + datetime.timedelta(days=90),
|
||||
"has_license": has_minecraft_license(entitlements),
|
||||
})
|
||||
self.progress_changed.emit(100, "Finished!", True)
|
||||
except InterruptedError:
|
||||
pass
|
||||
except LauncherException as exc:
|
||||
@@ -1347,3 +1641,28 @@ class TokenRefreshWorker(QObject):
|
||||
self.failed.emit(self.account_id, str(exc))
|
||||
finally:
|
||||
self.finished.emit()
|
||||
|
||||
class CheckLoginStatusWorker(QObject):
|
||||
"""Check account login status"""
|
||||
completed = Signal(str, object)
|
||||
finished = Signal()
|
||||
|
||||
def __init__(self, account_id: str, access_token: str):
|
||||
super().__init__()
|
||||
self.account_id = account_id
|
||||
self.access_token = access_token
|
||||
|
||||
def run(self):
|
||||
status = AccountLoginStatus(False, False, None)
|
||||
|
||||
try:
|
||||
status.access_token_is_valid = is_access_token_valid(self.access_token)
|
||||
status.success = True
|
||||
except LauncherException as error:
|
||||
status.error = error.user_message
|
||||
except Exception as error:
|
||||
status.error = str(error)
|
||||
|
||||
finally:
|
||||
self.completed.emit(self.account_id, status)
|
||||
self.finished.emit()
|
||||
+19
-5
@@ -28,7 +28,7 @@ from core_lib.game.version_info import fetch_and_save_version_manifest, get_spec
|
||||
from core_lib.runtime.java import find_java_installations, get_java_version
|
||||
from core_lib.runtime.mojang import download_java_runtimes, fetch_runtime_manifest, get_current_platform_runtime_key
|
||||
from manager.account import AccountManager, LaunchAccount
|
||||
from manager.profile import LaunchProfile
|
||||
from manager.profile import LaunchProfile, ProfileManager
|
||||
from manager.widgets import SelectPathRequest, AskForRequest, SignalTransferItem
|
||||
|
||||
MAX_DOWNLOAD_ATTEMPTS = 3
|
||||
@@ -967,6 +967,7 @@ class LaunchResult:
|
||||
error_message: str | None = None
|
||||
warnings: list[str] = field(default_factory=list)
|
||||
fail_callback: Callable | None = None
|
||||
success_callback: Callable | None = None
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
@@ -983,19 +984,20 @@ class LaunchResult:
|
||||
|
||||
class LaunchManager:
|
||||
def __init__(self, app, manifest_manager: ManifestManager, java_manager: JavaManager, game_file_manager: GameFileManager,
|
||||
account_manager: AccountManager):
|
||||
account_manager: AccountManager, profile_manager: ProfileManager):
|
||||
self.app = app
|
||||
self.manifest_mgr = manifest_manager
|
||||
self.widget_mgr = app.widget_manager
|
||||
self.java_mgr = java_manager
|
||||
self.game_file_mgr = game_file_manager
|
||||
self.account_mgr = account_manager
|
||||
self.profile_mgr = profile_manager
|
||||
self.launching_profiles: set[str] = set()
|
||||
self.launched_profiles: list[str] = []
|
||||
self.signal = self.LaunchSignal()
|
||||
|
||||
class LaunchSignal(QObject):
|
||||
finished = Signal(object, object) # LaunchProfile, LaunchResult
|
||||
finished = Signal(object, object) # LaunchProfile, LaunchResult > LaunchProfilePage.launch_finished()
|
||||
|
||||
def launch(self, profile: LaunchProfile) -> LaunchResult:
|
||||
result = LaunchResult()
|
||||
@@ -1003,7 +1005,12 @@ class LaunchManager:
|
||||
def fail_callback():
|
||||
self.profile_failed(profile.profile_id)
|
||||
|
||||
def success_callback():
|
||||
self.profile_mgr.update_last_used_time(profile.profile_id)
|
||||
self.profile_mgr.set_current_profile(profile.profile_id)
|
||||
|
||||
result.fail_callback = fail_callback
|
||||
result.success_callback = success_callback
|
||||
try:
|
||||
version_id = profile.version_id
|
||||
version_id = self.manifest_mgr.resolve_version_alias(version_id)
|
||||
@@ -1083,7 +1090,12 @@ class LaunchManager:
|
||||
"Select a account before launching."
|
||||
)
|
||||
|
||||
launch_account: LaunchAccount = self.account_mgr.get_launch_account()
|
||||
launch_account: LaunchAccount | None = self.account_mgr.get_launch_account()
|
||||
|
||||
if not launch_account:
|
||||
return result.fail(
|
||||
"Select a launch account before launching."
|
||||
)
|
||||
|
||||
# Asset
|
||||
default_assets_dir = Path(self.app.work_dir, "assets")
|
||||
@@ -1307,8 +1319,10 @@ class GameManager(QObject):
|
||||
super(GameManager, self).__init__(parent)
|
||||
self.app = app
|
||||
self.account_manager = app.account_manager
|
||||
self.profile_mgr = app.profile_manager
|
||||
self.widget_mgr = app.widget_manager
|
||||
self.manifest = ManifestManager(self.app)
|
||||
self.java = JavaManager(self.app)
|
||||
self.game_file = GameFileManager(self.app, manifest_manager=self.manifest)
|
||||
self.launch = LaunchManager(self.app, self.manifest, self.java, self.game_file, self.account_manager)
|
||||
self.launch = LaunchManager(self.app, self.manifest,
|
||||
self.java, self.game_file, self.account_manager, self.profile_mgr)
|
||||
+76
-18
@@ -8,13 +8,14 @@ from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from core_lib.common.exception import ProfileException, ProfileLoadException, ProfileSaveException
|
||||
from core_lib.game.profile import read_profile_file, is_profiles_valid, \
|
||||
get_profile_sample, create_or_save_profile_file, list_profiles as list_profiles_raw, convert_profile_data_to_object, \
|
||||
is_profile_exists, create_profile as create_profile_raw, update_profile as update_profile_raw, \
|
||||
get_current_profile_id, set_current_profile_id, remove_profile, duplicate_profile
|
||||
get_current_profile_id, set_current_profile_id, remove_profile, duplicate_profile, \
|
||||
set_last_used_time
|
||||
from core_lib.game.version_info import LATEST_VERSION_ALIASES
|
||||
from manager.widgets import AskForRequest
|
||||
|
||||
@@ -230,6 +231,21 @@ class ProfileManager(QObject):
|
||||
)
|
||||
return False
|
||||
|
||||
def _commit_profiles(self, updated_profiles: dict) -> bool:
|
||||
"""Persist an updated profile document and roll back memory on failure."""
|
||||
previous_profiles = self.profiles
|
||||
previous_modified = self._is_modified
|
||||
|
||||
self.profiles = updated_profiles
|
||||
self._is_modified = True
|
||||
|
||||
if self.save():
|
||||
return True
|
||||
|
||||
self.profiles = previous_profiles
|
||||
self._is_modified = previous_modified
|
||||
return False
|
||||
|
||||
def reload(self) -> tuple[bool, dict | None]:
|
||||
return self.load(path=self.path)
|
||||
|
||||
@@ -348,10 +364,10 @@ class ProfileManager(QObject):
|
||||
if not is_profiles_valid(updated_profiles):
|
||||
raise ProfileException("Created profile data is invalid.")
|
||||
|
||||
self.profiles = updated_profiles
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return None
|
||||
|
||||
# Update change event and flag
|
||||
self._is_modified = True
|
||||
# Update change events after the data is persisted.
|
||||
self.profile_created.emit(profile_id)
|
||||
self.profiles_changed.emit()
|
||||
|
||||
@@ -442,9 +458,8 @@ class ProfileManager(QObject):
|
||||
if profile_data == list_profiles_raw(self.profiles)[profile_id]:
|
||||
return True
|
||||
|
||||
# Update event and flag
|
||||
self.profiles = updated_profiles
|
||||
self._is_modified = True
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return False
|
||||
|
||||
self.profile_updated.emit(profile_id)
|
||||
self.profiles_changed.emit()
|
||||
@@ -472,10 +487,9 @@ class ProfileManager(QObject):
|
||||
if is_current_changed:
|
||||
updated_profiles["lastPlayedProfileID"] = None
|
||||
|
||||
self.profiles = updated_profiles
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return False
|
||||
|
||||
# event
|
||||
self._is_modified = True
|
||||
self.profile_removed.emit(profile_id)
|
||||
|
||||
if is_current_changed:
|
||||
@@ -507,9 +521,9 @@ class ProfileManager(QObject):
|
||||
new_name,
|
||||
)
|
||||
|
||||
# Update event and flag
|
||||
self.profiles = updated_profiles
|
||||
self._is_modified = True
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return None
|
||||
|
||||
self.profile_created.emit(new_profile_id)
|
||||
self.profiles_changed.emit()
|
||||
|
||||
@@ -551,13 +565,14 @@ class ProfileManager(QObject):
|
||||
"Replacing current profile ID {} to {}".format(existing_id, profile_id)
|
||||
)
|
||||
|
||||
set_current_profile_id(self.profiles, profile_id)
|
||||
updated_profiles = copy.deepcopy(self.profiles)
|
||||
set_current_profile_id(updated_profiles, profile_id)
|
||||
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return False
|
||||
|
||||
# event and flag update
|
||||
self._is_modified = True
|
||||
self.current_profile_changed.emit(profile_id)
|
||||
self.profiles_changed.emit()
|
||||
|
||||
return True
|
||||
except ProfileException as e:
|
||||
self.widget_manager.signal.show_error_message.emit(
|
||||
@@ -570,6 +585,49 @@ class ProfileManager(QObject):
|
||||
)
|
||||
return False
|
||||
|
||||
def update_last_used_time(
|
||||
self,
|
||||
profile_id: str,
|
||||
time: datetime | None = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Update profile last used time
|
||||
:param profile_id:
|
||||
:param time:
|
||||
:return:
|
||||
"""
|
||||
if time is None:
|
||||
time = datetime.now(timezone.utc)
|
||||
|
||||
if not self.is_loaded:
|
||||
success, _ = self.load()
|
||||
|
||||
if not success:
|
||||
return False
|
||||
|
||||
if profile_id is not None and not self.contains(profile_id, show_error=True):
|
||||
return False
|
||||
|
||||
try:
|
||||
updated_profiles = copy.deepcopy(self.profiles)
|
||||
set_last_used_time(updated_profiles, profile_id, time)
|
||||
|
||||
if not self._commit_profiles(updated_profiles):
|
||||
return False
|
||||
|
||||
self.profiles_changed.emit()
|
||||
return True
|
||||
except ProfileException as e:
|
||||
self.widget_manager.signal.show_error_message.emit(
|
||||
f"Unable to set last used time for profile ID: {e.user_message}"
|
||||
)
|
||||
return False
|
||||
except Exception as e:
|
||||
self.widget_manager.signal.show_error_message.emit(
|
||||
f"Unable to set last used time for profile with ID {profile_id}. An unknown error occurred {str(e)}"
|
||||
)
|
||||
return False
|
||||
|
||||
def get_current_profile_id(self) -> str | None:
|
||||
if not self.is_loaded:
|
||||
success, _ = self.load()
|
||||
|
||||
+2
-1
@@ -163,9 +163,10 @@ class SettingsManager:
|
||||
data = {
|
||||
section: self._models[section]
|
||||
.model_validate(self._settings[section])
|
||||
.model_dump(mode="json")
|
||||
.model_dump(mode="json", exclude_none=True) # ignore None keys
|
||||
for section in self._models
|
||||
}
|
||||
|
||||
config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
temporary_path = config_path.with_suffix(config_path.suffix + ".tmp")
|
||||
temporary_path.write_bytes(tomli_w.dumps(data).encode("utf-8"))
|
||||
|
||||
+62
-11
@@ -1,26 +1,77 @@
|
||||
"""Launcher settings schemas persisted by SettingsManager."""
|
||||
|
||||
from typing import Literal
|
||||
import warnings
|
||||
from typing import Literal, Any
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from pydantic import BaseModel, ConfigDict, field_validator, model_validator
|
||||
|
||||
from constant import CLIENT_ID
|
||||
|
||||
class WarnExtraModel(BaseModel):
|
||||
model_config = ConfigDict(extra="ignore")
|
||||
|
||||
class GeneralSettings(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def warn_extra_fields(cls, data: Any) -> Any:
|
||||
if isinstance(data, dict):
|
||||
extra = set(data) - set(cls.model_fields)
|
||||
if extra:
|
||||
warnings.warn(
|
||||
f"{cls.__name__}: ignored extra fields: {sorted(extra)}",
|
||||
UserWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return data
|
||||
|
||||
class GeneralSettings(WarnExtraModel):
|
||||
model_config = ConfigDict()
|
||||
|
||||
language: Literal["en", "zh-TW"] = "zh-TW"
|
||||
|
||||
|
||||
class AppearanceSettings(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
class AppearanceSettings(WarnExtraModel):
|
||||
model_config = ConfigDict()
|
||||
|
||||
theme: Literal["system", "light", "dark"] = "system"
|
||||
theme: str = "system"
|
||||
|
||||
@field_validator("theme")
|
||||
@classmethod
|
||||
def validate_theme_name(cls, value: str) -> str:
|
||||
value = value.strip()
|
||||
if not value or "/" in value or "\\" in value or ".." in value:
|
||||
raise ValueError("invalid theme name")
|
||||
return value
|
||||
|
||||
|
||||
class AccountSettings(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
class AccountSettings(WarnExtraModel):
|
||||
model_config = ConfigDict()
|
||||
|
||||
client_id: UUID = UUID(CLIENT_ID)
|
||||
credentials_save_method: Literal["system-keyring", "file"] = "system-keyring"
|
||||
custom_client_id: UUID | None = None
|
||||
token_refresh_interval: int = 600
|
||||
@field_validator("custom_client_id", mode="before")
|
||||
@classmethod
|
||||
def validate_custom_client_id(cls, value: str | None | UUID) -> UUID | None:
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
if isinstance(value, UUID):
|
||||
return value
|
||||
|
||||
if isinstance(value, str):
|
||||
value = value.strip()
|
||||
|
||||
if not value:
|
||||
return None
|
||||
|
||||
try:
|
||||
return UUID(value)
|
||||
except (TypeError, ValueError, AttributeError) as error:
|
||||
raise ValueError("invalid client ID") from error
|
||||
|
||||
@field_validator("token_refresh_interval", mode="before")
|
||||
@classmethod
|
||||
def validate_token_refresh_interval(cls, value: int) -> int:
|
||||
if value < 60 or value > 86400:
|
||||
raise ValueError("token refresh interval must be at least 60 seconds and at most 1 day")
|
||||
return value
|
||||
+127
-28
@@ -14,21 +14,23 @@ from PySide6.QtWidgets import (
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
QVBoxLayout,
|
||||
QWidget, QDialog, QLineEdit, QApplication, QToolButton,
|
||||
QWidget, QDialog, QLineEdit, QApplication, QToolButton, QProgressBar,
|
||||
)
|
||||
|
||||
from constant import MICROSOFT_VERIFY_ENDPOINT
|
||||
from constant import MICROSOFT_VERIFY_ENDPOINT, CLIENT_ID
|
||||
|
||||
from core_lib.qt.hack import move_window_to_center
|
||||
from manager.account import AccountManager, AccountSummary
|
||||
from manager.account import AccountManager, AccountSummary, AccountLoginStatus
|
||||
from manager.settings_models import AccountSettings
|
||||
|
||||
|
||||
class AccountWidget(QWidget):
|
||||
def __init__(self, app, account_name: str, account_head: QPixmap, login_status: str, parent=None,
|
||||
/, delete_account_callback=None, check_account_callback=None, switch_account_callback=None,):
|
||||
def __init__(self, app, account_id: str, account_name: str, account_head: QPixmap, login_status: str, parent=None,
|
||||
/, delete_account_callback=None, check_account_callback=None, refresh_token_callback=None,
|
||||
switch_account_callback=None,):
|
||||
super().__init__(parent)
|
||||
self.app = app
|
||||
self.account_id = account_id
|
||||
|
||||
# Layout
|
||||
self.layout = QHBoxLayout(self)
|
||||
@@ -51,6 +53,7 @@ class AccountWidget(QWidget):
|
||||
# Callback
|
||||
self.delete_account_callback = delete_account_callback
|
||||
self.check_account_callback = check_account_callback
|
||||
self.refresh_token_callback = refresh_token_callback
|
||||
self.switch_account_callback = switch_account_callback
|
||||
|
||||
self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
@@ -60,6 +63,7 @@ class AccountWidget(QWidget):
|
||||
menu = QMenu(self)
|
||||
switch_action = menu.addAction(self.app.tr_text("Switch to this account"))
|
||||
check_action = menu.addAction(self.app.tr_text("Check login status"))
|
||||
refresh_action = menu.addAction(self.app.tr_text("Refresh token"))
|
||||
menu.addSeparator()
|
||||
delete_action = menu.addAction(self.app.tr_text("Delete account"))
|
||||
selected = menu.exec(self.mapToGlobal(position))
|
||||
@@ -68,6 +72,8 @@ class AccountWidget(QWidget):
|
||||
self.delete_account_callback()
|
||||
elif selected == check_action and callable(self.check_account_callback):
|
||||
self.check_account_callback()
|
||||
elif selected == refresh_action and callable(self.refresh_token_callback):
|
||||
self.refresh_token_callback()
|
||||
elif selected == switch_action and callable(self.switch_account_callback):
|
||||
self.switch_account_callback()
|
||||
|
||||
@@ -106,6 +112,13 @@ class LoginDialog(QDialog):
|
||||
self.error_label.setWordWrap(True)
|
||||
self.error_label.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
|
||||
|
||||
# Progress label
|
||||
self.progress_label = QLabel(
|
||||
self.app.tr_text("Preparing Microsoft sign-in…")
|
||||
)
|
||||
self.progress_label.setObjectName("progressText")
|
||||
self.progress_label.setWordWrap(True)
|
||||
|
||||
# Button
|
||||
self.copy_code_button = QPushButton(self.app.tr_text("Copy code"))
|
||||
self.copy_code_button.setObjectName("copyCodeButton")
|
||||
@@ -114,6 +127,7 @@ class LoginDialog(QDialog):
|
||||
|
||||
self.center_layout = QVBoxLayout()
|
||||
self.center_layout.setSpacing(10)
|
||||
self.center_layout.addWidget(self.progress_label)
|
||||
self.center_layout.addWidget(self.code_edit)
|
||||
self.center_layout.addWidget(self.error_label)
|
||||
|
||||
@@ -141,6 +155,9 @@ class LoginDialog(QDialog):
|
||||
def set_code(self, code):
|
||||
self.code_edit.setText(str(code or ""))
|
||||
|
||||
def set_progress(self, value, message, busy=False):
|
||||
self.progress_label.setText(f"{message} {f"{f"({value}%)" if not busy else ""}"}")
|
||||
|
||||
def copy_code(self):
|
||||
QApplication.clipboard().setText(self.code)
|
||||
self.copy_code_button.setText(self.app.tr_text("Copied!"))
|
||||
@@ -176,17 +193,20 @@ class AccountPage(QWidget):
|
||||
self.account_list = QListWidget(self)
|
||||
self.add_account_button = QPushButton(self.app.tr_text("Add Account"))
|
||||
self.refresh_button = QPushButton(self.app.tr_text("Refresh all"))
|
||||
self.reload_button = QPushButton(self.app.tr_text("Reload accounts"))
|
||||
self.delete_all_button = QPushButton(self.app.tr_text("Delete All"))
|
||||
|
||||
# Button click handle
|
||||
self.add_account_button.clicked.connect(self.start_login_page)
|
||||
self.refresh_button.clicked.connect(self.refresh_accounts)
|
||||
self.reload_button.clicked.connect(self.reload_accounts)
|
||||
self.delete_all_button.clicked.connect(self.account_manager.delete_all_accounts)
|
||||
|
||||
# Bind widget
|
||||
main_layout.addWidget(self.account_list)
|
||||
right_layout.addWidget(self.add_account_button)
|
||||
right_layout.addWidget(self.refresh_button)
|
||||
right_layout.addWidget(self.reload_button)
|
||||
right_layout.addWidget(self.delete_all_button)
|
||||
right_layout.addStretch()
|
||||
|
||||
@@ -201,16 +221,37 @@ class AccountPage(QWidget):
|
||||
self.account_manager.login_signal.login_succeeded.connect(self._login_succeeded)
|
||||
self.account_manager.login_signal.login_failed.connect(self._login_failed)
|
||||
self.account_manager.login_signal.finished.connect(self._login_finished)
|
||||
self.account_manager.login_signal.progress_changed.connect(self._login_progress_changed)
|
||||
self.account_manager.head_signal.updated.connect(self._account_head_updated)
|
||||
self.account_manager.login_status_checked.connect(self._login_status_checked)
|
||||
self.account_manager.login_status_check_started.connect(self._log_status_check_started)
|
||||
self.account_manager.token_refresh_started.connect(self._token_refresh_started)
|
||||
self.account_manager.token_refreshed.connect(self._token_refreshed)
|
||||
self.account_manager.token_refresh_failed.connect(self._token_refresh_failed)
|
||||
self.account_manager.token_refresh_queue_finished.connect(self._token_refresh_queue_finished)
|
||||
self._render_accounts()
|
||||
|
||||
def set_related_button(self, button: QToolButton):
|
||||
self.related_button = button
|
||||
self._update_related_button(None)
|
||||
|
||||
def _login_progress_changed(self, value: int, message: str, busy: bool):
|
||||
if self.login_dialog is not None:
|
||||
self.login_dialog.set_progress(value, message, busy)
|
||||
|
||||
def _find_account_widget(self, account_id: str):
|
||||
for row in range(self.account_list.count()):
|
||||
item = self.account_list.item(row)
|
||||
widget = self.account_list.itemWidget(item)
|
||||
|
||||
if isinstance(widget, AccountWidget) and widget.account_id == account_id:
|
||||
return widget
|
||||
|
||||
return None
|
||||
|
||||
def _update_related_button(self, account_id: str | None):
|
||||
"""
|
||||
Update related button's icon to current (active) account avatar
|
||||
Update the related button's icon to the current (active) account avatar
|
||||
:param account_id:
|
||||
:return:
|
||||
"""
|
||||
@@ -260,12 +301,14 @@ class AccountPage(QWidget):
|
||||
head_size = QSize(32, 32)
|
||||
widget = AccountWidget(
|
||||
self.app,
|
||||
account.id,
|
||||
account.display_name,
|
||||
self.account_manager.get_head_pixmap(account.avatar, head_size),
|
||||
self.app.tr_text("Current" if is_current else "Available"),
|
||||
self,
|
||||
delete_account_callback=lambda: self._delete_account(account.id),
|
||||
check_account_callback=lambda: self._show_account_status(account.id),
|
||||
check_account_callback=lambda: self.account_manager.check_login_status_requested.emit(account.id),
|
||||
refresh_token_callback=lambda: self.account_manager.refresh_account_token(account.id),
|
||||
switch_account_callback=lambda: self._switch_account(account.id),
|
||||
)
|
||||
|
||||
@@ -304,24 +347,6 @@ class AccountPage(QWidget):
|
||||
if self.account_manager.remove_account(account_id):
|
||||
self.account_manager.save()
|
||||
|
||||
def _show_account_status(self, account_id: str):
|
||||
account = self.account_manager.get_account(account_id)
|
||||
|
||||
if account is None:
|
||||
return
|
||||
|
||||
QMessageBox.information(
|
||||
self,
|
||||
self.app.tr_text("Account status"),
|
||||
self.app.tr_text(
|
||||
"{account} — Minecraft profile {status}",
|
||||
account=account.display_name,
|
||||
status=self.app.tr_text(
|
||||
"available" if account.minecraft_uuid else "not available"
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
def _switch_account(self, account_id: str):
|
||||
self.account_manager.set_current_account(account_id)
|
||||
self.account_manager.save()
|
||||
@@ -330,8 +355,30 @@ class AccountPage(QWidget):
|
||||
self._render_accounts()
|
||||
|
||||
def refresh_accounts(self):
|
||||
self.account_manager.refresh_all_tokens()
|
||||
|
||||
def reload_accounts(self):
|
||||
self.account_manager.reload()
|
||||
|
||||
def _token_refresh_started(self, account_id: str):
|
||||
self.refresh_button.setEnabled(False)
|
||||
widget = self._find_account_widget(account_id)
|
||||
if widget is not None:
|
||||
widget.status_label.setText(self.app.tr_text("Refreshing…"))
|
||||
|
||||
def _token_refreshed(self, account_id: str):
|
||||
widget = self._find_account_widget(account_id)
|
||||
if widget is not None:
|
||||
widget.status_label.setText(self.app.tr_text("Signed in"))
|
||||
|
||||
def _token_refresh_failed(self, account_id: str, _message: str):
|
||||
widget = self._find_account_widget(account_id)
|
||||
if widget is not None:
|
||||
widget.status_label.setText(self.app.tr_text("Refresh failed"))
|
||||
|
||||
def _token_refresh_queue_finished(self):
|
||||
self.refresh_button.setEnabled(True)
|
||||
|
||||
# Microsoft sign-in
|
||||
def start_login_page(self):
|
||||
# Active existing login dialog
|
||||
@@ -349,9 +396,7 @@ class AccountPage(QWidget):
|
||||
self.login_dialog.open_browser_button.clicked.connect(self.open_sign_in_page)
|
||||
self.login_dialog.rejected.connect(self.account_manager.cancel_login)
|
||||
self.login_dialog.show()
|
||||
|
||||
account_settings = self.app.settings_manager.get("account", AccountSettings)
|
||||
self.account_manager.start_login(str(account_settings.client_id))
|
||||
self.account_manager.start_login()
|
||||
|
||||
def _show_device_code(self, device: dict):
|
||||
self._verification_uri = device.get("verification_uri", MICROSOFT_VERIFY_ENDPOINT)
|
||||
@@ -393,3 +438,57 @@ class AccountPage(QWidget):
|
||||
|
||||
def _login_finished(self):
|
||||
self.add_account_button.setEnabled(True)
|
||||
|
||||
def _log_status_check_started(self, account_id: str):
|
||||
widget = self._find_account_widget(account_id)
|
||||
|
||||
if widget is not None:
|
||||
widget.status_label.setText(
|
||||
self.app.tr_text("Checking…")
|
||||
)
|
||||
|
||||
def _login_status_checked(self, account_id: str, status: AccountLoginStatus):
|
||||
account = self.account_manager.get_account(
|
||||
account_id
|
||||
)
|
||||
|
||||
if account is None:
|
||||
return
|
||||
|
||||
widget = self._find_account_widget(account_id)
|
||||
|
||||
if widget is not None:
|
||||
if not status.success:
|
||||
widget.status_label.setText(
|
||||
self.app.tr_text("Check failed")
|
||||
)
|
||||
elif status.access_token_is_valid:
|
||||
widget.status_label.setText(
|
||||
self.app.tr_text("Signed in")
|
||||
)
|
||||
else:
|
||||
widget.status_label.setText(
|
||||
self.app.tr_text("Expired")
|
||||
)
|
||||
|
||||
if not status.success:
|
||||
message = self.app.tr_text(
|
||||
"Unable to check login status: {error}",
|
||||
error=status.error or "Unknown error",
|
||||
)
|
||||
elif status.access_token_is_valid:
|
||||
message = self.app.tr_text(
|
||||
"{account} is currently signed in.",
|
||||
account=account.display_name,
|
||||
)
|
||||
else:
|
||||
message = self.app.tr_text(
|
||||
"{account}'s session has expired.",
|
||||
account=account.display_name,
|
||||
)
|
||||
|
||||
QMessageBox.information(
|
||||
self,
|
||||
self.app.tr_text("Account status"),
|
||||
message,
|
||||
)
|
||||
@@ -525,7 +525,8 @@ class CreateProfilePage(QWidget):
|
||||
version_type=version_type,
|
||||
)
|
||||
|
||||
# Switch to current profile and save
|
||||
# Create and optionally switch to the new profile. ProfileManager
|
||||
# persists each successful mutation.
|
||||
profile_id = self.app.profile_manager.create_profile(request)
|
||||
if profile_id is None:
|
||||
return
|
||||
@@ -534,9 +535,6 @@ class CreateProfilePage(QWidget):
|
||||
if not self.app.profile_manager.set_current_profile(profile_id):
|
||||
return
|
||||
|
||||
if not self.app.profile_manager.save():
|
||||
return
|
||||
|
||||
self.widget_mgr.signal.show_info_message.emit(
|
||||
self.app.tr_text("Profile {profile_id} successfully created.", profile_id=profile_id),
|
||||
)
|
||||
@@ -623,9 +621,6 @@ class CreateProfilePage(QWidget):
|
||||
if not self.app.profile_manager.set_current_profile(profile_id):
|
||||
return
|
||||
|
||||
if not self.app.profile_manager.save():
|
||||
return
|
||||
|
||||
self.widget_mgr.signal.show_info_message.emit(
|
||||
self.app.tr_text(
|
||||
"Profile {profile_id} with fabric loader successfully created.",
|
||||
|
||||
@@ -332,6 +332,9 @@ class LaunchProfilePage(QWidget):
|
||||
)
|
||||
self.status_label_cleanup()
|
||||
return
|
||||
else:
|
||||
if callable(result.success_callback):
|
||||
result.success_callback()
|
||||
|
||||
# Create log view
|
||||
log_window = ProcessLogWindow(
|
||||
|
||||
@@ -403,7 +403,6 @@ class ManageProfilePage(QWidget):
|
||||
if self.profile_manager.validate_update(request).is_valid and self.profile_manager.update_profile(
|
||||
self.selected_profile_id, request
|
||||
):
|
||||
self.profile_manager.save()
|
||||
self.app.widget_manager.signal.show_info_message.emit(
|
||||
self.app.tr_text("Profile settings saved.")
|
||||
)
|
||||
@@ -478,7 +477,6 @@ class ManageProfilePage(QWidget):
|
||||
if new_id:
|
||||
self.selected_profile_id = new_id
|
||||
self.load_profiles()
|
||||
self.profile_manager.save()
|
||||
|
||||
def delete_profile(self, profile: ProfileSummary | None=None) -> None:
|
||||
if self.selected_profile_id is None and profile is None:
|
||||
@@ -496,4 +494,3 @@ class ManageProfilePage(QWidget):
|
||||
if answer == QMessageBox.StandardButton.Yes:
|
||||
if self.profile_manager.remove_profile(profile_id):
|
||||
self.selected_profile_id = None
|
||||
self.profile_manager.save()
|
||||
+182
-29
@@ -1,3 +1,4 @@
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from PySide6.QtCore import Qt
|
||||
@@ -11,21 +12,19 @@ from PySide6.QtWidgets import (
|
||||
QPushButton,
|
||||
QStackedWidget,
|
||||
QVBoxLayout,
|
||||
QWidget, QScrollArea,
|
||||
QWidget, QScrollArea, QSizePolicy, QSpinBox,
|
||||
)
|
||||
|
||||
from constant import LAUNCHER_DESCRIPTION, LAUNCHER_NAME, LAUNCHER_VERSION
|
||||
from manager.settings_models import AccountSettings, AppearanceSettings, GeneralSettings
|
||||
|
||||
|
||||
LANGUAGE_LABELS = {
|
||||
"en": "English",
|
||||
"zh-TW": "Chinese (Traditional)",
|
||||
}
|
||||
THEME_LABELS = {
|
||||
"system": "Follow system settings",
|
||||
"light": "Light",
|
||||
"dark": "Dark",
|
||||
CREDENTIALS_SAVE_METHODS = {
|
||||
"system-keyring": "Use system keyring",
|
||||
"file": "Save as a regular file",
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +53,7 @@ class SettingsItem(QPushButton):
|
||||
|
||||
|
||||
class SettingsSubPage(QWidget):
|
||||
def __init__(self, title: str, back_callback) -> None:
|
||||
def __init__(self, title: str, back_callback, /, expand_content: bool = False) -> None:
|
||||
super().__init__()
|
||||
self.setObjectName("settingsSubPage")
|
||||
|
||||
@@ -78,7 +77,12 @@ class SettingsSubPage(QWidget):
|
||||
self.content_layout = QVBoxLayout()
|
||||
self.content_layout.setSpacing(12)
|
||||
main_layout.addLayout(header_layout)
|
||||
main_layout.addLayout(self.content_layout)
|
||||
self.content_layout.setContentsMargins(0, 0, 0, 0)
|
||||
self.content_layout.setSpacing(6)
|
||||
if expand_content:
|
||||
main_layout.addLayout(self.content_layout, 1)
|
||||
else:
|
||||
main_layout.addLayout(self.content_layout)
|
||||
main_layout.addStretch()
|
||||
|
||||
|
||||
@@ -87,6 +91,7 @@ class SettingsPage(QWidget):
|
||||
super().__init__(parent)
|
||||
self.app = app
|
||||
self.settings = app.settings_manager
|
||||
self.account_mgr = app.account_manager
|
||||
self._settings_dirty = False
|
||||
self.setObjectName("settingsPage")
|
||||
|
||||
@@ -99,12 +104,14 @@ class SettingsPage(QWidget):
|
||||
self.appearance_page = self._create_appearance_page()
|
||||
self.account_page = self._create_account_page()
|
||||
self.about_page = self._create_about_page()
|
||||
self.log_page = self._create_log_page()
|
||||
for page in (
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
self.log_page,
|
||||
):
|
||||
self.stack.addWidget(page)
|
||||
|
||||
@@ -116,6 +123,10 @@ class SettingsPage(QWidget):
|
||||
self.theme_combo.currentIndexChanged.connect(
|
||||
self._apply_selected_theme
|
||||
)
|
||||
|
||||
self.credentials_save_method.currentIndexChanged.connect(
|
||||
self._mark_settings_dirty
|
||||
)
|
||||
self.app.i18n.language_changed.connect(self.retranslate_ui)
|
||||
|
||||
def _apply_selected_theme(self) -> None:
|
||||
@@ -137,11 +148,11 @@ class SettingsPage(QWidget):
|
||||
self.account_page = self._create_account_page()
|
||||
self.about_page = self._create_about_page()
|
||||
for page in (
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
self.main_page,
|
||||
self.general_page,
|
||||
self.appearance_page,
|
||||
self.account_page,
|
||||
self.about_page,
|
||||
):
|
||||
self.stack.addWidget(page)
|
||||
self.stack.setCurrentIndex(min(current_page, self.stack.count() - 1))
|
||||
@@ -178,6 +189,7 @@ class SettingsPage(QWidget):
|
||||
(tr("Appearance"), tr("Launcher theme"), "appearance_page"),
|
||||
(tr("Account"), tr("Microsoft authentication settings"), "account_page"),
|
||||
(tr("About"), tr("Version and project information"), "about_page"),
|
||||
(tr("Logger"), tr("Launcher log"), "log_page"),
|
||||
)
|
||||
for title_text, description, page_name in pages:
|
||||
button = SettingsItem(title_text, description)
|
||||
@@ -221,10 +233,21 @@ class SettingsPage(QWidget):
|
||||
current = self.settings.get("appearance", AppearanceSettings)
|
||||
|
||||
page.content_layout.addWidget(QLabel(tr("Theme")))
|
||||
self.theme_combo = self._choice_combo(
|
||||
"appearance", "theme", THEME_LABELS, current.theme
|
||||
)
|
||||
self.theme_combo = QComboBox()
|
||||
for theme_id, name in self.app.available_themes().items():
|
||||
self.theme_combo.addItem(tr(name), theme_id)
|
||||
|
||||
index = self.theme_combo.findData(current.theme)
|
||||
self.theme_combo.setCurrentIndex(max(index, 0))
|
||||
page.content_layout.addWidget(self.theme_combo)
|
||||
|
||||
help_label = QLabel(tr(
|
||||
"Add theme folders containing theme.toml and palette.toml to: {path}",
|
||||
path=self.app.user_themes_dir,
|
||||
))
|
||||
help_label.setObjectName("settingsHelpText")
|
||||
help_label.setWordWrap(True)
|
||||
page.content_layout.addWidget(help_label)
|
||||
return page
|
||||
|
||||
def _create_account_page(self) -> QWidget:
|
||||
@@ -232,8 +255,22 @@ class SettingsPage(QWidget):
|
||||
page = SettingsSubPage(tr("Account"), self._go_back)
|
||||
current = self.settings.get("account", AccountSettings)
|
||||
|
||||
page.content_layout.addWidget(QLabel(tr("Credentials save method")))
|
||||
self.credentials_save_method = self._choice_combo(
|
||||
"account", "credentials_save_method", CREDENTIALS_SAVE_METHODS,
|
||||
current.credentials_save_method,
|
||||
)
|
||||
page.content_layout.addWidget(self.credentials_save_method)
|
||||
|
||||
page.content_layout.addWidget(QLabel(tr("Microsoft OAuth Client ID")))
|
||||
self.client_id_edit = QLineEdit(str(current.client_id))
|
||||
custom_client_id_raw = self.account_mgr.settings_custom_client_id
|
||||
|
||||
if not custom_client_id_raw:
|
||||
custom_client_id = ""
|
||||
else:
|
||||
custom_client_id = custom_client_id_raw
|
||||
|
||||
self.client_id_edit = QLineEdit(str(custom_client_id))
|
||||
self.client_id_edit.setPlaceholderText(
|
||||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
)
|
||||
@@ -245,12 +282,28 @@ 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
|
||||
|
||||
def _create_about_page(self) -> QWidget:
|
||||
tr = self.app.tr_text
|
||||
page = SettingsSubPage(tr("About"), self._go_back)
|
||||
page = SettingsSubPage(tr("About"), self._go_back, expand_content=True)
|
||||
brand_label = QLabel(LAUNCHER_NAME)
|
||||
brand_label.setObjectName("settingsBrand")
|
||||
version_label = QLabel(tr("Version: {version}", version=LAUNCHER_VERSION))
|
||||
@@ -264,12 +317,26 @@ class SettingsPage(QWidget):
|
||||
page.content_layout.addWidget(description)
|
||||
return page
|
||||
|
||||
def _create_log_page(self) -> QWidget:
|
||||
tr = self.app.tr_text
|
||||
page = SettingsSubPage(tr("Log View"), self._go_back, expand_content=True)
|
||||
messages = "\n".join(self.app.log_capture_handler.get_messages())
|
||||
log_text = QPlainTextEdit(messages)
|
||||
log_text.setObjectName("settingsLogText")
|
||||
log_text.setReadOnly(True)
|
||||
self.app.log_capture_handler.emitter.message_emitted.connect(
|
||||
log_text.appendPlainText
|
||||
)
|
||||
log_text.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
|
||||
page.content_layout.addWidget(log_text, 1)
|
||||
return page
|
||||
|
||||
def _choice_combo(
|
||||
self,
|
||||
section: str,
|
||||
field: str,
|
||||
labels: dict[str, str],
|
||||
current: str,
|
||||
self,
|
||||
section: str,
|
||||
field: str,
|
||||
labels: dict[str, str],
|
||||
current: str,
|
||||
) -> QComboBox:
|
||||
combo = QComboBox()
|
||||
for value in self.settings.choices(section, field):
|
||||
@@ -288,16 +355,102 @@ class SettingsPage(QWidget):
|
||||
if not self._settings_dirty:
|
||||
return True
|
||||
|
||||
previous_credentials_method = (
|
||||
self.settings
|
||||
.get("account", AccountSettings)
|
||||
.credentials_save_method # sec
|
||||
)
|
||||
|
||||
previous_token_refresh_interval = (
|
||||
self.settings.get("account", AccountSettings)
|
||||
.token_refresh_interval
|
||||
)
|
||||
|
||||
current_token_refresh_interval = (
|
||||
self.token_refresh_interval.value() * 60 # minutes to seconds
|
||||
)
|
||||
|
||||
selected_credentials_method = (
|
||||
self.credentials_save_method.currentData()
|
||||
)
|
||||
|
||||
credentials_method_changed = (
|
||||
previous_credentials_method
|
||||
!= selected_credentials_method
|
||||
)
|
||||
|
||||
token_refresh_interval_changed = (
|
||||
previous_token_refresh_interval
|
||||
!= current_token_refresh_interval
|
||||
)
|
||||
|
||||
client_id = self.client_id_edit.text().strip()
|
||||
|
||||
try:
|
||||
client_id = uuid.UUID(client_id) if client_id else None
|
||||
except ValueError:
|
||||
if show_error:
|
||||
QMessageBox.warning(
|
||||
self,
|
||||
self.app.tr_text("Invalid Client ID"),
|
||||
self.app.tr_text(
|
||||
"Client ID must be a valid UUID.\n\n"
|
||||
"Example: 12345678-1234-5678-9abc-123456789abc"
|
||||
),
|
||||
)
|
||||
|
||||
self.client_id_edit.setFocus()
|
||||
self.client_id_edit.selectAll()
|
||||
return False
|
||||
|
||||
data = {
|
||||
"general": {"language": self.language_combo.currentData()},
|
||||
"appearance": {"theme": self.theme_combo.currentData()},
|
||||
"account": {"client_id": self.client_id_edit.text().strip()},
|
||||
"account": {"custom_client_id": client_id if client_id else None,
|
||||
"credentials_save_method": selected_credentials_method,
|
||||
"token_refresh_interval":
|
||||
current_token_refresh_interval
|
||||
},
|
||||
}
|
||||
try:
|
||||
self.settings.validate(data)
|
||||
for section, value in data.items():
|
||||
self.settings.set(section, value)
|
||||
self.settings.save()
|
||||
|
||||
# Handle credentials data migration
|
||||
if credentials_method_changed:
|
||||
success, _ = self.account_mgr.reload()
|
||||
|
||||
if not success:
|
||||
# Rollback to previous credentials method if migration failed
|
||||
rollback_account = dict(data["account"])
|
||||
rollback_account["credentials_save_method"] = (
|
||||
previous_credentials_method
|
||||
)
|
||||
|
||||
self.settings.set("account", rollback_account)
|
||||
self.settings.save()
|
||||
|
||||
index = self.credentials_save_method.findData(
|
||||
previous_credentials_method
|
||||
)
|
||||
self.credentials_save_method.setCurrentIndex(index)
|
||||
|
||||
if show_error:
|
||||
QMessageBox.critical(
|
||||
self,
|
||||
self.app.tr_text("Credential migration failed"),
|
||||
self.app.tr_text(
|
||||
"The credential storage method was restored "
|
||||
"to its previous value."
|
||||
),
|
||||
)
|
||||
return False
|
||||
|
||||
# Handle token refresh interval update
|
||||
if token_refresh_interval_changed:
|
||||
self.account_mgr.set_token_refresh_interval(current_token_refresh_interval)
|
||||
except Exception as error:
|
||||
if show_error:
|
||||
QMessageBox.critical(self, self.app.tr_text("Settings error"), str(error))
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "testlauncher"
|
||||
version = "0.0.6a0"
|
||||
version = "0.0.7a0"
|
||||
description = "A lightweight Minecraft launcher."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
@@ -19,12 +19,15 @@ QPushButton#manageProfileItem {
|
||||
}
|
||||
|
||||
QLabel#itemVersion {
|
||||
color: #aeb6c2;
|
||||
color: palette(placeholder-text);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
QPushButton#manageProfileItem:hover { background: palette(midlight); }
|
||||
QPushButton#manageProfileItem:checked { background: #3d6fb4; }
|
||||
QPushButton#manageProfileItem:checked {
|
||||
background: palette(highlight);
|
||||
color: palette(highlighted-text);
|
||||
}
|
||||
|
||||
QLabel#itemName { font-size: 15px; font-weight: 600; }
|
||||
|
||||
|
||||
@@ -9,13 +9,13 @@ QFrame#profileButton:hover {
|
||||
}
|
||||
|
||||
QLabel#profileName, QLabel#itemName {
|
||||
color: #f4f6f8;
|
||||
color: palette(text);
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
QLabel#profileVersion, QLabel#itemVersion {
|
||||
color: #aeb6c2;
|
||||
color: palette(placeholder-text);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ QPushButton#profileItem {
|
||||
}
|
||||
|
||||
QPushButton#profileItem:hover {
|
||||
background: #3d6fb4;
|
||||
background: palette(highlight);
|
||||
color: palette(highlighted-text);
|
||||
}
|
||||
|
||||
QPushButton#launchButton {
|
||||
@@ -54,4 +55,4 @@ QFrame#profileFrame {
|
||||
background-color: palette(base);
|
||||
border: 1px solid palette(mid);
|
||||
border-radius: 10px;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ QToolBar QToolButton:hover {
|
||||
|
||||
QToolBar QPushButton:focus,
|
||||
QToolBar QToolButton:focus {
|
||||
border-bottom: 2px solid #F52761;
|
||||
border-bottom: 2px solid palette(highlight);
|
||||
}
|
||||
|
||||
QToolBar QPushButton:pressed,
|
||||
@@ -97,4 +97,4 @@ QToolBar::handle:top, QToolBar::handle:bottom {
|
||||
|
||||
QToolBar::handle:right, QToolBar::handle:left {
|
||||
border-top: 3px solid palette(midlight);
|
||||
}
|
||||
}
|
||||
@@ -131,7 +131,11 @@
|
||||
"Redownload": "Redownload",
|
||||
"Refresh": "Refresh",
|
||||
"Refresh all": "Refresh all",
|
||||
"Refresh failed": "Refresh failed",
|
||||
"Refresh token": "Refresh token",
|
||||
"Refresh versions": "Refresh versions",
|
||||
"Refreshing…": "Refreshing…",
|
||||
"Reload accounts": "Reload accounts",
|
||||
"Requesting a Microsoft sign-in code…": "Requesting a Microsoft sign-in code…",
|
||||
"Resolution": "Resolution",
|
||||
"Resource Error": "Resource Error",
|
||||
@@ -279,5 +283,28 @@
|
||||
"Log Viewer": "Log Viewer",
|
||||
"Log output saved to {file_name}": "Log output saved to {file_name}",
|
||||
"Unable to save log file: {error}": "Unable to save log file: {error}",
|
||||
"Log truncated at {time}; {count} older lines removed.": "Log truncated at {time}; {count} older lines removed."
|
||||
"Log truncated at {time}; {count} older lines removed.": "Log truncated at {time}; {count} older lines removed.",
|
||||
"Add theme folders containing theme.toml and palette.toml to: {path}": "Add theme folders containing theme.toml and palette.toml to: {path}",
|
||||
"Check failed": "Check failed",
|
||||
"Checking…": "Checking…",
|
||||
"Client ID must be a valid UUID.\n\nExample: 12345678-1234-5678-9abc-123456789abc": "Client ID must be a valid UUID.\n\nExample: 12345678-1234-5678-9abc-123456789abc",
|
||||
"Credential migration failed": "Credential migration failed",
|
||||
"Credentials save method": "Credentials save method",
|
||||
"Custom": "Custom",
|
||||
"Expired": "Expired",
|
||||
"Invalid Client ID": "Invalid Client ID",
|
||||
"Launcher log": "Launcher log",
|
||||
"Log View": "Log View",
|
||||
"Logger": "Logger",
|
||||
"Preparing Microsoft sign-in…": "Preparing Microsoft sign-in…",
|
||||
"Save as a regular file": "Save as a regular file",
|
||||
"Signed in": "Signed in",
|
||||
"The credential storage method was restored to its previous value.": "The credential storage method was restored to its previous value.",
|
||||
"Token refresh check interval": "Token refresh check interval",
|
||||
"Unable to check login status: {error}": "Unable to check login status: {error}",
|
||||
"Use system keyring": "Use system keyring",
|
||||
"Vanilla": "Vanilla",
|
||||
"minutes": "minutes",
|
||||
"{account} is currently signed in.": "{account} is currently signed in.",
|
||||
"{account}'s session has expired.": "{account}'s session has expired."
|
||||
}
|
||||
@@ -130,7 +130,11 @@
|
||||
"Redownload": "重新下載",
|
||||
"Refresh": "重新整理",
|
||||
"Refresh all": "全部重新整理",
|
||||
"Refresh failed": "更新令牌失敗",
|
||||
"Refresh token": "重新整理",
|
||||
"Refresh versions": "重新整理版本",
|
||||
"Refreshing…": "正在更新令牌……",
|
||||
"Reload accounts": "重新載入列表",
|
||||
"Requesting a Microsoft sign-in code…": "正在要求 Microsoft 登入代碼……",
|
||||
"Resolution": "解析度",
|
||||
"Resource Error": "資源錯誤",
|
||||
@@ -279,5 +283,28 @@
|
||||
"Log Viewer": "紀錄檢視器",
|
||||
"Log output saved to {file_name}": "紀錄已儲存至 {file_name}",
|
||||
"Unable to save log file: {error}": "無法儲存紀錄檔:{error}",
|
||||
"Log truncated at {time}; {count} older lines removed.": "紀錄已於 {time} 裁切;已移除較舊的 {count} 行。"
|
||||
"Log truncated at {time}; {count} older lines removed.": "紀錄已於 {time} 裁切;已移除較舊的 {count} 行。",
|
||||
"Add theme folders containing theme.toml and palette.toml to: {path}": "請將包含 theme.toml 與 palette.toml 的主題資料夾放到:{path}",
|
||||
"Check failed": "檢查失敗",
|
||||
"Checking…": "正在檢查……",
|
||||
"Client ID must be a valid UUID.\n\nExample: 12345678-1234-5678-9abc-123456789abc": "Client ID 必須是有效的 UUID。\n\n範例:12345678-1234-5678-9abc-123456789abc",
|
||||
"Credential migration failed": "憑證移轉失敗",
|
||||
"Credentials save method": "憑證儲存方式",
|
||||
"Custom": "自訂",
|
||||
"Expired": "已過期",
|
||||
"Invalid Client ID": "無效的 Client ID",
|
||||
"Launcher log": "啟動器紀錄",
|
||||
"Log View": "紀錄檢視",
|
||||
"Logger": "紀錄",
|
||||
"Preparing Microsoft sign-in…": "正在準備 Microsoft 登入……",
|
||||
"Save as a regular file": "儲存於一般檔案",
|
||||
"Signed in": "已登入",
|
||||
"The credential storage method was restored to its previous value.": "已將憑證儲存方式還原為先前的設定。",
|
||||
"Token refresh check interval": "Token 重新整理檢查間隔",
|
||||
"Unable to check login status: {error}": "無法檢查登入狀態:{error}",
|
||||
"Use system keyring": "使用系統金鑰圈",
|
||||
"Vanilla": "原版",
|
||||
"minutes": "分鐘",
|
||||
"{account} is currently signed in.": "{account} 目前已登入。",
|
||||
"{account}'s session has expired.": "{account} 的工作階段已過期。"
|
||||
}
|
||||
Reference in new issue
Block a user