#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" python3 - "$ROOT_DIR" <<'PY' import re import sys from pathlib import Path root = Path(sys.argv[1]) app_dir = root / "Apptag" preferences = (app_dir / "PreferencesView.swift").read_text(encoding="utf-8") app = (app_dir / "ApptagApp.swift").read_text(encoding="utf-8") def fail(message: str) -> None: raise SystemExit(f"FAIL: {message}") def require(source: str, needle: str, message: str) -> None: if needle not in source: fail(message) require( app, 'window.title = tr("menu.preferences").replacingOccurrences(of: "…", with: "")', "Settings window must use the localized preferences title at creation", ) require( preferences, "private var localizedPreferencesWindowTitle: String", "PreferencesView must have a single localized title source", ) require( preferences, 'tr("menu.preferences").replacingOccurrences(of: "…", with: "")', "PreferencesView localized title must use menu.preferences and strip ellipsis", ) require( preferences, "private func refreshPreferencesWindowTitle()", "PreferencesView must expose a window-title refresh helper", ) require( preferences, "preferencesWindow?.title = localizedPreferencesWindowTitle", "PreferencesView must write the localized title back to NSWindow.title", ) require( preferences, "return window.title == localizedPreferencesWindowTitle", "Preferences window fallback detection must reuse the localized title source", ) language_marker = ".onReceive(NotificationCenter.default.publisher(for: .appLanguageDidChange))" language_start = preferences.find(language_marker) if language_start == -1: fail("PreferencesView must observe appLanguageDidChange") language_end = preferences.find(".onReceive(NotificationCenter.default.publisher(for: .tagLauncherDataDidChange))", language_start) if language_end == -1: fail("PreferencesView appLanguageDidChange handler must be followed by tagLauncherDataDidChange handler") language_block = preferences[language_start:language_end] if "refreshPreferencesWindowTitle()" not in language_block: fail("appLanguageDidChange handler must refresh NSWindow.title") root_frame_marker = ".frame(width: settingsWindowWidth, height: settingsWindowHeight)" root_frame_start = preferences.find(root_frame_marker) if root_frame_start == -1: fail("PreferencesView root frame marker is missing") appear_marker = ".onAppear {" appear_start = preferences.find(appear_marker, root_frame_start) if appear_start == -1: fail("PreferencesView must have an onAppear handler") appear_end = preferences.find(".onDisappear", appear_start) if appear_end == -1: fail("PreferencesView root onAppear must be followed by onDisappear") appear_block = preferences[appear_start:appear_end] if "refreshPreferencesWindowTitle()" not in appear_block: fail("PreferencesView.onAppear must refresh NSWindow.title for restored windows") if "window.title == tr(\"menu.preferences\")" in preferences: fail("PreferencesView must not duplicate raw localized title comparisons") print("PASS Settings language title QA: preferences window title refreshes on appear and language changes") PY