Skip to content

Словари не находятся при сборке на новом Swift (6.4): .bin кладутся в корень бандла, а не в Contents/Resources #14

Open

Description

@8ui

Кратко

Со свежим Swift scripts/build-app.sh копирует скомпилированные словари *.bin в корень SwitchFix_Dictionary.bundle. Но SwiftPM теперь собирает бандл по макОС-схеме (Contents/Resources/), а Bundle.url(forResource:) ищет только в Contents/Resources. В итоге ни один словарь не находится, и ничего не исправляется ни в автоматическом режиме, ни по хоткею.

Окружение

  • SwitchFix v0.0.9 (d31f7b6), собран из исходников через ./install.sh
  • macOS 27.0, Apple Silicon (arm64)
  • Xcode 27.0, Apple Swift 6.4 (swiftlang-6.4.0.34.1)

Симптомы

Приложение запускается, event tap активен, хоткей ловится, но исправлений нет. Лог:

[com.switchfix:dictionary] [SwitchFix] missing or invalid binary resource for ru_RU
[com.switchfix:dictionary] [SwitchFix] ru_RU unavailable; automatic correction target disabled
[com.switchfix:dictionary] [SwitchFix] missing or invalid binary resource for en_US
[com.switchfix:detector]   [SwitchFix] detect 'ghbdtn' -> keep (no correction, ms=0.254042)

Что получается внутри бандла:

SwitchFix_Dictionary.bundle/
├── en_US.bin          <- сюда их кладёт build-app.sh
├── ru_RU.bin
├── uk_UA.bin
└── Contents/
    ├── Info.plist
    └── Resources/     <- а Bundle.url(forResource:) ищет здесь
        ├── en_US.txt  <- и текстовые фолбэки тоже не удаляются
        ├── ru_RU.txt
        ├── uk_UA.txt
        └── overrides/

Исправление

Если у бандла есть Contents/Resources, класть бинарники туда. Для старых тулчейнов плоская структура остаётся рабочей:

     DICT_BUNDLE="$APP_BUNDLE/Contents/Resources/SwitchFix_Dictionary.bundle"
+    # Newer Swift toolchains emit a macOS-style bundle (Contents/Resources);
+    # Bundle.url(forResource:) only looks there, not at the bundle root.
+    if [ -d "$DICT_BUNDLE/Contents/Resources" ]; then
+        DICT_BUNDLE="$DICT_BUNDLE/Contents/Resources"
+    fi
     for lang in en_US ru_RU uk_UA; do

После правки в логе появляется loaded ru_RU (entries: 146229, bloom: yes), и исправления работают. Заодно строка rm -f "$DICT_BUNDLE/${lang}.txt" начинает удалять текстовые фолбэки там, где они реально лежат.

Возможно, связано с #1 и #5: там тоже был путь к бандлу словарей.

Activity

  1. Hantok commented on Oct 20, 2026

    @Hantok
    Member

    Pre-merge audit against released v0.0.11 and PR #22 (commit 68873cc): still unresolved. No verified fixed version yet.

    In both revisions, scripts/build-app.sh copies compiled dictionaries into the root of SwitchFix_Dictionary.bundle and removes text fallbacks from that same root. It does not select Contents/Resources when SwiftPM emits a macOS-style bundle.

    Proposed fix:

    1. After copying the bundle, use its Contents/Resources directory when present; otherwise retain the flat-bundle path.
    2. Copy all three .bin files and remove their .txt fallbacks in that selected resource directory.
    3. Exercise both bundle layouts with a small shell regression check, then build with Swift 6.4 and verify Foundation resource lookup and dictionary loading from the packaged app.

    Leaving open until the packaging fix is verified and shipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions