Skip to content

Commit 24a5c1a

Browse files
committed
use fcitx.invoke to replace emscripten_run_script which translates to eval
1 parent 685a38c commit 24a5c1a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

include/webview_candidate_window.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,21 @@ class WebviewCandidateWindow {
222222

223223
private:
224224
/* Invoke a JavaScript function. */
225-
template <typename Ret = void, bool debug = false, typename... Args>
225+
template <typename Ret = void, typename... Args>
226226
inline Ret invoke_js(const char *name, Args... args) const {
227227
std::stringstream ss;
228+
#ifdef __EMSCRIPTEN__
229+
ss << "[";
230+
build_js_args(ss, args...);
231+
ss << "]";
232+
auto s = ss.str();
233+
EM_ASM(fcitx.invoke(UTF8ToString($0), UTF8ToString($1)), name,
234+
s.c_str());
235+
#else
228236
ss << "fcitx." << name << "(";
229237
build_js_args(ss, args...);
230238
ss << ");";
231-
if constexpr (debug) {
232-
std::cerr << ss.str() << "\n";
233-
}
234239
auto s = ss.str();
235-
#ifdef __EMSCRIPTEN__
236-
emscripten_run_script(s.c_str());
237-
#else
238240
assert(std::this_thread::get_id() == main_thread_id_ &&
239241
"invoke_js must be called from main thread");
240242
w_->eval(s);

0 commit comments

Comments
 (0)