Skip to content

Commit ae7f63d

Browse files
committed
👽 Adapt to latest librime
1 parent 03ff5ce commit ae7f63d

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

.pre-commit-config.yaml

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.6.0
4+
rev: v5.0.0
55
hooks:
66
- id: check-added-large-files
77
- id: fix-byte-order-marker
@@ -38,23 +38,23 @@ repos:
3838
args:
3939
- --msg-filename
4040
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
41-
rev: 2.7.3
41+
rev: 3.0.3
4242
hooks:
4343
- id: editorconfig-checker
4444
- repo: https://github.com/jumanjihouse/pre-commit-hooks
4545
rev: 3.0.0
4646
hooks:
4747
- id: check-mailmap
4848
- repo: https://github.com/rhysd/actionlint
49-
rev: v1.7.1
49+
rev: v1.7.4
5050
hooks:
5151
- id: actionlint
5252
- repo: https://github.com/adrienverge/yamllint
5353
rev: v1.35.1
5454
hooks:
5555
- id: yamllint
5656
- repo: https://github.com/executablebooks/mdformat
57-
rev: 0.7.17
57+
rev: 0.7.19
5858
hooks:
5959
- id: mdformat
6060
additional_dependencies:
@@ -68,20 +68,16 @@ repos:
6868
- mdformat-config
6969
- mdformat-web
7070
- repo: https://github.com/DavidAnson/markdownlint-cli2
71-
rev: v0.13.0
71+
rev: v0.15.0
7272
hooks:
7373
- id: markdownlint-cli2
7474
additional_dependencies:
7575
- markdown-it-texmath
7676
- repo: https://github.com/astral-sh/ruff-pre-commit
77-
rev: v0.6.1
77+
rev: v0.7.4
7878
hooks:
7979
- id: ruff
8080
- id: ruff-format
81-
- repo: https://github.com/kumaraditya303/mirrors-pyright
82-
rev: v1.1.376
83-
hooks:
84-
- id: pyright
8581
- repo: https://github.com/pre-commit/mirrors-prettier
8682
rev: v4.0.0-alpha.8
8783
hooks:

binding.c

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#include <node_api.h>
2-
#if RIME_API_VERSION >= 1120
3-
#include <rime_api_deprecated.h>
4-
#else
52
#include <rime_api.h>
6-
#endif
73
#include <stdio.h>
84

95
#define DEFAULT_BUFFER_SIZE 1024
@@ -74,6 +70,8 @@
7470
} \
7571
} while (0);
7672

73+
static RimeApi *rime;
74+
7775
static napi_value init(napi_env env, napi_callback_info info) {
7876
napi_value argv[1];
7977
SET_ARGV(env, argv);
@@ -102,14 +100,14 @@ static napi_value init(napi_env env, napi_callback_info info) {
102100
NODE_API_CALL(
103101
env, napi_get_value_int32(env, result, &rime_traits.min_log_level));
104102
}
105-
RimeSetup(&rime_traits);
106-
RimeInitialize(&rime_traits);
103+
rime->setup(&rime_traits);
104+
rime->initialize(&rime_traits);
107105
return NULL;
108106
}
109107

110108
static napi_value createSession(napi_env env, napi_callback_info info) {
111109
napi_value result;
112-
RimeSessionId session_id = RimeCreateSession();
110+
RimeSessionId session_id = rime->create_session();
113111
if (session_id == 0) {
114112
napi_throw_error(env, NULL, "rime cannot create session");
115113
return NULL;
@@ -123,12 +121,12 @@ static napi_value destroySession(napi_env env, napi_callback_info info) {
123121
RimeSessionId session_id;
124122
SET_ARGV(env, argv);
125123
SET_SESSION_ID(env, argv[0], session_id);
126-
if (!RimeDestroySession(session_id)) {
124+
if (!rime->destroy_session(session_id)) {
127125
char str[DEFAULT_BUFFER_SIZE];
128126
sprintf(str, "cannot destroy session %ld", session_id);
129127
napi_throw_error(env, NULL, str);
130128
}
131-
RimeFinalize();
129+
rime->finalize();
132130
return NULL;
133131
}
134132

@@ -138,7 +136,7 @@ static napi_value getCurrentSchema(napi_env env, napi_callback_info info) {
138136
char buffer[DEFAULT_BUFFER_SIZE];
139137
SET_ARGV(env, argv);
140138
SET_SESSION_ID(env, argv[0], session_id);
141-
if (!RimeGetCurrentSchema(session_id, buffer, DEFAULT_BUFFER_SIZE)) {
139+
if (!rime->get_current_schema(session_id, buffer, DEFAULT_BUFFER_SIZE)) {
142140
napi_throw_error(env, NULL, "cannot get current schema");
143141
return NULL;
144142
}
@@ -150,7 +148,7 @@ static napi_value getCurrentSchema(napi_env env, napi_callback_info info) {
150148
static napi_value getSchemaList(napi_env env, napi_callback_info info) {
151149
napi_value result;
152150
RimeSchemaList schema_list;
153-
if (!RimeGetSchemaList(&schema_list)) {
151+
if (!rime->get_schema_list(&schema_list)) {
154152
napi_throw_error(env, NULL, "cannot get schema list");
155153
return NULL;
156154
}
@@ -169,7 +167,7 @@ static napi_value getSchemaList(napi_env env, napi_callback_info info) {
169167
NODE_API_CALL(env, napi_set_named_property(env, element, "name", name));
170168
NODE_API_CALL(env, napi_set_element(env, result, i, element));
171169
}
172-
RimeFreeSchemaList(&schema_list);
170+
rime->free_schema_list(&schema_list);
173171
return result;
174172
}
175173

@@ -180,7 +178,7 @@ static napi_value selectSchema(napi_env env, napi_callback_info info) {
180178
SET_ARGV(env, argv);
181179
SET_SESSION_ID(env, argv[0], session_id);
182180
SET_STRING(env, argv[1], schema_id);
183-
if (!RimeSelectSchema(session_id, schema_id)) {
181+
if (!rime->select_schema(session_id, schema_id)) {
184182
char str[DEFAULT_BUFFER_SIZE + sizeof("cannot select schema ")];
185183
sprintf(str, "cannot select schema %s", schema_id);
186184
napi_throw_error(env, NULL, str);
@@ -196,7 +194,7 @@ static napi_value processKey(napi_env env, napi_callback_info info) {
196194
SET_SESSION_ID(env, argv[0], session_id);
197195
NODE_API_CALL(env, napi_get_value_int32(env, argv[1], &keycode));
198196
NODE_API_CALL(env, napi_get_value_int32(env, argv[2], &mask));
199-
if (!RimeProcessKey(session_id, keycode, mask)) {
197+
if (!rime->process_key(session_id, keycode, mask)) {
200198
char str[DEFAULT_BUFFER_SIZE];
201199
sprintf(str, "cannot process key %d", keycode);
202200
napi_throw_error(env, NULL, str);
@@ -210,7 +208,7 @@ static napi_value getContext(napi_env env, napi_callback_info info) {
210208
SET_ARGV(env, argv);
211209
SET_SESSION_ID(env, argv[0], session_id);
212210
RIME_STRUCT(RimeContext, context);
213-
if (!RimeGetContext(session_id, &context)) {
211+
if (!rime->get_context(session_id, &context)) {
214212
napi_throw_error(env, NULL, "cannot get context");
215213
return NULL;
216214
}
@@ -308,7 +306,7 @@ static napi_value getContext(napi_env env, napi_callback_info info) {
308306
NODE_API_CALL(env, napi_set_element(env, select_keys, i, select_key));
309307
}
310308
}
311-
if (!RimeFreeContext(&context))
309+
if (!rime->free_context(&context))
312310
napi_throw_error(env, NULL, "cannot free context");
313311
return result;
314312
}
@@ -319,13 +317,13 @@ static napi_value getCommit(napi_env env, napi_callback_info info) {
319317
SET_ARGV(env, argv);
320318
SET_SESSION_ID(env, argv[0], session_id);
321319
RIME_STRUCT(RimeCommit, commit);
322-
if (!RimeGetCommit(session_id, &commit))
320+
if (!rime->get_commit(session_id, &commit))
323321
napi_throw_error(env, NULL, "cannot get commit");
324322
NODE_API_CALL(env, napi_create_object(env, &result));
325323
NODE_API_CALL(
326324
env, napi_create_string_utf8(env, commit.text, NAPI_AUTO_LENGTH, &text));
327325
NODE_API_CALL(env, napi_set_named_property(env, result, "text", text));
328-
if (!RimeFreeCommit(&commit))
326+
if (!rime->free_commit(&commit))
329327
napi_throw_error(env, NULL, "cannot free commit");
330328
return result;
331329
}
@@ -336,7 +334,7 @@ static napi_value commitComposition(napi_env env, napi_callback_info info) {
336334
SET_ARGV(env, argv);
337335
SET_SESSION_ID(env, argv[0], session_id);
338336
NODE_API_CALL(
339-
env, napi_create_int32(env, RimeCommitComposition(session_id), &result));
337+
env, napi_create_int32(env, rime->commit_composition(session_id), &result));
340338
return result;
341339
}
342340

@@ -345,11 +343,12 @@ static napi_value clearComposition(napi_env env, napi_callback_info info) {
345343
RimeSessionId session_id;
346344
SET_ARGV(env, argv);
347345
SET_SESSION_ID(env, argv[0], session_id);
348-
RimeClearComposition(session_id);
346+
rime->clear_composition(session_id);
349347
return NULL;
350348
}
351349

352350
NAPI_MODULE_INIT(/* napi_env env, napi_value exports */) {
351+
rime = rime_get_api();
353352
char *names[] = {"init",
354353
"createSession",
355354
"destroySession",

binding.gyp

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
"sources": [
99
"binding.c",
1010
],
11-
"defines": [
12-
"RIME_API_VERSION=<!@(pkg-config --modversion rime|sed 's/\\.//g')"
13-
],
1411
"cflags": [
1512
"<!@(pkg-config --cflags rime)",
1613
],

0 commit comments

Comments
 (0)