@@ -99,7 +99,9 @@ WebPanel::WebPanel(Instance *instance)
9999 actionableList->candidateActions (candidate)) {
100100 actions.push_back ({action.id (), action.text ()});
101101 }
102- window_->answer_actions (actions);
102+ dispatch_async (dispatch_get_main_queue (), ^{
103+ window_->answer_actions (actions);
104+ });
103105 }
104106 } catch (const std::invalid_argument &e) {
105107 FCITX_ERROR () << " action candidate index out of range" ;
@@ -151,7 +153,9 @@ WebPanel::WebPanel(Instance *instance)
151153 if (keyEvent.isRelease ()) {
152154 return ;
153155 }
154- window_->copy_html ();
156+ dispatch_async (dispatch_get_main_queue (), ^{
157+ window_->copy_html ();
158+ });
155159 return keyEvent.filterAndAccept ();
156160 }
157161 if (scrollState_ == candidate_window::scroll_state_t ::ready &&
@@ -209,7 +213,9 @@ WebPanel::WebPanel(Instance *instance)
209213 if (keyEvent.isRelease ()) {
210214 return ;
211215 }
212- window_->scroll_key_action (selectActions[keyIndex]);
216+ dispatch_async (dispatch_get_main_queue (), ^{
217+ window_->scroll_key_action (selectActions[keyIndex]);
218+ });
213219 return keyEvent.filterAndAccept ();
214220 }
215221 const std::vector<std::pair<
@@ -237,7 +243,10 @@ WebPanel::WebPanel(Instance *instance)
237243 for (const auto &pair : actionMap) {
238244 if (key.checkKeyList (*pair.first )) {
239245 if (!keyEvent.isRelease ()) {
240- window_->scroll_key_action (pair.second );
246+ auto captured = pair.second ;
247+ dispatch_async (dispatch_get_main_queue (), ^{
248+ window_->scroll_key_action (captured);
249+ });
241250 }
242251 // Must not send release event to engine, which resets
243252 // scroll mode.
@@ -250,8 +259,10 @@ WebPanel::WebPanel(Instance *instance)
250259 }
251260 // Instead of directly calling collapse, let webview handle
252261 // animation and call it.
253- window_->scroll_key_action (
254- candidate_window::scroll_key_action_t ::collapse);
262+ dispatch_async (dispatch_get_main_queue (), ^{
263+ window_->scroll_key_action (
264+ candidate_window::scroll_key_action_t ::collapse);
265+ });
255266 return keyEvent.filterAndAccept ();
256267 }
257268 // Karabiner-Elements defines Hyper as Ctrl+Alt+Shift+Cmd, but
@@ -282,28 +293,30 @@ WebPanel::WebPanel(Instance *instance)
282293}
283294
284295void WebPanel::updateConfig () {
285- window_->set_layout (config_.typography ->layout .value ());
286- window_->set_theme (config_.basic ->theme .value ());
287- window_->set_caret_text (config_.caret ->style .value () == CaretStyle::Text
288- ? config_.caret ->text .value ()
289- : " " );
290- window_->set_highlight_mark_text (config_.highlight ->markStyle .value () ==
291- HighlightMarkStyle::Text
292- ? config_.highlight ->markText .value ()
293- : " " );
294- window_->set_native_blur (config_.background ->blur .value ());
295- // Keep CSS shadow as native may leave a ghost shadow of last frame when
296- // typing fast.
297- // window_->set_native_shadow(config_.background->shadow.value());
298- auto style = configValueToJson (config_).dump ();
299- window_->set_style (style.c_str ());
300- window_->unload_plugins ();
301- using namespace candidate_window ;
302- uint64_t apis = (config_.advanced ->unsafeAPI ->curl .value () ? kCurl : 0 );
303- window_->set_api (apis);
304- if (*config_.advanced ->pluginNotice ) {
305- window_->load_plugins ({*config_.advanced ->plugins });
306- }
296+ dispatch_async (dispatch_get_main_queue (), ^{
297+ window_->set_layout (config_.typography ->layout .value ());
298+ window_->set_theme (config_.basic ->theme .value ());
299+ window_->set_caret_text (config_.caret ->style .value () == CaretStyle::Text
300+ ? config_.caret ->text .value ()
301+ : " " );
302+ window_->set_highlight_mark_text (config_.highlight ->markStyle .value () ==
303+ HighlightMarkStyle::Text
304+ ? config_.highlight ->markText .value ()
305+ : " " );
306+ window_->set_native_blur (config_.background ->blur .value ());
307+ // Keep CSS shadow as native may leave a ghost shadow of last frame when
308+ // typing fast.
309+ // window_->set_native_shadow(config_.background->shadow.value());
310+ auto style = configValueToJson (config_).dump ();
311+ window_->set_style (style.c_str ());
312+ window_->unload_plugins ();
313+ using namespace candidate_window ;
314+ uint64_t apis = (config_.advanced ->unsafeAPI ->curl .value () ? kCurl : 0 );
315+ window_->set_api (apis);
316+ if (*config_.advanced ->pluginNotice ) {
317+ window_->load_plugins ({*config_.advanced ->plugins });
318+ }
319+ });
307320}
308321
309322void WebPanel::reloadConfig () {
@@ -578,7 +591,10 @@ void WebPanel::collapse() {
578591}
579592
580593void WebPanel::applyAppAccentColor (const std::string &accentColor) {
581- window_->apply_app_accent_color (accentColor);
594+ auto captured = accentColor;
595+ dispatch_async (dispatch_get_main_queue (), ^{
596+ window_->apply_app_accent_color (captured);
597+ });
582598}
583599
584600} // namespace fcitx
0 commit comments