Server Config
1. Feature Overview
Server config lets the plugin sense Pilot's runtime configuration. What is currently exposed is language config: the plugin can query the language Pilot is using and listen for language-switch events in Pilot, keeping the plugin's UI text consistent with Pilot for multi-language coordination.
1.1 Capability Overview
| Capability | Description |
|---|---|
| Query current language | Get the language Pilot is currently using |
| Listen for language changes | Register a listener to receive Pilot language-switch events in real time |
| Remove listener | Cancel the language-change listener by the ID returned at registration |
1.2 Use Cases
- Text coordination: switch the plugin's UI text when Pilot switches language
- First-screen adaptation: load resources for Pilot's current language when the plugin starts
2. Interface Call Examples
The examples below assume you have completed SDK initialization and the plugin is connected to Pilot (for connection state, see the Plugin Connection State documentation). All interfaces are called through the manager singleton RemoteServerConfigManager.getInstance().
2.1 Query the Current Language and Listen for Changes (getCurrentLanguage / addLanguageObserver)
The recommended pattern is "query the current language once for first-screen sync, then register a listener for later changes." addLanguageObserver returns a listener ID used to cancel later:
val configManager = RemoteServerConfigManager.getInstance() // get the manager singleton
// 1. First-screen sync: query the current language (returns null if not received or unknown)
val current: RemoteLanguage? = configManager.getCurrentLanguage()
current?.let { applyLanguage(it) } // load resources for the current language
// 2. Register a listener for later changes, saving the returned listener ID
val listenerId: Int = configManager.addLanguageObserver { language ->
applyLanguage(language) // fires when Pilot switches language
}
RemoteLanguage values cover the languages Pilot supports, each carrying a language tag:
| Enum | tag | Enum | tag |
|---|---|---|---|
ZH_HANS | zh-Hans | ZH_HANT | zh-Hant |
EN | en | JA | ja |
FR | fr | DE | de |
RU | ru | KO | ko |
ES | es | TR | tr |
Note:
addLanguageObserverdoes not fire the current language immediately after registration. For first-screen sync, explicitly callgetCurrentLanguage()once (as in step 1 above). The same language is not reported twice; only a real change triggers a callback.
2.2 Remove the Listener (removeLanguageObserver)
Cancel the listener with the ID returned at registration when the page is destroyed:
override fun onDestroy() {
super.onDestroy()
configManager.removeLanguageObserver(listenerId) // pass the listener ID saved in 2.1
}
3. API Reference
For the full definitions of these interface methods (including enums), see the API documentation: IRemoteServerConfigManager.
IRemoteServerConfigManager is the entry point of the server config interface, exposing the following methods:
| Item | Description |
|---|---|
IRemoteServerConfigManager | Entry point of the server config interface |
getCurrentLanguage | Get the current language (null if unknown) |
addLanguageObserver | Register a language-change listener, returns a listener ID |
removeLanguageObserver | Cancel the language-change listener by ID |
4. FAQ
Q1: getCurrentLanguage() returns null—what do I do?
It means Pilot's language config has not arrived yet (e.g., the connection was just established) or the language tag was not recognized. Fall back to the plugin's default language for now, and switch once addLanguageObserver fires a language change.
Q2: Why don't I get the current language immediately after registering?
This is by design. addLanguageObserver only handles later change notifications and does not fire the current value. For first-screen sync, explicitly call getCurrentLanguage() once; together they cover "first + subsequent."
Q3: Why cancel by ID rather than by listener object?
addLanguageObserver identifies each registration with an incrementing ID, and removeLanguageObserver(id) cancels it precisely by ID. Be sure to save the ID returned at registration and pass it back when the page is destroyed, to avoid a lingering listener whose text callback holds a page reference.
Appendix: Note
This module's methods do not use error-code callbacks: getCurrentLanguage directly returns an enum or null, and listener registration / cancellation has no error code. When the connection is not ready, getCurrentLanguage returns null—fall back as in Q1.