Skip to content

Port macOS engine to Rust and simplify the menu-bar app - #341

Draft
haiphanworks wants to merge 17 commits into
tuyenvm:masterfrom
haiphanworks:codex/macos-rust-engine
Draft

haiphanworks wants to merge 17 commits into
tuyenvm:masterfrom
haiphanworks:codex/macos-rust-engine

Conversation

@haiphanworks

@haiphanworks haiphanworks commented Nov 25, 2026 •

Copy link
Copy Markdown

The macOS app runs its typing engine in a dependency-free Rust static library and becomes a smaller native menu-bar utility: four settings tabs and a permission gate. Windows/Linux source and build files remain unchanged.

Draft milestone 4 review checkpoint. Milestone 5 has not started. The final review artifact is OpenKey-milestone-4-input-menu/OpenKey.app, locally ad-hoc signed, not notarized. Physical remembered-language typing remains unverified; this PR is not ready to merge.

Changes

  • Rust handles composition, spelling, encoding conversion and legacy persistence behind a thin C++ bridge. Length/UTF-8 validation protects saved data; no Rust runtime is required on users' Macs.
  • Native input recovers from timeouts/invalid ports, handles permission revocation, secure input and explicit pauses, preserves replacement-event targets and resets editing sessions at context boundaries. Spotlight ownership and terminal routing have native regression coverage.
  • A native status menu provides checked English, Telex, VNI and both Simple Telex choices, plus Settings, conversion, About and Quit. The menu bar shows an outlined EN/VI badge and active mode name. Vietnamese choices save the style and enable it; English retains the last style. Fixed-English rules block Vietnamese choices; fixed-Vietnamese rules permit style changes while blocking English. Settings have no separate language selector.
  • An actual AppKit toolbar hosts four tabs: Chung, Gõ tiếng Việt, Ứng dụng and Tương thích. SwiftUI grouped Form/Section/Toggle/Picker own content metrics on macOS 13+; older systems use an AppKit fallback. There is no sidebar/search or Advanced Settings route.
  • Missing keyboard-access permission gates settings entirely. Approval connects input and dismisses setup; revocation restores the gate. A contextual menu action handles a paused/failed connection.
  • macOS owns text replacements and Fn/Globe. OpenKey has no Text Replacements link, editor or import/export route. Macro expansion is off at runtime; original stored macro data/preferences remain intact.
  • General exposes login, an accessible shortcut recorder and sound. Typing restores input method/encoding, spelling, accent placement, sentence capitalization, extra/quick consonants and temporary Control/Command bypass. Applications has language/encoding remembering and app rules in its own tab. Compatibility restores browser suggestions, Chromium, separate key delivery, keyboard layout and bypass with another macOS input method. Conversion remains a sheet; About is native. Existing preferences remain; new/reset installs leave remembering/login off.
  • Remembered saves resolve the current app and its rule together, including explicit remembered rules with global remembering off. Settings activation does not implicitly overwrite the typing app's choice. Shortcut recording bypasses interception and ends on focus loss/close/revocation. App pickers attach to settings; conversion alerts attach to the conversion sheet.

Validation

  • 7,305 independent C++ traces match Rust and the compiled bridge after every key. Six Rust tests include 500,000 deterministic random events, ABI/invalid inputs and transactional persistence. Clippy with warnings denied passed during engine validation.
  • Current sh scripts/check-macos-input.sh passes native callback, lifecycle, settings and real AppDelegate menu checks, including permission/rule/shortcut behavior and restored typing/compatibility controls. Menu regressions cover every style, the badge/name/checkmarks, persisted state, English retaining the last style and both fixed-language policies.
  • Xcode Release build passes with deployment target 12.0; the packaged app contains arm64 and x86_64 and passes strict local ad-hoc signature verification.
  • The current four-tab artifact is live-authorized and running. Computer use verified all four tabs, all typing-style selections through Settings (restored VNI), app picker open/cancel and Chromium compatibility toggle/restore. A clean restart retained Option-Z and an enabled tap. Preference comparison matched the original snapshot except SettingsPane; original macro and remembered-app data were preserved. The previous artifact was closed.
  • The status dropdown/badge could not be observed or clicked through computer control, even after the user manually opened it; only Settings was exposed and system-menu surfaces timed out. Its actual menu handlers/checkmarks/status names pass native regression tests, but live dropdown switching/visual synchronization remains unverified.
  • Computer use of the previous artifact verified the permission gate, authorization, clean restart with enabled tap, native forms, input-method/spelling/shortcut controls, app-rule add/change/remove, About, Command-Comma and utility layouts. A native macOS replacement import/expansion test passed; its temporary entry was removed, preserving all 10 originals. The document and tested OpenKey preferences/data were restored. Text Replacement integration has since been removed from OpenKey.

Review limits

  • Earlier physical fixed-English/fixed-Vietnamese checks passed on an older artifact. The full corrected physical shortcut/app-switch/remembered-language sequence has not passed on this build. Computer-injected typing bypasses the OpenKey tap and cannot establish that result.
  • Earlier actual sleep/wake proved enabled-tap recreation, not post-wake composition. Live Spotlight composition, secure-input behavior and remote desktop remain unverified; computer control denied Terminal access.
  • Older macOS fallback is untested at runtime. Updater repair, login-item API migration, signing/notarization and final release verification remain milestone 5.

Architecture, reproduction commands and precise live limits: Sources/OpenKey/engine-rust/README.md. Stop for user review before milestone 5.

@haiphanworks haiphanworks changed the title Port the macOS typing engine to Rust Port macOS engine to Rust and harden input event handling Nov 26, 2026
@haiphanworks haiphanworks changed the title Port macOS engine to Rust and harden input event handling Port macOS typing engine to Rust and improve input setup Nov 26, 2026
@haiphanworks haiphanworks changed the title Port macOS typing engine to Rust and improve input setup Port macOS typing engine to Rust and unify settings Nov 26, 2026
@haiphanworks haiphanworks changed the title Port macOS typing engine to Rust and unify settings Port macOS engine to Rust and simplify the menu-bar app Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant