Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
},
"license": "AGPL-3.0-or-later",
"devDependencies": {
"@antfu/eslint-config": "^3.12.1",
"@playwright/test": "^1.50.1",
"@types/node": "^22.13.5",
"@antfu/eslint-config": "^4.11.0",
"@playwright/test": "^1.51.1",
"@types/node": "^22.13.17",
"@types/uzip": "^0.20201231.2",
"error-stack-parser": "^2.1.4",
"esbuild": "^0.24.2",
"eslint": "^9.17.0",
"esbuild": "^0.25.2",
"eslint": "^9.23.0",
"serve": "^14.2.4",
"textarea-caret": "^3.1.0",
"typescript": "^5.7.2",
"typescript": "^5.8.2",
"uzip": "^0.20201231.0"
}
}
18 changes: 18 additions & 0 deletions src/event_js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ struct JSEventSource : public JSEventSourceBase<EventSource> {
std::shared_ptr<EventCallback> callback_;
};

struct JSEventSourceAsync : public JSEventSourceBase<EventSourceAsync> {
JSEventSourceAsync(EventCallback _callback)
: callback_(std::make_shared<EventCallback>(std::move(_callback))) {}

void send() override {
// This is synchronous but probably not a big deal for JS.
(*callback_)(nullptr);
}

std::shared_ptr<EventCallback> callback_;
};

struct JSEventSourceIO : public JSEventSourceBase<EventSourceIO> {
JSEventSourceIO(IOCallback _callback) {}

Expand Down Expand Up @@ -151,4 +163,10 @@ std::unique_ptr<EventSource> JSEventLoop::addPostEvent(EventCallback callback) {
return nullptr;
}

std::unique_ptr<EventSourceAsync>
JSEventLoop::addAsyncEvent(EventCallback callback) {
auto source = std::make_unique<JSEventSourceAsync>(std::move(callback));
return source;
}

} // namespace fcitx
4 changes: 3 additions & 1 deletion src/event_js.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <fcitx-utils/eventloopinterface.h>

namespace fcitx {
class JSEventLoop : public EventLoopInterface {
class JSEventLoop : public EventLoopInterfaceV2 {
public:
JSEventLoop() = default;
~JSEventLoop() override = default;
Expand All @@ -20,5 +20,7 @@ class JSEventLoop : public EventLoopInterface {
std::unique_ptr<EventSource> addExitEvent(EventCallback callback) override;
std::unique_ptr<EventSource> addDeferEvent(EventCallback callback) override;
std::unique_ptr<EventSource> addPostEvent(EventCallback callback) override;
std::unique_ptr<EventSourceAsync>
addAsyncEvent(EventCallback callback) override;
};
} // namespace fcitx
Loading