Skip to content

Commit ba5bd5d

Browse files
authored
chore: simplify candidate window class (#253)
1 parent 00cf19f commit ba5bd5d

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

webpanel/webpanel.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "../macosfrontend/macosfrontend.h"
55
#include "config/config.h"
66
#include "webpanel.h"
7-
#include "webview_candidate_window.hpp"
87

98
namespace fcitx {
109

@@ -148,9 +147,7 @@ WebPanel::WebPanel(Instance *instance)
148147
if (keyEvent.isRelease()) {
149148
return;
150149
}
151-
static_cast<candidate_window::WebviewCandidateWindow *>(
152-
window_.get())
153-
->copy_html();
150+
window_->copy_html();
154151
return keyEvent.filterAndAccept();
155152
}
156153
if (scrollState_ == candidate_window::scroll_state_t::ready &&
@@ -265,15 +262,12 @@ void WebPanel::updateConfig() {
265262
// window_->set_native_shadow(config_.background->shadow.value());
266263
auto style = configValueToJson(config_).dump();
267264
window_->set_style(style.c_str());
268-
if (auto web = dynamic_cast<candidate_window::WebviewCandidateWindow *>(
269-
window_.get())) {
270-
web->unload_plugins();
271-
using namespace candidate_window;
272-
uint64_t apis = (config_.advanced->unsafeAPI->curl.value() ? kCurl : 0);
273-
web->set_api(apis);
274-
if (*config_.advanced->pluginNotice) {
275-
web->load_plugins({*config_.advanced->plugins});
276-
}
265+
window_->unload_plugins();
266+
using namespace candidate_window;
267+
uint64_t apis = (config_.advanced->unsafeAPI->curl.value() ? kCurl : 0);
268+
window_->set_api(apis);
269+
if (*config_.advanced->pluginNotice) {
270+
window_->load_plugins({*config_.advanced->plugins});
277271
}
278272
}
279273

@@ -473,7 +467,8 @@ void WebPanel::updateClient(InputContext *ic) {
473467
/// Before calling this, the panel states must already be initialized
474468
/// synchronously, by using set_candidates, etc.
475469
void WebPanel::showAsync(bool show) {
476-
std::weak_ptr<candidate_window::CandidateWindow> weakWindow = window_;
470+
std::weak_ptr<candidate_window::WebviewCandidateWindow> weakWindow =
471+
window_;
477472
dispatch_async(dispatch_get_main_queue(), ^void() {
478473
if (auto window = weakWindow.lock()) {
479474
if (show) {

webpanel/webpanel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <fcitx/addonmanager.h>
1010
#include <fcitx/instance.h>
1111

12-
#include "candidate_window.hpp"
12+
#include "webview_candidate_window.hpp"
1313

1414
#define BORDER_WIDTH_MAX 10
1515

@@ -370,7 +370,7 @@ class WebPanel final : public UserInterface {
370370

371371
private:
372372
Instance *instance_;
373-
std::shared_ptr<candidate_window::CandidateWindow> window_;
373+
std::shared_ptr<candidate_window::WebviewCandidateWindow> window_;
374374

375375
static const inline std::string ConfPath = "conf/webpanel.conf";
376376
WebPanelConfig config_;

0 commit comments

Comments
 (0)