Skip to content

Commit

Permalink
getAllInputMethods
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Sep 1, 2024
1 parent d92aae7 commit 4850ad8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions page/Fcitx5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface FCITX {
setCurrentInputMethod: (im: string) => void
getInputMethods: () => { name: string, displayName: string }[]
setInputMethods: (ims: string[]) => void
getAllInputMethods: () => { name: string, displayName: string, languageCode: string }[]
setStatusAreaCallback: (callback: () => void) => void
updateStatusArea: () => void
}
Expand Down
3 changes: 2 additions & 1 deletion page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Module from './module'
import { blur, clickPanel, focus } from './focus'
import { keyEvent } from './keycode'
import { commit, hidePanel, placePanel, setPreedit } from './client'
import { currentInputMethod, getInputMethods, setCurrentInputMethod, setInputMethods } from './input-method'
import { currentInputMethod, getAllInputMethods, getInputMethods, setCurrentInputMethod, setInputMethods } from './input-method'

let res: (value: any) => void

Expand Down Expand Up @@ -39,6 +39,7 @@ window.fcitx = {
currentInputMethod,
getInputMethods,
setInputMethods,
getAllInputMethods,
enable() {
document.addEventListener('focus', focus, true)
document.addEventListener('blur', blur, true)
Expand Down
4 changes: 4 additions & 0 deletions page/input-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export function getInputMethods() {
export function setInputMethods(ims: string[]) {
return Module.ccall('set_input_methods', 'void', ['string'], [JSON.stringify(ims)])
}

export function getAllInputMethods() {
return JSON.parse(Module.ccall('get_all_input_methods', 'string', [], []))
}
13 changes: 13 additions & 0 deletions src/input_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static nlohmann::json json_describe_im(const fcitx::InputMethodEntry *entry) {
j["displayName"] = entry->nativeName() != "" ? entry->nativeName()
: entry->name() != "" ? entry->name()
: entry->uniqueName();
j["languageCode"] = entry->languageCode();
return j;
}

Expand Down Expand Up @@ -59,5 +60,17 @@ EMSCRIPTEN_KEEPALIVE void set_input_methods(const char *json) {
imMgr.setGroup(group);
imMgr.save();
}

EMSCRIPTEN_KEEPALIVE const char *get_all_input_methods() {
static std::string ret;
nlohmann::json j;
auto &imMgr = instance->inputMethodManager();
imMgr.foreachEntries([&j](const fcitx::InputMethodEntry &entry) {
j.push_back(json_describe_im(&entry));
return true;
});
ret = j.dump();
return ret.c_str();
}
}
} // namespace fcitx

0 comments on commit 4850ad8

Please sign in to comment.