Skip to content

Commit

Permalink
getAddons
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Sep 23, 2024
1 parent 6f2e5a1 commit 68b7174
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
4 changes: 4 additions & 0 deletions page/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export function getConfig(uri: string) {
export function setConfig(uri: string, json: object) {
return Module.ccall('set_config', 'void', ['string', 'string'], [uri, JSON.stringify(json)])
}

export function getAddons() {
return JSON.parse(Module.ccall('get_addons', 'string', [], []))
}
3 changes: 2 additions & 1 deletion page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { blur, clickPanel, focus } from './focus'
import { jsKeyToFcitxString, keyEvent } from './keycode'
import { commit, hidePanel, placePanel, setPreedit } from './client'
import { currentInputMethod, getAllInputMethods, getInputMethods, setCurrentInputMethod, setInputMethods } from './input-method'
import { getConfig, setConfig } from './config'
import { getAddons, getConfig, setConfig } from './config'
import { activateMenuAction, getMenuActions } from './action'

let res: (value: any) => void
Expand Down Expand Up @@ -44,6 +44,7 @@ window.fcitx = {
getAllInputMethods,
getConfig,
setConfig,
getAddons,
jsKeyToFcitxString,
getMenuActions,
activateMenuAction,
Expand Down
31 changes: 31 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,37 @@ EMSCRIPTEN_KEEPALIVE bool set_config(const char *uri_, const char *json_) {
return false;
}
}

const char *addon_category_name[] = {"Input Method", "Frontend", "Loader",
"Module", "UI"};

EMSCRIPTEN_KEEPALIVE const char *get_addons() noexcept {
static std::string ret;
auto j = nlohmann::json::array();
for (auto category :
{fcitx::AddonCategory::Frontend, fcitx::AddonCategory::Loader,
fcitx::AddonCategory::Module}) {
auto addons = nlohmann::json::array();
auto names = instance->addonManager().addonNames(category);
for (const auto &name : names) {
const auto *info = instance->addonManager().addonInfo(name);
if (!info || !info->isConfigurable()) {
continue;
}
addons.push_back(
nlohmann::json{{"id", info->uniqueName()},
{"name", info->name().match()},
{"comment", info->comment().match()}});
}
if (!addons.empty()) {
j.push_back({{"id", category},
{"name", addon_category_name[(int)category]},
{"addons", addons}});
}
}
ret = j.dump();
return ret.c_str();
}
}

void jsonFillRawConfigValues(const nlohmann::json &j, RawConfig &config) {
Expand Down

0 comments on commit 68b7174

Please sign in to comment.