Rime PRO
The Rime namespace exposes a programmable Chinese input-method engine that ships with the main app and the keyboard extension. Use it to build custom input flows: load schemas, feed key events, render candidates yourself, and commit the chosen text.
The engine is process-global; you set it up once and create one Rime.Session per input session.
Data directories
Rime reads schemas/dictionaries from a shared data directory and stores user state (user dictionaries, build cache) in a user data directory. Both default to the app group container shared between the main app and the keyboard extension, so the schemas you import in the main app are immediately available from the keyboard.
Rime.sharedDataDir— string path to the shared (read-only) directory.Rime.userDataDir— string path to the user directory.
You may override either path when calling Rime.setup({ sharedDataDir, userDataDir }), for example when running tests in a private sandbox.
Lifecycle
Rime.setup(options?): Promise<void>
Initializes the engine. Call this once before any other Rime.* API. Subsequent calls in the same process resolve successfully without re-initializing.
Rime.deploy(options?): Promise<void>
Recompiles schemas and rebuilds user dictionaries when needed. Call after importing or modifying schema/dict files in sharedDataDir.
Status getters (synchronous)
Schemas
Rime.listSchemas(): Promise<{ id, name }[]>
Rime.getCurrentSchema(): { id, name } | null
Returns the engine-wide current schema, or null when no schema is active.
Rime.selectSchema(schemaId): Promise<void>
Switches the engine-wide default schema. New sessions created after this call inherit the new schema; existing sessions keep their previous schema until you call session.selectSchema(id) on them.
Engine-wide options
These flags (e.g. ascii_mode, full_shape, simplification) are propagated to new sessions through an internal shared session. Per-session overrides are still possible via session.setOption(...).
Notifications
Rime.onNotification is a single optional handler invoked on the main thread when the engine fires events.
To support multiple subscribers, fan out from one handler:
Rime.Session
A session represents a single input attempt. Create one with new Rime.Session() and release it with session.close() when done.
Key handling
keyCode uses X11 keysym values (e.g. 'w'.charCodeAt(0) is 0x77, Return is 0xff0d). Returns true when the engine consumed the key.
Composition state
session.context has the shape:
Candidate selection
Commit / clear
Per-session schema and options
Closing
After close(), all methods become no-ops (processKey returns false, context returns null, etc.) and session.closed is true. Calling close() again is safe.
End-to-end example
Notes
- The shared and user directories must exist and be writable. The default app-group locations are created on first
setup()automatically. - The engine deploys schemas in the background; render a "loading" indicator while
Rime.isDeployingistrue. - To switch between Chinese and ASCII (English) modes from a key, your schema needs a
key_bindersection. Without one,Rime.setOption("ascii_mode", true)still works, but a Shift-toggle key will not. - Importing user dictionaries: drop
.dict.yamlfiles intosharedDataDir, then callRime.deploy().
