cj-tauri 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -18
- package/cjpm.toml +52 -52
- package/cli/cjpm.toml +10 -1
- package/cli/src/doctor.cj +4 -2
- package/cli/src/main.cj +11 -3
- package/cli/src/manifest.cj +558 -0
- package/cli/src/project.cj +38 -22
- package/cli/src/scaffold.cj +369 -361
- package/cli/src/sync.cj +526 -0
- package/cli/src/util.cj +168 -159
- package/cli/templates/app/README.md +48 -80
- package/cli/templates/app/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app/{ui → assets/ui}/index.html +118 -118
- package/cli/templates/app/cj-tauri.toml +22 -0
- package/cli/templates/app/cjpm.toml +34 -17
- package/cli/templates/app/src/main.cj +90 -88
- package/cli/templates/app-react/README.md +56 -67
- package/cli/templates/app-react/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app-react/{ui → assets/ui}/package.json +19 -19
- package/cli/templates/app-react/{ui → assets/ui}/src/main.jsx +6 -6
- package/cli/templates/app-react/{ui → assets/ui}/vite.config.js +24 -24
- package/cli/templates/app-react/cj-tauri.toml +23 -0
- package/cli/templates/app-react/cjpm.toml +34 -17
- package/cli/templates/app-react/src/main.cj +91 -102
- package/cli/templates/app-vue/README.md +56 -60
- package/cli/templates/app-vue/{capabilities → assets/capabilities}/default.json +7 -7
- package/cli/templates/app-vue/{ui → assets/ui}/package.json +18 -18
- package/cli/templates/app-vue/{ui → assets/ui}/src/main.js +4 -4
- package/cli/templates/app-vue/{ui → assets/ui}/vite.config.js +24 -24
- package/cli/templates/app-vue/cj-tauri.toml +23 -0
- package/cli/templates/app-vue/cjpm.toml +34 -17
- package/cli/templates/app-vue/src/main.cj +91 -102
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/app.json5 +13 -13
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/element/string.json +8 -8
- package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/layered_image.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/README.md +79 -79
- package/cli/templates/{ohos-pc → ohos-skeleton}/build-profile.json5 +46 -46
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/build-profile.json5 +26 -26
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/cjpm.toml +43 -43
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/hvigorfile.ts +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/oh-package.json5 +9 -9
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/ability_stage.cj +17 -17
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/app_host.cj +94 -94
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/index.cj +167 -167
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/cangjie/main_ability.cj +139 -139
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/module.json5 +49 -49
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/color.json +8 -8
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/element/string.json +16 -16
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/layered_image.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/profile/main_pages.json +2 -2
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/capabilities.json +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/rawfile/index.html +92 -92
- package/cli/templates/{ohos-pc → ohos-skeleton}/hvigor/hvigor-config.json5 +5 -5
- package/cli/templates/{ohos-pc → ohos-skeleton}/hvigorfile.ts +6 -6
- package/cli/templates/{ohos-pc → ohos-skeleton}/oh-package.json5 +10 -10
- package/package.json +4 -2
- package/prebuilt/win32-x64/cj-tauri.exe +0 -0
- package/src/app.cj +49 -20
- package/src/app_spec.cj +76 -0
- package/src/arkweb_script.cj +142 -154
- package/src/host.cj +20 -17
- package/src/host_arkweb.cj +778 -740
- package/src/host_webkit.cj +22 -0
- package/src/host_webview2.cj +22 -0
- package/src/launch.cj +62 -0
- package/src/platform/platform_app_context.cj +77 -0
- package/src/platform/platform_assets.cj +33 -0
- package/src/platform/platform_discover.cj +176 -0
- package/src/platform/platform_env.cj +29 -0
- package/src/platform/platform_feature.cj +31 -0
- package/src/platform/platform_page_source.cj +87 -0
- package/src/platform/platform_target_info.cj +32 -0
- package/src/platform_host_provider.cj +87 -0
- package/src/plugin.cj +36 -2
- package/src/plugins/clipboard/plugin_clipboard.cj +8 -0
- package/src/plugins/menu/plugin_menu.cj +158 -150
- package/src/plugins/notification/plugin_notification.cj +8 -0
- package/src/plugins/serial/plugin_serial.cj +454 -442
- package/src/plugins/serial/serial_bridge.cj +194 -186
- package/src/plugins/serial/serial_ohos_stub.cj +61 -0
- package/src/plugins/shell/plugin_shell.cj +258 -230
- package/src/plugins/sqlite/plugin_sqlite.cj +710 -697
- package/src/plugins/sqlite/sqlite_ffi.cj +211 -206
- package/src/plugins/sqlite/sqlite_ohos_stub.cj +91 -0
- package/src/tests/app_spec_test.cj +127 -0
- package/src/tests/fake_host.cj +23 -8
- package/src/tests/platform_contract_test.cj +251 -0
- package/src/tests/plugin_test.cj +585 -542
- package/src/version.cj +1 -1
- package/src/host_factory.cj +0 -48
- /package/cli/templates/app-react/{ui → assets/ui}/index.html +0 -0
- /package/cli/templates/app-react/{ui → assets/ui}/src/App.css +0 -0
- /package/cli/templates/app-react/{ui → assets/ui}/src/App.jsx +0 -0
- /package/cli/templates/app-vue/{ui → assets/ui}/index.html +0 -0
- /package/cli/templates/app-vue/{ui → assets/ui}/src/App.vue +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/background.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/AppScope/resources/base/media/foreground.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/build-hap.sh +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/background.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/foreground.png +0 -0
- /package/cli/templates/{ohos-pc → ohos-skeleton}/entry/src/main/resources/base/media/startIcon.png +0 -0
|
@@ -1,186 +1,194 @@
|
|
|
1
|
-
package cjTauri.plugins.serial
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
unsafe {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
1
|
+
package cjTauri.plugins.serial
|
|
2
|
+
|
|
3
|
+
// 桌面两端包装函数用(ohos 桩在 serial_ohos_stub.cj,RFC §4.6.4 P-1);
|
|
4
|
+
// foreign 声明不带门禁:ohos 侧无引用即不要求符号,不产生链接错误
|
|
5
|
+
@When[env != "ohos"]
|
|
6
|
+
import std.collection.*
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 串口桥(plugin_serial 的 FFI 面):C 桥 `cj_bridge_serial_*` 的声明与薄包装。
|
|
10
|
+
*
|
|
11
|
+
* 为什么这里**不带 @When**:两平台的导出同名同签名(AGENTS §2 的硬约束),平台差异全在
|
|
12
|
+
* `native/bridge_*.c` 里——Linux 是 termios,Windows 侧接口已留、实现待补(返回可读的
|
|
13
|
+
* 「暂不支持」,不是静默失败)。所以仓颉侧一份声明就能同时编两个平台,上层不需要平台分支。
|
|
14
|
+
*
|
|
15
|
+
* 参数约定(与 native/bridge_core.h 逐字一致):parity 0=无 1=奇 2=偶,stopBits 1|2,
|
|
16
|
+
* dataBits 5..8。**路径白名单与参数校验都在 C 侧 core**——页面可控的字符串绝不能只在仓颉侧挡。
|
|
17
|
+
*
|
|
18
|
+
* 这组导出**不收宿主句柄**:串口不是宿主能力,不必先建窗口才能用(无头进程里照样能开)。
|
|
19
|
+
*/
|
|
20
|
+
@C
|
|
21
|
+
foreign func cj_bridge_serial_open(path: CString, baud: Int32, dataBits: Int32, parity: Int32,
|
|
22
|
+
stopBits: Int32): Int64
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 读:最多 len 字节、最多等 timeoutMs 毫秒(0 = 立即返回)。返回实际字节数(0 = 超时无数据)
|
|
26
|
+
*/
|
|
27
|
+
@C
|
|
28
|
+
foreign func cj_bridge_serial_read(h: Int64, buf: CPointer<UInt8>, len: Int32, timeoutMs: Int32): Int32
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 写:在 timeoutMs 预算内尽量写完;返回实际写入字节数(可能小于 len)
|
|
32
|
+
*/
|
|
33
|
+
@C
|
|
34
|
+
foreign func cj_bridge_serial_write(h: Int64, buf: CPointer<UInt8>, len: Int32,
|
|
35
|
+
timeoutMs: Int32): Int32
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 关闭并释放句柄(幂等:重复关同一句柄返回 -4)
|
|
39
|
+
*/
|
|
40
|
+
@C
|
|
41
|
+
foreign func cj_bridge_serial_close(h: Int64): Int32
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 最近一次失败的明细(UTF-8,C 侧**线程局部**:命令各自跑在 worker 线程上,
|
|
45
|
+
* 静态单槽会被并发调用互相覆盖)
|
|
46
|
+
*/
|
|
47
|
+
@C
|
|
48
|
+
foreign func cj_bridge_serial_last_error(): CString
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 枚举本机串口(serial:list 的平台层):一行一个名字写进 buf('\n' 分隔),
|
|
52
|
+
* 返回条数(0 = 没有串口,不是错误);-1 参数非法,-4 本平台未实现。
|
|
53
|
+
* 两平台导出同名同签名:Windows 走 QueryDosDeviceW,Linux 返回 -4(list 在 Linux 走 /dev 扫描)。
|
|
54
|
+
*/
|
|
55
|
+
@C
|
|
56
|
+
foreign func cj_bridge_serial_list(buf: CPointer<UInt8>, bufLen: Int32): Int32
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 打开串口:成功返回 >0 句柄,失败返回负码(-1 参数/白名单、-2 句柄表满、-3 平台打不开)。
|
|
60
|
+
* 失败明细用 serialLastError() 取(C 侧线程局部,同一线程内取才有意义)。
|
|
61
|
+
*/
|
|
62
|
+
@When[env != "ohos"]
|
|
63
|
+
public func serialOpen(path: String, baud: Int32, dataBits: Int32, parity: Int32,
|
|
64
|
+
stopBits: Int32): Int64 {
|
|
65
|
+
var h: Int64 = -1
|
|
66
|
+
unsafe {
|
|
67
|
+
let cpath = LibC.mallocCString(path)
|
|
68
|
+
h = cj_bridge_serial_open(cpath, baud, dataBits, parity, stopBits)
|
|
69
|
+
// C 侧(core)当场把路径拷进自己的句柄槽,不持有我们的指针——这里立刻归还,
|
|
70
|
+
// 免得每次打开漏一小块(跨 FFI 的内存一律「谁分配谁释放」)
|
|
71
|
+
LibC.free(cpath)
|
|
72
|
+
}
|
|
73
|
+
return h
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* C 侧最近一次失败的明细;取不到时返回空串(调用方自行降级成数字码)
|
|
78
|
+
*/
|
|
79
|
+
@When[env != "ohos"]
|
|
80
|
+
public func serialLastError(): String {
|
|
81
|
+
unsafe {
|
|
82
|
+
return cj_bridge_serial_last_error().toString()
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* C 桥枚举本机串口:Windows 下走 QueryDosDeviceW(返回 COM 名字列表);
|
|
88
|
+
* Linux 返回 None(-4 未实现,serial:list 在 Linux 走 /dev 扫描)。C 侧异常时也回 None。
|
|
89
|
+
*/
|
|
90
|
+
@When[env != "ohos"]
|
|
91
|
+
public func serialListC(): Option<ArrayList<String>> {
|
|
92
|
+
let cap: Int32 = 8192
|
|
93
|
+
let buf = LibC.malloc<UInt8>(count: Int64(cap))
|
|
94
|
+
var n: Int32 = 0
|
|
95
|
+
unsafe {
|
|
96
|
+
n = cj_bridge_serial_list(buf, cap)
|
|
97
|
+
}
|
|
98
|
+
if (n < 0) {
|
|
99
|
+
unsafe {
|
|
100
|
+
LibC.free(buf)
|
|
101
|
+
}
|
|
102
|
+
return None
|
|
103
|
+
}
|
|
104
|
+
// 返回值是「条数」不是字节数;真正的文本以 '\0' 结尾,按终止符取整段再按 '\n' 切开
|
|
105
|
+
var len: Int64 = 0
|
|
106
|
+
unsafe {
|
|
107
|
+
while (len < Int64(cap) && buf.read(len) != 0) {
|
|
108
|
+
len++
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
let bytes = Array<UInt8>(len, repeat: 0)
|
|
112
|
+
unsafe {
|
|
113
|
+
for (i in 0..len) {
|
|
114
|
+
bytes[i] = buf.read(i)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
unsafe {
|
|
118
|
+
LibC.free(buf)
|
|
119
|
+
}
|
|
120
|
+
let out = ArrayList<String>()
|
|
121
|
+
let text = String.fromUtf8(bytes)
|
|
122
|
+
if (text != "") {
|
|
123
|
+
for (line in text.split('\n')) {
|
|
124
|
+
if (line != "") {
|
|
125
|
+
out.add(line)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return Some(out)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 读:最多 maxBytes 字节。返回实际读到的字节(空数组 = 超时无数据)。
|
|
134
|
+
* 缓冲在这里现分配现释放——每次读的用量都很小,不值得为它引一层对象池。
|
|
135
|
+
*/
|
|
136
|
+
@When[env != "ohos"]
|
|
137
|
+
public func serialRead(h: Int64, maxBytes: Int32, timeoutMs: Int32): Array<UInt8> {
|
|
138
|
+
let cap = Int64(maxBytes)
|
|
139
|
+
let buf = LibC.malloc<UInt8>(count: cap)
|
|
140
|
+
var n: Int32 = 0
|
|
141
|
+
unsafe {
|
|
142
|
+
n = cj_bridge_serial_read(h, buf, maxBytes, timeoutMs)
|
|
143
|
+
}
|
|
144
|
+
var out = Array<UInt8>(0, repeat: 0)
|
|
145
|
+
if (n > 0) {
|
|
146
|
+
out = Array<UInt8>(Int64(n), repeat: 0)
|
|
147
|
+
unsafe {
|
|
148
|
+
for (i in 0..Int64(n)) {
|
|
149
|
+
out[i] = buf.read(i)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
unsafe {
|
|
154
|
+
LibC.free(buf)
|
|
155
|
+
}
|
|
156
|
+
return out
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 写:在 timeoutMs 预算内尽量写完,返回实际写入字节数(可能 < data.size;0 = 一个字节都没出去)
|
|
161
|
+
*/
|
|
162
|
+
@When[env != "ohos"]
|
|
163
|
+
public func serialWrite(h: Int64, data: Array<UInt8>, timeoutMs: Int32): Int32 {
|
|
164
|
+
if (data.size == 0) {
|
|
165
|
+
return 0
|
|
166
|
+
}
|
|
167
|
+
let n = data.size
|
|
168
|
+
let buf = LibC.malloc<UInt8>(count: n)
|
|
169
|
+
unsafe {
|
|
170
|
+
for (i in 0..n) {
|
|
171
|
+
buf.write(i, data[i])
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
var w: Int32 = 0
|
|
175
|
+
unsafe {
|
|
176
|
+
w = cj_bridge_serial_write(h, buf, Int32(n), timeoutMs)
|
|
177
|
+
}
|
|
178
|
+
unsafe {
|
|
179
|
+
LibC.free(buf)
|
|
180
|
+
}
|
|
181
|
+
return w
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 关句柄:0 = 成功,负码 = 失败(重复关返回 -4)
|
|
186
|
+
*/
|
|
187
|
+
@When[env != "ohos"]
|
|
188
|
+
public func serialClose(h: Int64): Int32 {
|
|
189
|
+
var rc: Int32 = 0
|
|
190
|
+
unsafe {
|
|
191
|
+
rc = cj_bridge_serial_close(h)
|
|
192
|
+
}
|
|
193
|
+
return rc
|
|
194
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package cjTauri.plugins.serial
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ohos 侧 serial 桩(RFC §4.6.4 P-1):插件子包三端必须可编译——某端未接通的能力,
|
|
5
|
+
* 在子包内给「调用即可照做地报错」的桩实现(业务 build() 三端共用、import 全部所用插件,
|
|
6
|
+
* 不能靠编译期排除子包兜底——与「业务零平台分支」冲突,RFC §4.6.4 有完整论证)。
|
|
7
|
+
*
|
|
8
|
+
* 真实现批次 4 走 NDK FFI 接通(§4.6.5 四通道决策);届时删掉本文件的桩,
|
|
9
|
+
* 并在 serial_bridge.cj / plugin_serial.cj 的同名函数上补 ohos 实现段。
|
|
10
|
+
* 桩行为与 SerialPlugin.describe().supportedHosts(webkitgtk + webview2)严格一致(P-2)。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
@When[env == "ohos"]
|
|
14
|
+
import std.collection.*
|
|
15
|
+
|
|
16
|
+
@When[env == "ohos"]
|
|
17
|
+
import cjTauri.*
|
|
18
|
+
|
|
19
|
+
@When[env == "ohos"]
|
|
20
|
+
public func serialOpen(path: String, baud: Int32, dataBits: Int32, parity: Int32,
|
|
21
|
+
stopBits: Int32): Int64 {
|
|
22
|
+
throw CommandException("serial: 打开串口在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 桩的 lastError 返回可读文案而不是抛异常:桌面口径里它出现在错误消息拼接里
|
|
27
|
+
* (`serial:open failed (code …): ${serialLastError()}`),抛异常会打断拼接。
|
|
28
|
+
*/
|
|
29
|
+
@When[env == "ohos"]
|
|
30
|
+
public func serialLastError(): String {
|
|
31
|
+
return "serial: 串口在 ohos 端尚未接通(P-1 桩,批次 4 走 NDK FFI,见 RFC §4.6.4)"
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@When[env == "ohos"]
|
|
35
|
+
public func serialListC(): Option<ArrayList<String>> {
|
|
36
|
+
return None
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@When[env == "ohos"]
|
|
40
|
+
public func serialRead(h: Int64, maxBytes: Int32, timeoutMs: Int32): Array<UInt8> {
|
|
41
|
+
throw CommandException("serial: 读串口在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@When[env == "ohos"]
|
|
45
|
+
public func serialWrite(h: Int64, data: Array<UInt8>, timeoutMs: Int32): Int32 {
|
|
46
|
+
throw CommandException("serial: 写串口在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@When[env == "ohos"]
|
|
50
|
+
public func serialClose(h: Int64): Int32 {
|
|
51
|
+
throw CommandException("serial: 关闭串口在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 枚举桩抛异常而不是返回空数组:空数组在页面侧语义是「没有串口」,
|
|
56
|
+
* 与「端不支持」是两回事(P-2 的如实失败)。
|
|
57
|
+
*/
|
|
58
|
+
@When[env == "ohos"]
|
|
59
|
+
public func serialPortList(): ArrayList<String> {
|
|
60
|
+
throw CommandException("serial: 枚举串口在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
61
|
+
}
|