Skip to content

Commit

Permalink
load shared addons
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj committed Feb 8, 2025
1 parent 64f2c4f commit a1de181
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
#include <fcitx-utils/environ.h>
#include <fcitx-utils/event.h>
#include <fcitx-utils/eventdispatcher.h>
#include <fcitx/addonmanager.h>
#include <fcitx/instance.h>
#include <filesystem>
#include <windows.h>

namespace fs = std::filesystem;

namespace fcitx {
std::unique_ptr<Instance> instance;
std::unique_ptr<fcitx::EventDispatcher> dispatcher;

void setenv(const char *name, const std::string &value) {
setEnvironment(name, value.c_str());
}

void setupEnv() {
char path[MAX_PATH];
GetModuleFileNameA(NULL, path, MAX_PATH);
auto rootPath = ::fs::path(path).parent_path().parent_path();
auto fcitx_addon_dirs = rootPath / "lib" / "fcitx5";
setenv("FCITX_ADDON_DIRS", fcitx_addon_dirs.u8string());
auto xdg_data_dirs = rootPath / "share";
auto fcitx_data_dirs = xdg_data_dirs / "fcitx5";
setenv("XDG_DATA_DIRS", xdg_data_dirs.u8string());
setenv("FCITX_DATA_DIRS", fcitx_data_dirs.u8string());
}

void start() {
Log::setLogRule("*=5,notimedate");
setupEnv();
instance = std::make_unique<Instance>(0, nullptr);
auto &addonMgr = instance->addonManager();
addonMgr.registerDefaultLoader(nullptr);
instance->initialize();
dispatcher = std::make_unique<fcitx::EventDispatcher>();
dispatcher->attach(&instance->eventLoop());
Expand Down

0 comments on commit a1de181

Please sign in to comment.