cj-tauri 2.0.0 → 2.1.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 +113 -99
- package/bin/cj-tauri.js +287 -287
- package/cjpm.toml +63 -52
- package/cli/cjpm.toml +22 -22
- package/cli/src/doctor.cj +308 -306
- package/cli/src/main.cj +129 -129
- package/cli/src/manifest.cj +632 -558
- package/cli/src/manifest_test.cj +87 -0
- package/cli/src/project.cj +770 -770
- package/cli/src/resolve.cj +348 -348
- package/cli/src/scaffold.cj +369 -369
- package/cli/src/sync.cj +526 -526
- package/cli/src/util.cj +168 -168
- package/cli/templates/app/README.md +51 -48
- package/cli/templates/app/assets/capabilities/default.json +7 -7
- package/cli/templates/app/assets/ui/index.html +120 -118
- package/cli/templates/app/cj-tauri.toml +32 -22
- package/cli/templates/app/cjpm.toml +34 -34
- package/cli/templates/app/src/main.cj +101 -90
- package/cli/templates/app-react/README.md +56 -56
- package/cli/templates/app-react/assets/capabilities/default.json +7 -7
- package/cli/templates/app-react/assets/ui/index.html +25 -25
- package/cli/templates/app-react/assets/ui/package.json +19 -19
- package/cli/templates/app-react/assets/ui/src/App.css +67 -67
- package/cli/templates/app-react/assets/ui/src/App.jsx +124 -124
- package/cli/templates/app-react/assets/ui/src/main.jsx +6 -6
- package/cli/templates/app-react/assets/ui/vite.config.js +24 -24
- package/cli/templates/app-react/cj-tauri.toml +33 -23
- package/cli/templates/app-react/cjpm.toml +34 -34
- package/cli/templates/app-react/src/main.cj +91 -91
- package/cli/templates/app-vue/README.md +56 -56
- package/cli/templates/app-vue/assets/capabilities/default.json +7 -7
- package/cli/templates/app-vue/assets/ui/index.html +25 -25
- package/cli/templates/app-vue/assets/ui/package.json +18 -18
- package/cli/templates/app-vue/assets/ui/src/App.vue +176 -176
- package/cli/templates/app-vue/assets/ui/src/main.js +4 -4
- package/cli/templates/app-vue/assets/ui/vite.config.js +24 -24
- package/cli/templates/app-vue/cj-tauri.toml +33 -23
- package/cli/templates/app-vue/cjpm.toml +34 -34
- package/cli/templates/app-vue/src/main.cj +91 -91
- package/cli/templates/ohos-skeleton/AppScope/app.json5 +13 -13
- package/cli/templates/ohos-skeleton/AppScope/resources/base/element/string.json +8 -8
- package/cli/templates/ohos-skeleton/AppScope/resources/base/media/layered_image.json +6 -6
- package/cli/templates/ohos-skeleton/README.md +84 -79
- package/cli/templates/ohos-skeleton/build-hap.sh +15 -0
- package/cli/templates/ohos-skeleton/build-profile.json5 +46 -46
- package/cli/templates/ohos-skeleton/entry/build-profile.json5 +26 -26
- package/cli/templates/ohos-skeleton/entry/cjpm.toml +51 -43
- package/cli/templates/ohos-skeleton/entry/hvigorfile.ts +6 -6
- package/cli/templates/ohos-skeleton/entry/oh-package.json5 +9 -9
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/ability_stage.cj +17 -17
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/app_host.cj +94 -94
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/dialog_host.cj +217 -0
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/index.cj +527 -167
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/main_ability.cj +139 -139
- package/cli/templates/ohos-skeleton/entry/src/main/module.json5 +57 -49
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/element/color.json +8 -8
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/element/string.json +16 -16
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/media/layered_image.json +6 -6
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/profile/main_pages.json +2 -2
- package/cli/templates/ohos-skeleton/entry/src/main/resources/rawfile/capabilities.json +6 -6
- package/cli/templates/ohos-skeleton/entry/src/main/resources/rawfile/index.html +92 -92
- package/cli/templates/ohos-skeleton/hvigor/hvigor-config.json5 +5 -5
- package/cli/templates/ohos-skeleton/hvigorfile.ts +6 -6
- package/cli/templates/ohos-skeleton/oh-package.json5 +10 -10
- package/native/build_win.bat +62 -62
- package/native/core/bridge_core.c +1681 -1626
- package/native/core/bridge_core.h +675 -618
- package/native/core/bridge_js.h +108 -108
- package/native/platforms/harmonyos/README.md +115 -6
- package/native/platforms/linux/bridge_linux.c +2787 -2485
- package/native/platforms/windows/bridge_win.c +3740 -3248
- package/native/tests/gtk_threading_probe.c +143 -143
- package/native/tests/test_bridge_core.c +1339 -1228
- package/package.json +53 -53
- package/prebuilt/linux-x64/cj-tauri +0 -0
- package/src/api_system.cj +67 -67
- package/src/app.cj +325 -969
- package/src/app_events.cj +166 -0
- package/src/app_host_ops.cj +287 -0
- package/src/app_run.cj +283 -0
- package/src/app_spec.cj +76 -76
- package/src/arkweb_menu.cj +216 -0
- package/src/arkweb_script.cj +142 -142
- package/src/capability.cj +409 -409
- package/src/clipboard_bridge.cj +178 -0
- package/src/dialog_spec.cj +79 -0
- package/src/dragdrop.cj +26 -26
- package/src/embedded_assets.cj +98 -98
- package/src/host.cj +752 -607
- package/src/host_arkweb.cj +924 -778
- package/src/host_webkit.cj +663 -570
- package/src/host_webview2.cj +663 -570
- package/src/hotkey.cj +66 -66
- package/src/ipc_hub.cj +337 -337
- package/src/ipc_message.cj +286 -286
- package/src/launch.cj +62 -62
- package/src/logging.cj +127 -127
- package/src/menu.cj +197 -197
- package/src/platform/platform_app_context.cj +77 -77
- package/src/platform/platform_assets.cj +33 -33
- package/src/platform/platform_discover.cj +176 -176
- package/src/platform/platform_env.cj +29 -29
- package/src/platform/platform_feature.cj +31 -31
- package/src/platform/platform_page_source.cj +87 -87
- package/src/platform/platform_target_info.cj +32 -32
- package/src/platform_host_provider.cj +87 -87
- package/src/plugin.cj +333 -333
- package/src/plugins/clipboard/plugin_clipboard.cj +152 -152
- package/src/plugins/dialog/plugin_dialog.cj +209 -209
- package/src/plugins/fs/plugin_fs.cj +105 -1
- package/src/plugins/http/http_backend.cj +131 -0
- package/src/plugins/http/http_desktop.cj +195 -0
- package/src/plugins/http/http_ohos.cj +204 -0
- package/src/plugins/http/plugin_http.cj +310 -459
- package/src/plugins/log/plugin_log.cj +105 -105
- package/src/plugins/menu/plugin_menu.cj +158 -158
- package/src/plugins/notification/plugin_notification.cj +154 -154
- package/src/plugins/serial/plugin_serial.cj +458 -454
- package/src/plugins/serial/serial_bridge.cj +194 -194
- package/src/plugins/serial/serial_manager_ohos.cj +92 -0
- package/src/plugins/serial/serial_ohos.cj +529 -0
- package/src/plugins/shell/plugin_shell.cj +258 -258
- package/src/plugins/sqlite/plugin_sqlite.cj +705 -710
- package/src/plugins/sqlite/sqlite_ffi.cj +206 -211
- package/src/plugins/ws/plugin_ws.cj +488 -470
- package/src/process_hidden.cj +174 -174
- package/src/scope.cj +391 -391
- package/src/shell_event.cj +69 -69
- package/src/tests/app_spec_test.cj +126 -127
- package/src/tests/capability_test.cj +243 -243
- package/src/tests/dialog_spec_test.cj +73 -0
- package/src/tests/fake_host.cj +201 -201
- package/src/tests/ipc_hub_test.cj +487 -487
- package/src/tests/logging_test.cj +62 -62
- package/src/tests/platform_contract_test.cj +251 -251
- package/src/tests/plugin_clipboard_test.cj +222 -222
- package/src/tests/plugin_dialog_test.cj +237 -237
- package/src/tests/plugin_fs_test.cj +207 -0
- package/src/tests/plugin_http_test.cj +124 -124
- package/src/tests/plugin_notification_test.cj +205 -205
- package/src/tests/plugin_serial_test.cj +48 -0
- package/src/tests/plugin_test.cj +605 -585
- package/src/tests/plugin_ws_test.cj +40 -40
- package/src/tests/process_hidden_test.cj +129 -129
- package/src/tests/scope_test.cj +350 -350
- package/src/tests/system_host_test.cj +99 -81
- package/src/tests/urlutil_test.cj +53 -53
- package/src/tests/version_test.cj +75 -75
- package/src/tests/window_registry_test.cj +123 -123
- package/src/tray.cj +90 -90
- package/src/urlutil.cj +159 -159
- package/src/version.cj +44 -44
- package/src/window.cj +51 -51
- package/src/window_registry.cj +116 -116
- package/prebuilt/win32-x64/cj-tauri.exe +0 -0
- package/src/plugins/serial/serial_ohos_stub.cj +0 -61
- package/src/plugins/sqlite/sqlite_ohos_stub.cj +0 -91
package/src/window_registry.cj
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
package cjTauri
|
|
2
|
-
|
|
3
|
-
import std.collection.*
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 一个窗口的记录:label 唯一,config 是它创建时的窗口配置快照
|
|
7
|
-
*
|
|
8
|
-
* label 是窗口对外的**唯一身份**(Tauri 同样按 label 寻址):前端页面只认 label,
|
|
9
|
-
* C 侧句柄是跨 FFI 的不透明指针,留在宿主实现内部、不越过 IPC 协议(见
|
|
10
|
-
* docs/架构演进-多平台与多窗口.md §7.2)。
|
|
11
|
-
*/
|
|
12
|
-
public class WindowRecord {
|
|
13
|
-
public let label: String
|
|
14
|
-
public let host: WebViewHost
|
|
15
|
-
public let config: WindowConfig
|
|
16
|
-
|
|
17
|
-
public init(label: String, host: WebViewHost, config: WindowConfig) {
|
|
18
|
-
this.label = label
|
|
19
|
-
this.host = host
|
|
20
|
-
this.config = config
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* label → 窗口记录(批次 2 的地基)
|
|
26
|
-
*
|
|
27
|
-
* 单窗口阶段只登记一条 "main"——与桥 JS 的 windowLabel 缺省值、旧代码里写死的 "main"
|
|
28
|
-
* 是同一个约定(**默认值不能变**,否则现有示例与探针会静默收不到事件,见架构文档 §6.4)。
|
|
29
|
-
* 多窗口落地后它是「label → 宿主」的唯一权威来源:事件定向投递(emitToWindow)与
|
|
30
|
-
* 命令上下文(IpcContext.window)都从这里查。
|
|
31
|
-
*
|
|
32
|
-
* 为什么重复 label 直接抛而不是覆盖:覆盖会让「一个 label 后面挂着两个宿主」静默成立,
|
|
33
|
-
* 而这类 bug 的表现是「事件忽而收得到、忽而收不到」,是最难查的一类。
|
|
34
|
-
*/
|
|
35
|
-
class WindowRegistry {
|
|
36
|
-
private var windows: HashMap<String, WindowRecord> = HashMap<String, WindowRecord>()
|
|
37
|
-
// 为什么另存一份插入顺序:HashMap 不承诺迭代顺序,而广播要按确定顺序投递——
|
|
38
|
-
// 否则多窗口下事件的到达顺序随机,测试也没法断言(labels() 直接给这张表)。
|
|
39
|
-
private var order: ArrayList<String> = ArrayList<String>()
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 登记一个窗口:label 非空且未被占用
|
|
43
|
-
*/
|
|
44
|
-
func add(record: WindowRecord): Unit {
|
|
45
|
-
if (record.label.size == 0) {
|
|
46
|
-
throw Exception("window label 不能为空")
|
|
47
|
-
}
|
|
48
|
-
if (this.windows.contains(record.label)) {
|
|
49
|
-
throw Exception("duplicate window label: \"${record.label}\"")
|
|
50
|
-
}
|
|
51
|
-
this.windows.add(record.label, record)
|
|
52
|
-
this.order.add(record.label)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 按 label 取窗口;未登记返回 None(调用方决定是降级还是报错)
|
|
57
|
-
*/
|
|
58
|
-
func get(label: String): Option<WindowRecord> {
|
|
59
|
-
return this.windows.get(label)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 全部 label,**按登记顺序**(广播路径据此保持确定顺序)
|
|
64
|
-
*/
|
|
65
|
-
func labels(): ArrayList<String> {
|
|
66
|
-
let out = ArrayList<String>()
|
|
67
|
-
for (l in this.order) {
|
|
68
|
-
out.add(l)
|
|
69
|
-
}
|
|
70
|
-
return out
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 解析投递目标:空串 = 广播(按登记顺序给出全部窗口),非空 = 命中则单元素、否则空表
|
|
75
|
-
*
|
|
76
|
-
* 路由决策放在这里而不是调用方:它是纯函数(不碰宿主)因而能单测,调用方只剩
|
|
77
|
-
* 「投给谁」与「一个都没命中时怎么报」两件事。**未注册的 label 不回落成广播**——
|
|
78
|
-
* 写错 label 就该什么都收不到(由调用方打一条 stderr),静默变成广播比丢事件更难查。
|
|
79
|
-
*/
|
|
80
|
-
func targets(window: String): ArrayList<WindowRecord> {
|
|
81
|
-
let out = ArrayList<WindowRecord>()
|
|
82
|
-
if (window.size == 0) {
|
|
83
|
-
for (l in this.order) {
|
|
84
|
-
out.add(this.windows.get(l).getOrThrow())
|
|
85
|
-
}
|
|
86
|
-
return out
|
|
87
|
-
}
|
|
88
|
-
match (this.windows.get(window)) {
|
|
89
|
-
case Some(rec) => out.add(rec)
|
|
90
|
-
case None => ()
|
|
91
|
-
}
|
|
92
|
-
return out
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 注销窗口;label 不存在时为空操作(关窗路径可能重复触发,不该被异常打断)
|
|
97
|
-
*/
|
|
98
|
-
func remove(label: String): Unit {
|
|
99
|
-
if (!this.windows.contains(label)) {
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
let _ = this.windows.remove(label)
|
|
103
|
-
// 顺序表同步:重建一遍(窗口数以个位计,不值得为它引一个索引表)
|
|
104
|
-
let kept = ArrayList<String>()
|
|
105
|
-
for (l in this.order) {
|
|
106
|
-
if (l != label) {
|
|
107
|
-
kept.add(l)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
this.order = kept
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
func size(): Int64 {
|
|
114
|
-
return this.windows.size
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
package cjTauri
|
|
2
|
+
|
|
3
|
+
import std.collection.*
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 一个窗口的记录:label 唯一,config 是它创建时的窗口配置快照
|
|
7
|
+
*
|
|
8
|
+
* label 是窗口对外的**唯一身份**(Tauri 同样按 label 寻址):前端页面只认 label,
|
|
9
|
+
* C 侧句柄是跨 FFI 的不透明指针,留在宿主实现内部、不越过 IPC 协议(见
|
|
10
|
+
* docs/架构演进-多平台与多窗口.md §7.2)。
|
|
11
|
+
*/
|
|
12
|
+
public class WindowRecord {
|
|
13
|
+
public let label: String
|
|
14
|
+
public let host: WebViewHost
|
|
15
|
+
public let config: WindowConfig
|
|
16
|
+
|
|
17
|
+
public init(label: String, host: WebViewHost, config: WindowConfig) {
|
|
18
|
+
this.label = label
|
|
19
|
+
this.host = host
|
|
20
|
+
this.config = config
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* label → 窗口记录(批次 2 的地基)
|
|
26
|
+
*
|
|
27
|
+
* 单窗口阶段只登记一条 "main"——与桥 JS 的 windowLabel 缺省值、旧代码里写死的 "main"
|
|
28
|
+
* 是同一个约定(**默认值不能变**,否则现有示例与探针会静默收不到事件,见架构文档 §6.4)。
|
|
29
|
+
* 多窗口落地后它是「label → 宿主」的唯一权威来源:事件定向投递(emitToWindow)与
|
|
30
|
+
* 命令上下文(IpcContext.window)都从这里查。
|
|
31
|
+
*
|
|
32
|
+
* 为什么重复 label 直接抛而不是覆盖:覆盖会让「一个 label 后面挂着两个宿主」静默成立,
|
|
33
|
+
* 而这类 bug 的表现是「事件忽而收得到、忽而收不到」,是最难查的一类。
|
|
34
|
+
*/
|
|
35
|
+
class WindowRegistry {
|
|
36
|
+
private var windows: HashMap<String, WindowRecord> = HashMap<String, WindowRecord>()
|
|
37
|
+
// 为什么另存一份插入顺序:HashMap 不承诺迭代顺序,而广播要按确定顺序投递——
|
|
38
|
+
// 否则多窗口下事件的到达顺序随机,测试也没法断言(labels() 直接给这张表)。
|
|
39
|
+
private var order: ArrayList<String> = ArrayList<String>()
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 登记一个窗口:label 非空且未被占用
|
|
43
|
+
*/
|
|
44
|
+
func add(record: WindowRecord): Unit {
|
|
45
|
+
if (record.label.size == 0) {
|
|
46
|
+
throw Exception("window label 不能为空")
|
|
47
|
+
}
|
|
48
|
+
if (this.windows.contains(record.label)) {
|
|
49
|
+
throw Exception("duplicate window label: \"${record.label}\"")
|
|
50
|
+
}
|
|
51
|
+
this.windows.add(record.label, record)
|
|
52
|
+
this.order.add(record.label)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 按 label 取窗口;未登记返回 None(调用方决定是降级还是报错)
|
|
57
|
+
*/
|
|
58
|
+
func get(label: String): Option<WindowRecord> {
|
|
59
|
+
return this.windows.get(label)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 全部 label,**按登记顺序**(广播路径据此保持确定顺序)
|
|
64
|
+
*/
|
|
65
|
+
func labels(): ArrayList<String> {
|
|
66
|
+
let out = ArrayList<String>()
|
|
67
|
+
for (l in this.order) {
|
|
68
|
+
out.add(l)
|
|
69
|
+
}
|
|
70
|
+
return out
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 解析投递目标:空串 = 广播(按登记顺序给出全部窗口),非空 = 命中则单元素、否则空表
|
|
75
|
+
*
|
|
76
|
+
* 路由决策放在这里而不是调用方:它是纯函数(不碰宿主)因而能单测,调用方只剩
|
|
77
|
+
* 「投给谁」与「一个都没命中时怎么报」两件事。**未注册的 label 不回落成广播**——
|
|
78
|
+
* 写错 label 就该什么都收不到(由调用方打一条 stderr),静默变成广播比丢事件更难查。
|
|
79
|
+
*/
|
|
80
|
+
func targets(window: String): ArrayList<WindowRecord> {
|
|
81
|
+
let out = ArrayList<WindowRecord>()
|
|
82
|
+
if (window.size == 0) {
|
|
83
|
+
for (l in this.order) {
|
|
84
|
+
out.add(this.windows.get(l).getOrThrow())
|
|
85
|
+
}
|
|
86
|
+
return out
|
|
87
|
+
}
|
|
88
|
+
match (this.windows.get(window)) {
|
|
89
|
+
case Some(rec) => out.add(rec)
|
|
90
|
+
case None => ()
|
|
91
|
+
}
|
|
92
|
+
return out
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 注销窗口;label 不存在时为空操作(关窗路径可能重复触发,不该被异常打断)
|
|
97
|
+
*/
|
|
98
|
+
func remove(label: String): Unit {
|
|
99
|
+
if (!this.windows.contains(label)) {
|
|
100
|
+
return
|
|
101
|
+
}
|
|
102
|
+
let _ = this.windows.remove(label)
|
|
103
|
+
// 顺序表同步:重建一遍(窗口数以个位计,不值得为它引一个索引表)
|
|
104
|
+
let kept = ArrayList<String>()
|
|
105
|
+
for (l in this.order) {
|
|
106
|
+
if (l != label) {
|
|
107
|
+
kept.add(l)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.order = kept
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func size(): Int64 {
|
|
114
|
+
return this.windows.size
|
|
115
|
+
}
|
|
116
|
+
}
|
|
Binary file
|
|
@@ -1,61 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
package cjTauri.plugins.sqlite
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ohos 侧 sqlite 桩(RFC §4.6.4 P-1):FFI 直连系统 sqlite3 在鸿蒙 hap 里没有链接对象,
|
|
5
|
-
* 桌面实现整体门禁(plugin_sqlite.cj / sqlite_ffi.cj 的 `@When[env != "ohos"]`),
|
|
6
|
-
* 本文件提供同名的桩类占住装配位——业务 build() 三端共用、import 全部所用插件,
|
|
7
|
-
* 不能靠编译期排除子包(与「业务零平台分支」冲突,RFC §4.6.4 有完整论证)。
|
|
8
|
-
*
|
|
9
|
-
* 桩语义:命令表 / 权限集 / 前端 shim 与桌面版完全一致(页面 API 面不变),
|
|
10
|
-
* 但每条命令运行期抛「端不支持」——P-2 的如实失败,与 describe().supportedHosts
|
|
11
|
-
* (webkitgtk)严格一致。真实现批次 4 走 NDK FFI 接通(§4.6.5 四通道决策)后,
|
|
12
|
-
* 删掉本文件、在桌面声明上补 ohos 实现段。
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
@When[env == "ohos"]
|
|
16
|
-
import std.collection.*
|
|
17
|
-
|
|
18
|
-
@When[env == "ohos"]
|
|
19
|
-
import stdx.encoding.json.*
|
|
20
|
-
|
|
21
|
-
@When[env == "ohos"]
|
|
22
|
-
import cjTauri.*
|
|
23
|
-
|
|
24
|
-
@When[env == "ohos"]
|
|
25
|
-
public class SqlitePlugin <: Plugin {
|
|
26
|
-
public init() {}
|
|
27
|
-
|
|
28
|
-
/** 自描述与桌面版一致(P-2:桩行为与 supportedHosts 严格对齐) */
|
|
29
|
-
public func describe(): PluginManifest {
|
|
30
|
-
let hosts = ArrayList<String>()
|
|
31
|
-
hosts.add("webkitgtk")
|
|
32
|
-
return PluginManifest(hosts, ArrayList<String>())
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public func name(): String {
|
|
36
|
-
return "sqlite"
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** 与桌面版一致:path 参数吃 scope 校验(桩不碰路径,语义保持一致免得两端行为分叉) */
|
|
40
|
-
public func scopeAware(): Bool {
|
|
41
|
-
return true
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 命令表与桌面版同形(常量共用 plugin_sqlite.cj 的门禁外 let),每条指向桩处理器 */
|
|
45
|
-
public func commands(): HashMap<String, CommandHandler> {
|
|
46
|
-
let m = HashMap<String, CommandHandler>()
|
|
47
|
-
for (short in SQLITE_PLUGIN_COMMANDS) {
|
|
48
|
-
m.add(short, SqliteOhosStubHandler())
|
|
49
|
-
}
|
|
50
|
-
return m
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public func permissions(): HashMap<String, ArrayList<String>> {
|
|
54
|
-
let m = HashMap<String, ArrayList<String>>()
|
|
55
|
-
let ro = ArrayList<String>()
|
|
56
|
-
for (short in SQLITE_READONLY_COMMANDS) {
|
|
57
|
-
ro.add(short)
|
|
58
|
-
}
|
|
59
|
-
m.add("readonly", ro)
|
|
60
|
-
let all = ArrayList<String>()
|
|
61
|
-
for (short in SQLITE_PLUGIN_COMMANDS) {
|
|
62
|
-
all.add(short)
|
|
63
|
-
}
|
|
64
|
-
m.add("default", all)
|
|
65
|
-
return m
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 前端 shim 与桌面版逐字一致:页面 __CJ_TAURI__.sqlite 命名空间照常存在,调用得到可读错误 */
|
|
69
|
-
public func jsShim(): String {
|
|
70
|
-
return "(function () { var t = window.__CJ_TAURI__ || (window.__CJ_TAURI__ = {});" +
|
|
71
|
-
" t.sqlite = {" +
|
|
72
|
-
" info: function (args) { return window.__CJ_TAURI__.invoke('sqlite:info', args); }," +
|
|
73
|
-
" tables: function (args) { return window.__CJ_TAURI__.invoke('sqlite:tables', args); }," +
|
|
74
|
-
" schema: function (args) { return window.__CJ_TAURI__.invoke('sqlite:schema', args); }," +
|
|
75
|
-
" page: function (args) { return window.__CJ_TAURI__.invoke('sqlite:page', args); }," +
|
|
76
|
-
" query: function (args) { return window.__CJ_TAURI__.invoke('sqlite:query', args); }," +
|
|
77
|
-
" exec: function (args) { return window.__CJ_TAURI__.invoke('sqlite:exec', args); }," +
|
|
78
|
-
" env: function (args) { return window.__CJ_TAURI__.invoke('sqlite:env', args); }" +
|
|
79
|
-
" }; })();\n"
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** 桩处理器:不分命令、一律如实报错(可照做:换端或等批次 4) */
|
|
84
|
-
@When[env == "ohos"]
|
|
85
|
-
class SqliteOhosStubHandler <: CommandHandler {
|
|
86
|
-
public init() {}
|
|
87
|
-
|
|
88
|
-
public func handle(cmd: String, args: JsonObject, ipc: IpcContext): JsonValue {
|
|
89
|
-
throw CommandException("sqlite: ${cmd} 在 ohos 端暂不支持(P-1 桩,批次 4 走 NDK FFI 接通,见 RFC §4.6.4)")
|
|
90
|
-
}
|
|
91
|
-
}
|