Server Config

2026-09-20Loading rating…

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

CapabilityDescription
Query current languageGet the language Pilot is currently using
Listen for language changesRegister a listener to receive Pilot language-switch events in real time
Remove listenerCancel 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:

EnumtagEnumtag
ZH_HANSzh-HansZH_HANTzh-Hant
ENenJAja
FRfrDEde
RUruKOko
ESesTRtr

Note: addLanguageObserver does not fire the current language immediately after registration. For first-screen sync, explicitly call getCurrentLanguage() 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: IRemoteServerConfigManageropen in new window.

IRemoteServerConfigManager is the entry point of the server config interface, exposing the following methods:

ItemDescription
IRemoteServerConfigManagerEntry point of the server config interface
getCurrentLanguageGet the current language (null if unknown)
addLanguageObserverRegister a language-change listener, returns a listener ID
removeLanguageObserverCancel 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.

Last Updated: