Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

frontend-qt: frameless window, app icon, shell cache, pill buttons, DPI & Windows terms

LNPANDY609f81fc1b46
diff --git a/.github/workflows/build-qt.yml b/.github/workflows/build-qt.yml
index 7c9e7d44..dc409ceb 100644
--- a/.github/workflows/build-qt.yml
+++ b/.github/workflows/build-qt.yml
@@ -99,6 +99,7 @@ jobs:
# directory a windowed build would otherwise miss.
pyinstaller --noconfirm --clean --windowed \
--name "NS Port Builder" \
+ --icon "nspb_qt/assets/app_icon.ico" \
--collect-submodules PySide6.QtCore \
--collect-submodules PySide6.QtGui \
--collect-submodules PySide6.QtWidgets \
diff --git a/frontend-qt/nspb_qt/__main__.py b/frontend-qt/nspb_qt/__main__.py
index 70f73edb..bb35c895 100644
--- a/frontend-qt/nspb_qt/__main__.py
+++ b/frontend-qt/nspb_qt/__main__.py
@@ -2,21 +2,37 @@
from __future__ import annotations
import sys
+from pathlib import Path
from PySide6.QtCore import Qt
-from PySide6.QtGui import QGuiApplication
+from PySide6.QtGui import QGuiApplication, QIcon
from PySide6.QtWidgets import QApplication
from .model import Model
-from .platform_util import hide_console_for_children
+from .platform_util import IS_WIN, hide_console_for_children
from .style import STYLE, load_font
from .ui import MainWindow
+def app_icon() -> QIcon:
+ assets = Path(__file__).resolve().parent / 'assets'
+ for name in ('app_icon.png', 'app_icon.ico'):
+ p = assets / name
+ if p.is_file():
+ return QIcon(str(p))
+ return QIcon()
+
+
def main() -> int:
# Before anything can spawn a child: on Windows every subprocess would otherwise open its own
# console window (see the docstring — this is the "black window, nothing happens" report).
hide_console_for_children()
+ if IS_WIN:
+ try:
+ import ctypes
+ ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('nxnative.nx2apple.launcher')
+ except Exception:
+ pass
# High-DPI: let Qt scale with the screen. On a handheld (a small 720p/800p panel at
# 125-150%) the default policy rounds the scale factor up and the window no longer fits;
# PassThrough honours the system factor as-is and the font sizes below stay in points.
@@ -24,7 +40,10 @@ def main() -> int:
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
app = QApplication(sys.argv)
app.setApplicationName('NS Port Builder')
- app.setApplicationDisplayName('NS Port Builder')
+ app.setApplicationDisplayName('NX2Apple')
+ icon = app_icon()
+ if not icon.isNull():
+ app.setWindowIcon(icon)
app.setStyleSheet(STYLE)
app.setStyle('Fusion') # the same widget look on Windows and macOS
family = load_font() # Manrope, as the Mac launcher; the system font when it cannot load
diff --git a/frontend-qt/nspb_qt/assets/app_icon.ico b/frontend-qt/nspb_qt/assets/app_icon.ico
new file mode 100644
index 00000000..f9ceedbe
Binary files /dev/null and b/frontend-qt/nspb_qt/assets/app_icon.ico differ
diff --git a/frontend-qt/nspb_qt/assets/app_icon.png b/frontend-qt/nspb_qt/assets/app_icon.png
new file mode 100644
index 00000000..04b177d5
Binary files /dev/null and b/frontend-qt/nspb_qt/assets/app_icon.png differ
diff --git a/frontend-qt/nspb_qt/model.py b/frontend-qt/nspb_qt/model.py
index 2e777ef5..8f88100b 100644
--- a/frontend-qt/nspb_qt/model.py
+++ b/frontend-qt/nspb_qt/model.py
@@ -149,7 +149,85 @@ class Model(QObject):
# ---- strings
def t(self, key: str, *args: object) -> str:
- return t(key, self.lang, *args)
+ res = t(key, self.lang, *args)
+ if pu.IS_WIN or getattr(self, 'target_platform', 'ios') == 'ios':
+ if key not in ('build.mac', 'build.macNote', 'target.macDone', 'msg.macAppDone', 'target.tip'):
+ res = (
+ res.replace('在访达中显示', '在文件夹中显示')
+ .replace('在访达里', '在文件夹中')
+ .replace('在访达中', '在文件夹中')
+ .replace('用访达复制', '用文件资源管理器复制')
+ .replace('在访达边栏', '在文件资源管理器')
+ .replace('访达', '文件夹')
+ .replace('此 Mac', '此电脑')
+ .replace('Reveal in Finder', 'Show in folder')
+ .replace('Show in Finder', 'Show in folder')
+ .replace('in the Finder', 'in the folder')
+ .replace('in Finder', 'in folder')
+ .replace('with Finder', 'with File Explorer')
+ .replace('this Mac', 'this PC')
+ .replace('This Mac', 'This PC')
+ )
+ return res
+
+ # ---- shell cache folder (mirrors BuildStore+ShellRoot.swift)
+
+ @staticmethod
+ def default_shell_cache_path() -> str:
+ return str(lib.default_state_dir() / 'shell')
+
+ @property
+ def shell_cache_path(self) -> str:
+ saved = self.settings.value('shellRoot', defaultValue='', type=str)
+ if saved and saved.strip():
+ return saved.strip()
+ return self.default_shell_cache_path()
+
+ @property
+ def shell_cache_is_default(self) -> bool:
+ try:
+ return Path(self.shell_cache_path).resolve() == Path(self.default_shell_cache_path()).resolve()
+ except OSError:
+ return self.shell_cache_path == self.default_shell_cache_path()
+
+ def move_shell_cache(self, target_dir: str, *, exact_dest: bool = False) -> tuple[bool, str]:
+ if self.running:
+ return False, self.t('shellCache.busy')
+ if not target_dir or not target_dir.strip():
+ return False, self.t('shellCache.problem.readOnly')
+ src = Path(self.shell_cache_path)
+ raw_target = Path(target_dir.strip())
+ dst = raw_target if (exact_dest or raw_target.name.lower() == 'shell') else (raw_target / 'shell')
+ try:
+ src_res = src.resolve()
+ dst_res = dst.resolve()
+ except OSError:
+ src_res, dst_res = src, dst
+ if src_res == dst_res:
+ return False, self.t('shellCache.problem.same')
+ if src_res in dst_res.parents:
+ return False, self.t('shellCache.problem.inside')
+ try:
+ if src.exists():
+ if dst.exists() and any(dst.iterdir()):
+ return False, self.t('shellCache.problem.taken')
+ dst.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copytree(src, dst, dirs_exist_ok=True)
+ shutil.rmtree(src, ignore_errors=True)
+ else:
+ dst.mkdir(parents=True, exist_ok=True)
+ except OSError as e:
+ return False, self.t('shellCache.failed', str(e), str(src))
+ default_res = Path(self.default_shell_cache_path()).resolve()
+ if dst_res == default_res:
+ self.settings.setValue('shellRoot', '')
+ else:
+ self.settings.setValue('shellRoot', str(dst))
+ self.repoChanged.emit()
+ return True, self.t('shellCache.moved', str(dst))
+
+ def reset_shell_cache_default(self) -> tuple[bool, str]:
+ return self.move_shell_cache(self.default_shell_cache_path(), exact_dest=True)
def settings_value(self, key: str, default: bool | None = None) -> bool | None:
v = self.settings.value(key, defaultValue='', type=str)
@@ -1490,6 +1568,10 @@ class Model(QObject):
exists = bool(self.mac_app_path) and Path(self.mac_app_path).exists()
self.finished.emit(exists, self.t('target.macDone' if exists else 'target.missingApp'))
elif ok:
+ for st in self.stages:
+ if st.state == 'running':
+ st.state = 'done'
+ self.stagesChanged.emit()
if self.ipa_kind == 'oneGame':
self._record_library_ios_completion()
self.finished.emit(True, self.t('shell.oneGameDone', self.ipa_path))
@@ -1591,6 +1673,10 @@ class Model(QObject):
self.stages[-1].state = 'done'
self.stages.append(Stage(name=name, state='running'))
self.stagesChanged.emit()
+ elif name and '✓' in name:
+ if self.stages and self.stages[-1].state == 'running':
+ self.stages[-1].state = 'done'
+ self.stagesChanged.emit()
def _flush_lines(self) -> None:
self._line_buf = ''
diff --git a/frontend-qt/nspb_qt/style.py b/frontend-qt/nspb_qt/style.py
index 53694ddb..df1789dc 100644
--- a/frontend-qt/nspb_qt/style.py
+++ b/frontend-qt/nspb_qt/style.py
@@ -202,8 +202,9 @@ QPushButton {{
background: rgba(255, 255, 255, 0.08);
color: {TEXT};
border: 1px solid rgba(255, 255, 255, 0.13);
- border-radius: 9px;
- padding: 6px 14px;
+ border-radius: 12px;
+ padding: 6px 16px;
+ min-height: 18px;
font-weight: 600;
font-size: 12.5px;
}}
@@ -222,9 +223,10 @@ QPushButton:disabled {{
QPushButton#creamPill {{
background: {ACCENT};
color: {ACCENT_INK};
- border: none;
- border-radius: 18px;
- padding: 7px 18px;
+ border: 1px solid transparent;
+ border-radius: 14px;
+ padding: 6px 18px;
+ min-height: 20px;
font-size: 13px;
font-weight: 700;
}}
@@ -241,9 +243,10 @@ QPushButton#creamPill:disabled {{
QPushButton#primary {{
background: {ACCENT};
color: {ACCENT_INK};
- border: none;
- border-radius: 22px;
- padding: 11px 26px;
+ border: 1px solid transparent;
+ border-radius: 18px;
+ padding: 10px 26px;
+ min-height: 22px;
font-size: 14px;
font-weight: 700;
}}
@@ -260,9 +263,10 @@ QPushButton#primary:disabled {{
QPushButton#heroPlay {{
background: {ACCENT};
color: {ACCENT_INK};
- border: none;
- border-radius: 25px;
- padding: 12px 28px;
+ border: 1px solid transparent;
+ border-radius: 22px;
+ padding: 10px 28px;
+ min-height: 24px;
font-size: 15px;
font-weight: 800;
}}
@@ -277,8 +281,9 @@ QPushButton#heroSecondary {{
background: rgba(20, 20, 22, 0.72);
color: {TEXT};
border: 1px solid rgba(255, 255, 255, 0.20);
- border-radius: 21px;
- padding: 9px 18px;
+ border-radius: 16px;
+ padding: 7px 18px;
+ min-height: 20px;
font-size: 13px;
font-weight: 600;
}}
@@ -286,6 +291,34 @@ QPushButton#heroSecondary:hover {{
background: rgba(38, 38, 42, 0.88);
border-color: rgba(255, 255, 255, 0.32);
}}
+QPushButton#winCtrlBtn {{
+ background: transparent;
+ color: rgba(255, 255, 255, 0.72);
+ border: none;
+ border-radius: 6px;
+ padding: 0px;
+ min-height: 0px;
+ font-size: 13px;
+ font-weight: 500;
+}}
+QPushButton#winCtrlBtn:hover {{
+ background: rgba(255, 255, 255, 0.12);
+ color: #ffffff;
+}}
+QPushButton#winCloseBtn {{
+ background: transparent;
+ color: rgba(255, 255, 255, 0.72);
+ border: none;
+ border-radius: 6px;
+ padding: 0px;
+ min-height: 0px;
+ font-size: 13px;
+ font-weight: 500;
+}}
+QPushButton#winCloseBtn:hover {{
+ background: #e81123;
+ color: #ffffff;
+}}
QPushButton#danger {{
background: rgba(255, 97, 97, 0.15);
color: {RED};
diff --git a/frontend-qt/nspb_qt/ui.py b/frontend-qt/nspb_qt/ui.py
index e96c3ce7..3be60a73 100644
--- a/frontend-qt/nspb_qt/ui.py
+++ b/frontend-qt/nspb_qt/ui.py
@@ -4,8 +4,8 @@ from __future__ import annotations
import os
from pathlib import Path
-from PySide6.QtCore import QTimer, QUrl, Qt
-from PySide6.QtGui import QDesktopServices, QDragEnterEvent, QDropEvent, QFont
+from PySide6.QtCore import QPoint, QTimer, QUrl, Qt
+from PySide6.QtGui import QDesktopServices, QDragEnterEvent, QDropEvent, QFont, QIcon, QMouseEvent, QPixmap
from PySide6.QtWidgets import (
QApplication,
QComboBox,
@@ -62,6 +62,71 @@ def _set_dot(d: QLabel, color: str) -> None:
d.setStyleSheet(f'background: {color}; border-radius: 4px;')
+class TopBarFrame(QFrame):
+ """Custom frameless top bar that keeps the center navigation tabs pinned at the exact horizontal center
+ and supports dragging / double-clicking to move or maximize the window."""
+
+ def __init__(self, parent: QWidget | None = None) -> None:
+ super().__init__(parent)
+ self.nav_container: QWidget | None = None
+ self.search_box: QLineEdit | None = None
+ self._drag_offset: QPoint | None = None
+
+ def recenter_nav(self) -> None:
+ if self.search_box is not None:
+ sw = max(108, min(172, self.width() - 845))
+ self.search_box.setFixedWidth(sw)
+ if self.nav_container is None:
+ return
+ self.nav_container.adjustSize()
+ nw = self.nav_container.width()
+ nh = self.nav_container.height()
+ x = max(0, (self.width() - nw) // 2)
+ y = max(0, (self.height() - nh) // 2)
+ self.nav_container.setGeometry(x, y, nw, nh)
+ self.nav_container.raise_()
+
+ def resizeEvent(self, event) -> None:
+ super().resizeEvent(event)
+ self.recenter_nav()
+
+ def mousePressEvent(self, event: QMouseEvent) -> None:
+ if event.button() == Qt.LeftButton:
+ win = self.window()
+ wh = win.windowHandle() if win else None
+ if wh is not None and hasattr(wh, 'startSystemMove'):
+ if wh.startSystemMove():
+ event.accept()
+ return
+ if win is not None and not win.isMaximized():
+ self._drag_offset = event.globalPosition().toPoint() - win.frameGeometry().topLeft()
+ event.accept()
+ return
+ super().mousePressEvent(event)
+
+ def mouseMoveEvent(self, event: QMouseEvent) -> None:
+ if self._drag_offset is not None and (event.buttons() & Qt.LeftButton):
+ win = self.window()
+ if win is not None and not win.isMaximized():
+ win.move(event.globalPosition().toPoint() - self._drag_offset)
+ event.accept()
+ return
+ super().mouseMoveEvent(event)
+
+ def mouseReleaseEvent(self, event: QMouseEvent) -> None:
+ self._drag_offset = None
+ super().mouseReleaseEvent(event)
+
+ def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
+ if event.button() == Qt.LeftButton:
+ win = self.window()
+ if hasattr(win, '_toggle_maximize_window'):
+ win._toggle_maximize_window()
+ event.accept()
+ return
+ super().mouseDoubleClickEvent(event)
+
+
class MainWindow(QMainWindow):
def __init__(self, model: Model) -> None:
super().__init__()
@@ -71,6 +136,15 @@ class MainWindow(QMainWindow):
)
self.m.ask_file = self._ask_metal_archive
self.setWindowTitle(f'NX2Apple v{APP_VERSION}')
+ self.setWindowFlags(
+ Qt.Window
+ | Qt.FramelessWindowHint
+ | Qt.WindowSystemMenuHint
+ | Qt.WindowMinMaxButtonsHint
+ )
+ icon_file = Path(__file__).resolve().parent / 'assets' / 'app_icon.png'
+ if icon_file.is_file():
+ self.setWindowIcon(QIcon(str(icon_file)))
self.resize(1080, 800)
self.setMinimumSize(820, 440)
self.setAcceptDrops(True)
@@ -91,7 +165,7 @@ class MainWindow(QMainWindow):
root_col.setContentsMargins(0, 0, 0, 0)
root_col.setSpacing(0)
- # 1. Top Navigation Bar (64px)
+ # 1. Top Navigation Bar (64px, frameless with built-in Min/Max/Close & centered nav)
self.top_bar = self._build_top_bar()
root_col.addWidget(self.top_bar)
@@ -99,9 +173,9 @@ class MainWindow(QMainWindow):
self.engine_banner = self._build_engine_banner()
root_col.addWidget(self.engine_banner)
- # 3. Main Stacked Pages
- # `self.scroll` is the ONLY QScrollArea in MainWindow (hosting both Builds and Settings
- # containers), so `w.findChild(QScrollArea)` always returns `self.scroll`.
+ # 3. Main Scrollable Workspace
+ # `self.scroll` is the ONLY QScrollArea in MainWindow (hosting Library, Builds and Settings),
+ # so `w.findChild(QScrollArea)` always returns `self.scroll`, and Library scrolls cleanly at high DPI.
self.stack = QStackedWidget()
self.scroll = QScrollArea()
self.scroll.setWidgetResizable(True)
@@ -111,16 +185,15 @@ class MainWindow(QMainWindow):
self.scroll_col.setContentsMargins(0, 0, 0, 0)
self.scroll_col.setSpacing(0)
+ self.library_page = self._build_library_page()
self.builds_page = self._build_builds_page()
self.settings_page = self._build_settings_page()
+ self.scroll_col.addWidget(self.library_page, 1)
self.scroll_col.addWidget(self.builds_page)
self.scroll_col.addWidget(self.settings_page)
self.scroll.setWidget(scroll_body)
- self.library_page = self._build_library_page()
-
- self.stack.addWidget(self.scroll) # index 0: Scrollable workspace (Builds / Settings)
- self.stack.addWidget(self.library_page) # index 1: Full-bleed Library showcase
+ self.stack.addWidget(self.scroll)
root_col.addWidget(self.stack, 1)
# 4. Bottom Global Activity Bar
@@ -154,21 +227,39 @@ class MainWindow(QMainWindow):
self._init_timer.timeout.connect(self.m.check_deps)
self._init_timer.start(50)
- # ================================================================ Top Bar
+ # ================================================================ Top Bar & Window Controls
- def _build_top_bar(self) -> QFrame:
- bar = QFrame()
+ def _toggle_maximize_window(self) -> None:
+ if self.isMaximized():
+ self.showNormal()
+ self.max_win_btn.setText('□')
+ else:
+ self.showMaximized()
+ self.max_win_btn.setText('❐')
+
+ def _build_top_bar(self) -> TopBarFrame:
+ bar = TopBarFrame()
bar.setObjectName('topBar')
bar.setFixedHeight(64)
row = QHBoxLayout(bar)
- row.setContentsMargins(28, 0, 28, 0)
- row.setSpacing(12)
+ row.setContentsMargins(24, 0, 16, 0)
+ row.setSpacing(10)
- # Brand
+ # Brand (App Icon + NX2Apple — by nxnative)
brand_row = QHBoxLayout()
- brand_row.setSpacing(8)
+ brand_row.setSpacing(10)
+ self.app_icon_lbl = QLabel()
+ self.app_icon_lbl.setFixedSize(26, 26)
+ icon_file = Path(__file__).resolve().parent / 'assets' / 'app_icon.png'
+ if icon_file.is_file():
+ pm = QPixmap(str(icon_file))
+ if not pm.isNull():
+ self.app_icon_lbl.setPixmap(
+ pm.scaled(26, 26, Qt.KeepAspectRatio, Qt.SmoothTransformation)
+ )
+ brand_row.addWidget(self.app_icon_lbl)
self.title_label = QLabel('NX2Apple')
- self.title_label.setStyleSheet('font-size: 24px; font-weight: 800; color: #ffffff;')
+ self.title_label.setStyleSheet('font-size: 23px; font-weight: 800; color: #ffffff;')
self.sub_label = QLabel('— by nxnative')
self.sub_label.setObjectName('faint')
brand_row.addWidget(self.title_label)
@@ -177,8 +268,10 @@ class MainWindow(QMainWindow):
row.addStretch(1)
- # Navigation tabs: Library / Builds / Settings
- nav_wrap = QHBoxLayout()
+ # Pinned-center Navigation tabs: Library / Builds / Settings
+ nav_host = QWidget(bar)
+ nav_wrap = QHBoxLayout(nav_host)
+ nav_wrap.setContentsMargins(0, 0, 0, 0)
nav_wrap.setSpacing(4)
self.nav_btns: dict[str, QPushButton] = {}
for page_id in ('library', 'builds', 'settings'):
@@ -187,17 +280,17 @@ class MainWindow(QMainWindow):
btn.clicked.connect(lambda _=False, p=page_id: self._switch_page(p))
self.nav_btns[page_id] = btn
nav_wrap.addWidget(btn)
- row.addLayout(nav_wrap)
-
- row.addStretch(1)
+ bar.nav_container = nav_host
+ bar.recenter_nav()
- # Trailing controls: Search input + New Build + Update pill + Language toggle
+ # Trailing controls: Search input + New Build + Update pill + Window controls (Min/Max/Close)
self.search_input = QLineEdit()
self.search_input.setObjectName('searchField')
self.search_input.setPlaceholderText(self.m.t('library.search'))
- self.search_input.setFixedWidth(180)
+ self.search_input.setFixedWidth(172)
self.search_input.setClearButtonEnabled(True)
self.search_input.textChanged.connect(self._on_search_changed)
+ bar.search_box = self.search_input
row.addWidget(self.search_input)
self.new_build_btn = QPushButton('+ ' + self.m.t('library.newBuild'))
@@ -215,23 +308,50 @@ class MainWindow(QMainWindow):
self.lang_btn.clicked.connect(self.m.toggle_lang)
self.lang_btn.hide() # Language selection lives in Settings -> App -> Language, matching the Mac SwiftUI top bar
+ # Built-in Frameless Window Controls (Minimize / Maximize / Close)
+ win_ctrl_wrap = QHBoxLayout()
+ win_ctrl_wrap.setContentsMargins(6, 0, 0, 0)
+ win_ctrl_wrap.setSpacing(2)
+
+ self.min_win_btn = QPushButton('—')
+ self.min_win_btn.setObjectName('winCtrlBtn')
+ self.min_win_btn.setFixedSize(36, 28)
+ self.min_win_btn.setCursor(Qt.PointingHandCursor)
+ self.min_win_btn.clicked.connect(self.showMinimized)
+ win_ctrl_wrap.addWidget(self.min_win_btn)
+
+ self.max_win_btn = QPushButton('□')
+ self.max_win_btn.setObjectName('winCtrlBtn')
+ self.max_win_btn.setFixedSize(36, 28)
+ self.max_win_btn.setCursor(Qt.PointingHandCursor)
+ self.max_win_btn.clicked.connect(self._toggle_maximize_window)
+ win_ctrl_wrap.addWidget(self.max_win_btn)
+
+ self.close_win_btn = QPushButton('✕')
+ self.close_win_btn.setObjectName('winCloseBtn')
+ self.close_win_btn.setFixedSize(36, 28)
+ self.close_win_btn.setCursor(Qt.PointingHandCursor)
+ self.close_win_btn.clicked.connect(self.close)
+ win_ctrl_wrap.addWidget(self.close_win_btn)
+
+ row.addLayout(win_ctrl_wrap)
+
return bar
def _switch_page(self, page_id: str) -> None:
self._current_page = page_id
- if page_id == 'library':
- self.stack.setCurrentIndex(1)
- else:
- self.builds_page.setVisible(page_id == 'builds')
- self.settings_page.setVisible(page_id == 'settings')
- self.stack.setCurrentIndex(0)
- self.scroll.verticalScrollBar().setValue(0)
+ self.library_page.setVisible(page_id == 'library')
+ self.builds_page.setVisible(page_id == 'builds')
+ self.settings_page.setVisible(page_id == 'settings')
+ self.stack.setCurrentIndex(0)
+ self.scroll.verticalScrollBar().setValue(0)
for pid, btn in self.nav_btns.items():
btn.setObjectName('navTabActive' if pid == page_id else 'navTab')
btn.style().unpolish(btn)
btn.style().polish(btn)
self.search_input.setVisible(page_id == 'library')
self.new_build_btn.setVisible(page_id != 'builds')
+ self.top_bar.recenter_nav()
if page_id == 'library':
self._refresh_library()
@@ -477,8 +597,11 @@ class MainWindow(QMainWindow):
# Rebuild horizontal strip
while self.coll_strip_layout.count():
it = self.coll_strip_layout.takeAt(0)
- if it.widget():
- it.widget().deleteLater()
+ w_old = it.widget()
+ if w_old:
+ w_old.hide()
+ w_old.setParent(None)
+ w_old.deleteLater()
if not filtered:
no_lbl = QLabel(self.m.t('library.noResults'))
@@ -931,6 +1054,7 @@ class MainWindow(QMainWindow):
r_s1 = QWidget()
rs1_lay = QHBoxLayout(r_s1)
rs1_lay.setContentsMargins(18, 11, 18, 11)
+ rs1_lay.setSpacing(10)
s1_col = QVBoxLayout()
self.step1_title = QLabel('① ' + self.m.t('shell.step1Title'))
self.step1_title.setObjectName('rowTitle')
@@ -940,6 +1064,11 @@ class MainWindow(QMainWindow):
s1_col.addWidget(self.step1_title)
s1_col.addWidget(self.step1_sub)
rs1_lay.addLayout(s1_col, 1)
+
+ self.step1_reveal_btn = QPushButton(self.m.t('shell.showInFinder'))
+ self.step1_reveal_btn.clicked.connect(lambda: pu.reveal(self.m.ipa_path))
+ self.step1_reveal_btn.hide()
+ rs1_lay.addWidget(self.step1_reveal_btn)
grp.add_row(r_s1)
grp.add_divider()
@@ -970,15 +1099,25 @@ class MainWindow(QMainWindow):
rs3_lay.setContentsMargins(18, 11, 18, 11)
rs3_lay.setSpacing(10)
s3_col = QVBoxLayout()
+ s3_col.setSpacing(3)
self.step3_title = QLabel('③ ' + self.m.t('shell.step3Title') + ' · ' + self.m.t('shell.whereDrive'))
self.step3_title.setObjectName('rowTitle')
+ self.drive_path_lbl = QLabel(self.m.t('shell.driveNone'))
+ self.drive_path_lbl.setObjectName('mono')
+ self.drive_path_lbl.setWordWrap(True)
self.step3_sub = QLabel(self.m.t('shell.copyExternalNote'))
self.step3_sub.setObjectName('muted')
self.step3_sub.setWordWrap(True)
s3_col.addWidget(self.step3_title)
+ s3_col.addWidget(self.drive_path_lbl)
s3_col.addWidget(self.step3_sub)
rs3_lay.addLayout(s3_col, 1)
+ self.step3_open_romfs_btn = QPushButton(self.m.t('shell.showInFinder'))
+ self.step3_open_romfs_btn.clicked.connect(lambda: pu.reveal(self.m.archive_path))
+ self.step3_open_romfs_btn.hide()
+ rs3_lay.addWidget(self.step3_open_romfs_btn)
+
self.drive_choose_btn = QPushButton(self.m.t('shell.driveChoose'))
self.drive_choose_btn.clicked.connect(self._pick_drive_folder)
rs3_lay.addWidget(self.drive_choose_btn)
@@ -1010,25 +1149,37 @@ class MainWindow(QMainWindow):
self.ipa_kind_note.setText(self.m.t('shell.ipaOneGameNote' if one else 'shell.ipaSharedNote'))
self.step1_title.setText('① ' + self.m.t('shell.step1Title'))
self.step1_sub.setText(self.m.t('shell.oneGameSub' if one else 'shell.step1Sub'))
+ has_ipa = bool(self.m.ipa_path and os.path.exists(self.m.ipa_path))
+ self.step1_reveal_btn.setText(self.m.t('shell.showInFinder'))
+ self.step1_reveal_btn.setVisible(has_ipa)
self.step2_title.setText('② ' + self.m.t('shell.step2Title'))
self.step2_sub.setText(self.m.t('shell.oneGameStep2Sub' if one else 'shell.step2Sub'))
self.step3_title.setText('③ ' + self.m.t('shell.step3Title') + ' · ' + self.m.t('shell.whereDrive'))
+ self.drive_path_lbl.setText(self._drive_folder or self.m.t('shell.driveNone'))
+ self.step3_open_romfs_btn.setText(self.m.t('shell.showInFinder'))
self.drive_choose_btn.setText(self.m.t('shell.driveChoose'))
self.drive_copy_btn.setText(self.m.t('shell.driveCopy'))
self.step3_container.setVisible(not one)
has_arch = bool(self.m.archive_path and os.path.isdir(self.m.archive_path))
- self.drive_copy_btn.setEnabled(has_arch and bool(self._drive_folder))
+ self.step3_open_romfs_btn.setVisible(has_arch)
+ self.drive_copy_btn.setEnabled(has_arch)
def _pick_drive_folder(self) -> None:
d = QFileDialog.getExistingDirectory(self, self.m.t('shell.driveChoose'), self._drive_folder or str(Path.home()))
if d:
self._drive_folder = d
- self.step3_sub.setText(d)
+ self.drive_path_lbl.setText(d)
self._refresh_install_card()
def _copy_archive_to_drive(self) -> None:
- if not self.m.archive_path or not self._drive_folder:
+ if not self.m.archive_path or not os.path.isdir(self.m.archive_path):
return
+ if not self._drive_folder:
+ d = QFileDialog.getExistingDirectory(self, self.m.t('shell.driveChoose'), str(Path.home()))
+ if not d:
+ return
+ self._drive_folder = d
+ self.drive_path_lbl.setText(d)
tid = self.m.build_key
ok, info = lib.DriveCopy.copy_to_folder(self.m.archive_path, self._drive_folder, tid)
if ok:
@@ -1055,12 +1206,12 @@ class MainWindow(QMainWindow):
self.footer.setTextInteractionFlags(Qt.TextSelectableByMouse)
act.addWidget(self.footer, 1)
- self.reveal_ipa_btn = QPushButton('IPA')
+ self.reveal_ipa_btn = QPushButton(f"{self.m.t('shell.showInFinder')} (IPA)")
self.reveal_ipa_btn.clicked.connect(lambda: pu.reveal(self.m.ipa_path))
self.reveal_ipa_btn.hide()
act.addWidget(self.reveal_ipa_btn)
- self.reveal_arc_btn = QPushButton('romfs.img')
+ self.reveal_arc_btn = QPushButton(f"{self.m.t('shell.showInFinder')} (romfs)")
self.reveal_arc_btn.clicked.connect(lambda: pu.reveal(self.m.archive_path))
self.reveal_arc_btn.hide()
act.addWidget(self.reveal_arc_btn)
@@ -1297,6 +1448,48 @@ class MainWindow(QMainWindow):
grp.add_row(r_deps)
grp.add_divider()
+ # Row 2.5: Shell Cache Folder (mirrors ShellCacheRow.swift)
+ r_cache = QWidget()
+ rc_lay = QHBoxLayout(r_cache)
+ rc_lay.setContentsMargins(18, 12, 18, 12)
+ rc_lay.setSpacing(12)
+ self.cache_dot = _dot(style.GREEN)
+ rc_lay.addWidget(self.cache_dot)
+ ccol = QVBoxLayout()
+ ccol.setSpacing(2)
+ self.cache_title_lbl = QLabel(self.m.t('shellCache.row'))
+ self.cache_title_lbl.setObjectName('rowTitle')
+ self.cache_path_lbl = QLabel(self.m.shell_cache_path)
+ self.cache_path_lbl.setObjectName('mono')
+ self.cache_path_lbl.setWordWrap(True)
+ self.cache_note_lbl = QLabel(self.m.t('shellCache.note'))
+ self.cache_note_lbl.setObjectName('muted')
+ self.cache_note_lbl.setWordWrap(True)
+ self.cache_status_lbl = QLabel('')
+ self.cache_status_lbl.setObjectName('muted')
+ self.cache_status_lbl.setWordWrap(True)
+ self.cache_status_lbl.hide()
+ ccol.addWidget(self.cache_title_lbl)
+ ccol.addWidget(self.cache_path_lbl)
+ ccol.addWidget(self.cache_note_lbl)
+ ccol.addWidget(self.cache_status_lbl)
+ rc_lay.addLayout(ccol, 1)
+
+ self.cache_open_btn = QPushButton(self.m.t('shellCache.open'))
+ self.cache_open_btn.clicked.connect(self._open_shell_cache)
+ rc_lay.addWidget(self.cache_open_btn)
+
+ self.cache_move_btn = QPushButton(self.m.t('shellCache.move'))
+ self.cache_move_btn.clicked.connect(self._move_shell_cache)
+ rc_lay.addWidget(self.cache_move_btn)
+
+ self.cache_default_btn = QPushButton(self.m.t('shellCache.useDefault'))
+ self.cache_default_btn.clicked.connect(self._reset_shell_cache)
+ self.cache_default_btn.setVisible(not self.m.shell_cache_is_default)
+ rc_lay.addWidget(self.cache_default_btn)
+ grp.add_row(r_cache)
+ grp.add_divider()
+
# Row 3: Copy Diagnostics (diag.title / diag.copy)
r_diag = QWidget()
rd_lay = QHBoxLayout(r_diag)
@@ -1321,6 +1514,39 @@ class MainWindow(QMainWindow):
return grp
+ def _open_shell_cache(self) -> None:
+ p = Path(self.m.shell_cache_path)
+ try:
+ p.mkdir(parents=True, exist_ok=True)
+ except OSError:
+ pass
+ pu.reveal(str(p))
+
+ def _move_shell_cache(self) -> None:
+ d = QFileDialog.getExistingDirectory(
+ self,
+ self.m.t('shellCache.pickMessage'),
+ str(Path(self.m.shell_cache_path).parent),
+ )
+ if not d:
+ return
+ ok, msg = self.m.move_shell_cache(d)
+ self.cache_status_lbl.setText(msg)
+ self.cache_status_lbl.setStyleSheet(
+ f'color: {style.GREEN if ok else style.AMBER}; font-size: 12px;'
+ )
+ self.cache_status_lbl.show()
+ self._refresh_all()
+
+ def _reset_shell_cache(self) -> None:
+ ok, msg = self.m.reset_shell_cache_default()
+ self.cache_status_lbl.setText(msg)
+ self.cache_status_lbl.setStyleSheet(
+ f'color: {style.GREEN if ok else style.AMBER}; font-size: 12px;'
+ )
+ self.cache_status_lbl.show()
+ self._refresh_all()
+
def _copy_diagnostics(self) -> None:
report = feat.Diagnostics.format_report(
app_version=APP_VERSION,
@@ -1556,9 +1782,19 @@ class MainWindow(QMainWindow):
self.recheck_btn.setText(t('dep.recheck'))
self.deps_toggle_btn.setText(t('dep.hide' if self._deps_expanded else 'dep.show'))
self.install_all_btn.setText(t('dep.installAll'))
+ self.cache_title_lbl.setText(t('shellCache.row'))
+ self.cache_path_lbl.setText(self.m.shell_cache_path)
+ self.cache_note_lbl.setText(t('shellCache.note'))
+ self.cache_open_btn.setText(t('shellCache.open'))
+ self.cache_move_btn.setText(t('shellCache.move'))
+ self.cache_default_btn.setText(t('shellCache.useDefault'))
+ self.cache_default_btn.setVisible(not self.m.shell_cache_is_default)
self.diag_title_lbl.setText(t('diag.title'))
self.diag_note_lbl.setText(t('diag.note'))
self.diag_btn.setText(t('diag.copy'))
+ self.reveal_ipa_btn.setText(f"{t('shell.showInFinder')} (IPA)")
+ self.reveal_arc_btn.setText(f"{t('shell.showInFinder')} (romfs)")
+ self.top_bar.recenter_nav()
self.app_group.set_title(t('section.app'))
self.app_lang_lbl.setText(t('settings.language'))
@@ -2109,9 +2345,32 @@ class MainWindow(QMainWindow):
def resizeEvent(self, event) -> None:
super().resizeEvent(event)
+ if hasattr(self, 'top_bar'):
+ self.top_bar.recenter_nav()
if hasattr(self, 'drop_overlay') and self.centralWidget():
self.drop_overlay.setGeometry(self.centralWidget().rect())
+ def mousePressEvent(self, event: QMouseEvent) -> None:
+ if event.button() == Qt.LeftButton and not self.isMaximized():
+ pos = event.position().toPoint()
+ margin = 6
+ edges = Qt.Edges()
+ if pos.x() <= margin:
+ edges |= Qt.LeftEdge
+ elif pos.x() >= self.width() - margin:
+ edges |= Qt.RightEdge
+ if pos.y() <= margin:
+ edges |= Qt.TopEdge
+ elif pos.y() >= self.height() - margin:
+ edges |= Qt.BottomEdge
+ if edges:
+ wh = self.windowHandle()
+ if wh is not None and hasattr(wh, 'startSystemResize'):
+ if wh.startSystemResize(edges):
+ event.accept()
+ return
+ super().mousePressEvent(event)
+
def dragEnterEvent(self, event: QDragEnterEvent) -> None:
if event.mimeData().hasUrls():
event.acceptProposedAction()
diff --git a/frontend-qt/nspb_qt/widgets.py b/frontend-qt/nspb_qt/widgets.py
index 9d5ab37e..6b21fef5 100644
--- a/frontend-qt/nspb_qt/widgets.py
+++ b/frontend-qt/nspb_qt/widgets.py
@@ -109,12 +109,14 @@ class LauncherSegmented(QWidget):
"""Capsule segmented control matching SwiftUI's LauncherSegmented (cream active pill)."""
changed = Signal(str)
+ _PAD = 4.0
+ _GAP = 6.0
def __init__(self, items: list[tuple[str, str]] | None = None, selected: str = '', parent: QWidget | None = None) -> None:
super().__init__(parent)
self._items: list[tuple[str, str]] = list(items or [])
self._selected = selected or (self._items[0][0] if self._items else '')
- self.setFixedHeight(34)
+ self.setFixedHeight(36)
self.setCursor(Qt.PointingHandCursor)
self._recalc_width()
@@ -135,27 +137,59 @@ class LauncherSegmented(QWidget):
self._selected = key
self.update()
- def _recalc_width(self) -> None:
- fm = QFontMetrics(self.font())
- total = 8
+ def _measure_segments(self) -> tuple[list[float], float]:
+ f = QFont(self.font())
+ if f.pointSize() <= 0 and f.pixelSize() <= 0:
+ f.setPixelSize(13)
+ f.setBold(True)
+ fm = QFontMetrics(f)
+ widths: list[float] = []
for _, label in self._items:
- total += max(68, fm.horizontalAdvance(label) + 28)
- self.setFixedWidth(max(120, total))
+ widths.append(max(68.0, float(fm.horizontalAdvance(label) + 34)))
+ if not widths:
+ return [], 120.0
+ total = self._PAD * 2.0 + sum(widths) + self._GAP * max(0, len(widths) - 1)
+ return widths, max(120.0, total)
+
+ def _recalc_width(self) -> None:
+ _, total = self._measure_segments()
+ self.setFixedWidth(int(total + 0.5))
+
+ def _segment_rects(self) -> list[tuple[str, str, QRectF]]:
+ widths, total = self._measure_segments()
+ if not widths:
+ return []
+ extra = max(0.0, float(self.width()) - total) / len(widths)
+ x = self._PAD
+ h = float(self.height()) - self._PAD * 2.0
+ out: list[tuple[str, str, QRectF]] = []
+ for (key, label), w in zip(self._items, widths):
+ seg_w = w + extra
+ out.append((key, label, QRectF(x, self._PAD, seg_w, h)))
+ x += seg_w + self._GAP
+ return out
def mouseReleaseEvent(self, event: QMouseEvent) -> None:
if event.button() != Qt.LeftButton or not self.isEnabled() or not self._items:
return
- n = len(self._items)
- seg_w = (self.width() - 6.0) / n
- idx = int((event.position().x() - 3.0) // seg_w)
- idx = max(0, min(n - 1, idx))
- key = self._items[idx][0]
- if key != self._selected:
- self._selected = key
+ px = float(event.position().x())
+ rects = self._segment_rects()
+ chosen_key = None
+ for key, _label, r in rects:
+ if r.left() - self._GAP / 2.0 <= px <= r.right() + self._GAP / 2.0:
+ chosen_key = key
+ break
+ if chosen_key is None and rects:
+ chosen_key = rects[0][0] if px < rects[0][2].left() else rects[-1][0]
+ if chosen_key and chosen_key != self._selected:
+ self._selected = chosen_key
self.update()
- self.changed.emit(key)
+ self.changed.emit(chosen_key)
def paintEvent(self, _event) -> None:
+ _, needed = self._measure_segments()
+ if abs(self.width() - int(needed + 0.5)) > 2:
+ self.setFixedWidth(int(needed + 0.5))
p = QPainter(self)
p.setRenderHint(QPainter.Antialiasing)
outer = QRectF(0.5, 0.5, self.width() - 1.0, self.height() - 1.0)
@@ -163,12 +197,7 @@ class LauncherSegmented(QWidget):
p.setBrush(QColor(255, 255, 255, 13))
p.drawRoundedRect(outer, outer.height() / 2.0, outer.height() / 2.0)
- if not self._items:
- return
- n = len(self._items)
- seg_w = (self.width() - 6.0) / n
- for i, (key, label) in enumerate(self._items):
- r = QRectF(3.0 + i * seg_w, 3.0, seg_w, self.height() - 6.0)
+ for key, label, r in self._segment_rects():
active = key == self._selected
if active:
p.setPen(Qt.NoPen)
@@ -292,8 +321,8 @@ class HeroBannerWidget(QWidget):
def __init__(self, parent: QWidget | None = None) -> None:
super().__init__(parent)
- self.setMinimumHeight(330)
- self.setMaximumHeight(410)
+ self.setMinimumHeight(250)
+ self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._pixmap: QPixmap | None = None
self._image_path: str = ''
self._title_id: str = ''
diff --git a/frontend-qt/tests/test_swift_parity.py b/frontend-qt/tests/test_swift_parity.py
index 14b611d6..ee9a9009 100644
--- a/frontend-qt/tests/test_swift_parity.py
+++ b/frontend-qt/tests/test_swift_parity.py
@@ -272,6 +272,102 @@ class ParityWindowTests(unittest.TestCase):
self.assertTrue((build_app.SDK_COMPAT / 'MetalFX' / 'MetalFX.h').is_file())
self.assertTrue((build_app.SDK_COMPAT / 'CoreMotion' / 'CoreMotion.h').is_file())
+ def test_ten_point_ui_and_ux_refinements(self) -> None:
+ from unittest import mock
+ from PySide6.QtCore import Qt
+ from nspb_qt.model import Model
+ from nspb_qt.ui import MainWindow
+
+ p = mock.patch.object(Model, 'check_deps', lambda self: None)
+ p.start()
+ self.addCleanup(p.stop)
+
+ with tempfile.TemporaryDirectory() as td:
+ td_path = Path(td)
+ m = Model()
+ m.lang = Lang('zh')
+ w = MainWindow(m)
+ self.addCleanup(self._delete, m, w)
+ w.resize(1120, 780)
+ w.show()
+ self.app.processEvents()
+
+ # 1. Center navigation stays pinned at horizontal center across page switches
+ centers = []
+ for page_id in ('library', 'builds', 'settings'):
+ w._switch_page(page_id)
+ self.app.processEvents()
+ nav_center = w.top_bar.nav_container.geometry().center().x()
+ bar_center = w.top_bar.width() // 2
+ self.assertLessEqual(abs(nav_center - bar_center), 2)
+ centers.append(nav_center)
+ self.assertEqual(len(set(centers)), 1, f'nav center jumped across pages: {centers}')
+
+ # 2 & 3. Frameless window + built-in Min/Max/Close + synced AppIcon
+ self.assertTrue(bool(w.windowFlags() & Qt.FramelessWindowHint))
+ self.assertFalse(w.min_win_btn.isHidden())
+ self.assertFalse(w.max_win_btn.isHidden())
+ self.assertFalse(w.close_win_btn.isHidden())
+ assets_dir = Path(ROOT / 'frontend-qt' / 'nspb_qt' / 'assets')
+ self.assertTrue((assets_dir / 'app_icon.png').is_file())
+ self.assertTrue((assets_dir / 'app_icon.ico').is_file())
+ self.assertFalse(w.windowIcon().isNull())
+
+ # 4. Shell cache setting row in Settings -> Build Tools
+ self.assertEqual(w.cache_title_lbl.text(), '缓存文件')
+ new_cache_parent = td_path / 'custom_cache_parent'
+ new_cache_parent.mkdir()
+ ok_move, _ = m.move_shell_cache(str(new_cache_parent))
+ self.assertTrue(ok_move)
+ self.assertFalse(m.shell_cache_is_default)
+ self.assertEqual(Path(m.shell_cache_path).resolve(), (new_cache_parent / 'shell').resolve())
+ ok_reset, _ = m.reset_shell_cache_default()
+ self.assertTrue(ok_reset)
+ self.assertTrue(m.shell_cache_is_default)
+
+ # 5 & 7. Segmented control non-overlapping segments with gap >= 5px
+ rects = w.ipa_kind_seg._segment_rects()
+ self.assertEqual(len(rects), 2)
+ r0, r1 = rects[0][2], rects[1][2]
+ self.assertGreaterEqual(r1.left() - r0.right(), 5.0)
+
+ # 6. Step 1 & Step 3 reveal buttons + Copy game data button enabled when archive exists
+ fake_ipa = td_path / '0100E65002BB8000.ipa'
+ fake_ipa.write_bytes(b'PK\x03\x04')
+ fake_romfs = td_path / 'romfs'
+ fake_romfs.mkdir()
+ (fake_romfs / 'romfs.img').write_bytes(b'DMROMFS1')
+ m.ipa_path = str(fake_ipa)
+ m.archive_path = str(fake_romfs)
+ w._switch_page('builds')
+ w._refresh_install_card()
+ w._on_finished(True, '')
+ self.assertFalse(w.step1_reveal_btn.isHidden())
+ self.assertFalse(w.step3_open_romfs_btn.isHidden())
+ self.assertTrue(w.drive_copy_btn.isEnabled())
+ self.assertIn('在文件夹中显示', w.reveal_ipa_btn.text())
+ self.assertIn('在文件夹中显示', w.reveal_arc_btn.text())
+
+ # 8. Stage completion marks running stage 'done' (green) instead of staying 'running' (orange)
+ m.stages.clear()
+ m._on_line('[17:20:01] [6/7] app build')
+ self.assertEqual(m.stages[-1].state, 'running')
+ m._on_line('[17:20:15] [6/7] app build ✓ (14.0s)')
+ self.assertEqual(m.stages[-1].state, 'done')
+
+ # 9. HeroBannerWidget has no 410px max-height cap, and library_page is hosted inside scroll
+ self.assertGreater(w.hero.maximumHeight(), 2000)
+ self.assertTrue(w.scroll.widget().isAncestorOf(w.library_page))
+
+ # 10. Windows terminology replaces "访达" and "此 Mac"
+ self.assertEqual(m.t('install.reveal'), '在文件夹中显示')
+ self.assertEqual(m.t('shell.showInFinder'), '在文件夹中显示')
+ self.assertIn('此电脑', m.t('shell.copyExternalNote'))
+ self.assertNotIn('访达', m.t('shell.showInFinder'))
+ m.lang = Lang('en')
+ self.assertEqual(m.t('install.reveal'), 'Show in folder')
+ self.assertIn('this PC', m.t('shell.copyExternalNote'))
+
if __name__ == '__main__':
unittest.main()