cj-tauri 2.1.3 → 2.3.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.
Files changed (43) hide show
  1. package/bin/cj-tauri.js +87 -0
  2. package/cjpm.toml +1 -1
  3. package/cli/cjpm.toml +1 -1
  4. package/cli/src/doctor.cj +1 -1
  5. package/cli/src/manifest.cj +5 -2
  6. package/cli/src/project.cj +1 -1
  7. package/cli/templates/ohos-skeleton/entry/cjpm.toml +7 -1
  8. package/native/core/bridge_core.c +8 -5
  9. package/native/core/bridge_core.h +5 -2
  10. package/native/platforms/linux/bridge_linux.c +6 -3
  11. package/native/platforms/windows/bridge_win.c +44 -9
  12. package/native/tests/test_bridge_core.c +27 -3
  13. package/package.json +1 -1
  14. package/src/app.cj +1 -1
  15. package/src/app_events.cj +5 -5
  16. package/src/app_host_ops.cj +8 -8
  17. package/src/app_run.cj +8 -8
  18. package/src/capability.cj +3 -3
  19. package/src/capability_loader.cj +8 -8
  20. package/src/embedded_assets.cj +5 -5
  21. package/src/host.cj +6 -6
  22. package/src/host_arkweb.cj +31 -31
  23. package/src/host_webkit.cj +31 -10
  24. package/src/host_webview2.cj +31 -9
  25. package/src/ipc_hub.cj +8 -8
  26. package/src/launch.cj +1 -1
  27. package/src/log_bridge.cj +141 -13
  28. package/src/logging.cj +2 -2
  29. package/src/menu.cj +1 -1
  30. package/src/plugin.cj +6 -6
  31. package/src/plugins/http/http_ohos.cj +2 -2
  32. package/src/plugins/http/plugin_http.cj +2 -2
  33. package/src/plugins/mqtt/plugin_mqtt.cj +4 -4
  34. package/src/plugins/redis/plugin_redis.cj +20 -20
  35. package/src/plugins/sqlite/sqlite_ffi.cj +3 -3
  36. package/src/plugins/store/plugin_store.cj +3 -3
  37. package/src/plugins/ws/plugin_ws.cj +7 -7
  38. package/src/process_hidden.cj +5 -5
  39. package/src/tests/logging_test.cj +66 -0
  40. package/src/tests/plugin_store_test.cj +1 -1
  41. package/src/tests/scope_test.cj +2 -2
  42. package/src/tray.cj +2 -2
  43. package/src/version.cj +1 -1
package/src/log_bridge.cj CHANGED
@@ -1,10 +1,11 @@
1
1
  package cjTauri
2
2
 
3
+ import std.collection.*
3
4
 
4
5
  /**
5
- * 日志落盘桥(RFC-003 第 5 期):C 桥 `cj_bridge_log_*` 的声明与薄包装。
6
+ * 日志出口桥(RFC-003 第 5 期 + 2026-11-12 鸿蒙 hilog 收口)。
6
7
  *
7
- * 桌面两平台导出同名同签名(AGENTS §2 的硬约束),实现只有一份
8
+ * 桌面两平台:C 桥 `cj_bridge_log_*`,导出同名同签名(AGENTS §2 的硬约束),实现只有一份
8
9
  * (`native/core/bridge_core.c`)——落盘是把 fd 2 指到日志文件,与宿主 UI 栈无关,
9
10
  * 所以不吃宿主句柄、也不进 `WebViewHost` 接口:它是**进程级**的,不是窗口级的。
10
11
  *
@@ -12,15 +13,19 @@ package cjTauri
12
13
  * **两侧**的诊断收进同一份文件,只有 fd 层的接管做得到(见 core 里那段注释的取舍)。
13
14
  *
14
15
  * 鸿蒙(`env == "ohos"`)侧没有 C 桥产物(`native/platforms/harmonyos/` 目前只有契约),
15
- * 这三个 FFI 符号无处解析——若照桌面那份写下去,**模块加载期就 SIGSEGV**(实测 2026-10-18:
16
- * 应用进程 signal:11,AbilityStage.onCreate 一行都执行不到)。所以这里按平台分叉,
17
- * 鸿蒙侧如实降级:不落盘、`writeLogLine` 返回 false,绝不假装成功。
16
+ * 那三个 FFI 符号无处解析——若照桌面那份写下去,**模块加载期就 SIGSEGV**(实测 2026-10-18:
17
+ * 应用进程 signal:11,AbilityStage.onCreate 一行都执行不到)。但「没有落盘出口」不等于
18
+ * 「没有日志出口」:设备上的日志出口是 hilog(`OH_LOG_Print`,`libhilog_ndk.z.so`)。
19
+ *
20
+ * 于是这里按平台分叉成两条出口,上层只认一个函数:
21
+ * - 桌面:诊断走 stderr(`logd`),要留文件由 `enableLogFile` 接管 fd 2;
22
+ * - 鸿蒙:诊断走 hilog(tag = `cj-tauri`),没有文件出口,`enableLogFile` 如实回 false。
18
23
  *
19
24
  * 判据用 `env` 而不是 `arch`(2026-10-19 校正):`arch == "aarch64"` 连桌面 aarch64 Linux
20
25
  * 一起门禁掉了,那个平台**是有 C 桥的**,会白白失去日志落盘能力。
21
26
  */
22
27
 
23
- /** 门禁口径与 `host.cj` 的 FFI 一致:桌面走 C 桥,鸿蒙走降级实现。 */
28
+ /** 门禁口径与 `host.cj` 的 FFI 一致:桌面走 C 桥,鸿蒙走 hilog / 降级实现。 */
24
29
  @When[env != "ohos"]
25
30
  @C
26
31
  foreign func cj_bridge_set_log_file(path: CString, maxKB: Int32, keep: Int32): Int32
@@ -41,6 +46,128 @@ foreign func cj_bridge_log_file(): CString
41
46
  @C
42
47
  foreign func cj_bridge_log_write(line: CString): Int32
43
48
 
49
+ // ==========================================================================
50
+ // 鸿蒙侧:hilog 原生 C API(NDK,`libhilog_ndk.z.so`)
51
+ //
52
+ // 为什么不用 SDK 的 `ohos.hilog` 包:框架包对 ohos 模块的依赖要额外落链接开关,
53
+ // 而 hilog 的 NDK C 符号(`OH_LOG_Print`)是稳定接口、与 `libpasteboard` / `libudmf`
54
+ // 同一个套路(`src/clipboard_bridge.cj` 已真机验证),链接库名固定为 `hilog_ndk.z`。
55
+ // **链接开关写在入口模块**(`cli/src/manifest.cj` 的 `renderOhosEntryToml`)——最终链接发生在
56
+ // `output-type = dynamic` 的 entry,框架自己的 cjpm.toml 写了不生效,缺了就是模块加载期崩。
57
+ // ==========================================================================
58
+
59
+ /** hilog 的日志域(`OH_LOG_Print` 的 domain)与 tag;取证按 tag 过滤:`hdc shell hilog | grep cj-tauri` */
60
+ const HILOG_DOMAIN: Int32 = 0
61
+ const HILOG_TAG: String = "cj-tauri"
62
+
63
+ /** LogType:应用日志是 LOG_APP = 0 */
64
+ const HILOG_TYPE_APP: Int32 = 0
65
+ /** LogLevel:DEBUG = 3 / INFO = 4 / WARN = 5 / ERROR = 6 / FATAL = 7 */
66
+ const HILOG_INFO: Int32 = 4
67
+
68
+ /**
69
+ * 单条 hilog 的字节预算:hilog 对单条日志有长度上限(1024 字节),留出 tag 与域的余量取 1000。
70
+ * 超长行按 UTF-8 字符边界切片、分多条打印,**不截断**——取证要对得上每一条明细。
71
+ */
72
+ const HILOG_MAX_BYTES: Int64 = 1000
73
+
74
+ /**
75
+ * `int OH_LOG_Print(LogType type, LogLevel level, unsigned int domain, const char *tag,
76
+ * const char *fmt, ...)`
77
+ *
78
+ * 变长参数是硬需求:hilog 的 `%s` 不带隐私修饰符会打成 `<private>`,正文必须经
79
+ * `%{public}s` + 一个实参送进去。若把正文直接当 fmt 传(不传实参),正文里一个 `%`
80
+ * 就会让 hilog 去消费不存在的参数——所以 fmt 恒为字面量,正文只做实参。
81
+ */
82
+ @When[env == "ohos"]
83
+ @C
84
+ foreign func OH_LOG_Print(logType: Int32, level: Int32, domain: Int32, tag: CString, fmt: CString, ...): Int32
85
+
86
+ /**
87
+ * 按字节预算把一行切成若干片,UTF-8 边界安全(不切在半个汉字中间)。
88
+ *
89
+ * 平台无关、无 FFI 依赖,public 是为了让单测与探针能直接验它——鸿蒙分支在本机编不了
90
+ * (SDK 只有 linux / windows 两个目标),能本地验证的部分就别留在未验证里。
91
+ */
92
+ public func hilogSplit(line: String, maxBytes: Int64): ArrayList<String> {
93
+ let out = ArrayList<String>()
94
+ // 预算下限 4 字节 = 一个 UTF-8 字符的最大长度,保证下面「回退到边界」一定落得下来
95
+ let limit = if (maxBytes < 4) {
96
+ 4
97
+ } else {
98
+ maxBytes
99
+ }
100
+ let total = line.size
101
+ if (total <= limit) {
102
+ out.add(line)
103
+ return out
104
+ }
105
+ let bytes = line.toArray()
106
+ var start: Int64 = 0
107
+ while (start < total) {
108
+ var end = start + limit
109
+ if (end > total) {
110
+ end = total
111
+ }
112
+ if (end < total) {
113
+ // 0b10xxxxxx 是 UTF-8 续字节:落在续字节上就往回退到字符起点
114
+ while (end > start && (bytes[end] & 0xC0u8) == 0x80u8) {
115
+ end = end - 1
116
+ }
117
+ if (end == start) {
118
+ // 兜底(limit >= 4 时到不了这里):与其硬切出非法 UTF-8,不如把余下整段一次交出
119
+ end = total
120
+ }
121
+ }
122
+ out.add(String.fromUtf8(bytes[start..end]))
123
+ start = end
124
+ }
125
+ return out
126
+ }
127
+
128
+ /** 把一行打到 hilog(超预算分条)。返回是否全部送出(非 0 说明 hilog 侧拒了) */
129
+ @When[env == "ohos"]
130
+ func hilogPrint(level: Int32, text: String): Bool {
131
+ var ok = true
132
+ for (chunk in hilogSplit(text, HILOG_MAX_BYTES)) {
133
+ unsafe {
134
+ let tag = LibC.mallocCString(HILOG_TAG)
135
+ let fmt = LibC.mallocCString("%{public}s")
136
+ let msg = LibC.mallocCString(chunk)
137
+ let rc = OH_LOG_Print(HILOG_TYPE_APP, level, HILOG_DOMAIN, tag, fmt, msg)
138
+ // hilog 只拷贝内容,不接管入参所有权——每行都释放,长驻进程不能靠泄漏换省事
139
+ LibC.free(tag)
140
+ LibC.free(fmt)
141
+ LibC.free(msg)
142
+ if (rc < 0) {
143
+ ok = false
144
+ }
145
+ }
146
+ }
147
+ return ok
148
+ }
149
+
150
+ /**
151
+ * 框架统一的诊断出口:桌面写 stderr(可能已被 `enableLogFile` 接管到日志文件),鸿蒙写 hilog。
152
+ *
153
+ * 名字取 `logd`(log diagnostic)是因为调用点有两百来处,长名字把每行诊断都推过折行线;
154
+ * 语义不变:一行一条、不加前缀、不加时间戳——前缀由调用方自己带(`[cj-tauri] …`)。
155
+ *
156
+ * 框架内新代码一律调它,**别再直接 `eprintln`**——鸿蒙上 `eprintln` 的 stderr 一行都不进
157
+ * hilog,设备侧等于没有日志(AGENTS §4 实测:白屏排查时 hilog 里连 AbilityStage.onCreate
158
+ * 都看不见,而 CANGJIE-RUNTIME 的行照常打)。
159
+ */
160
+ @When[env != "ohos"]
161
+ public func logd(line: String): Unit {
162
+ eprintln(line)
163
+ }
164
+
165
+ /** 鸿蒙侧:同上,出口换成 hilog(tag = cj-tauri,等级 INFO) */
166
+ @When[env == "ohos"]
167
+ public func logd(line: String): Unit {
168
+ let _ = hilogPrint(HILOG_INFO, line)
169
+ }
170
+
44
171
  /** 开日志落盘,返回是否真的开了(被拒时 C 侧已出声,这里绝不假装成功) */
45
172
  @When[env != "ohos"]
46
173
  func enableLogFile(path: String, maxKB: Int64, keep: Int64): Bool {
@@ -60,16 +187,18 @@ func enableLogFile(path: String, maxKB: Int64, keep: Int64): Bool {
60
187
  }
61
188
 
62
189
  /**
63
- * 鸿蒙侧:没有 C 桥,落盘能力位如实为 0。
190
+ * 鸿蒙侧:没有 C 桥,落盘能力位如实为 0——但日志出口仍在(hilog),
191
+ * 所以这行提示要经 `logd` 发出去,否则「为什么没有日志文件」这件事本身也没凭证。
64
192
  *
65
193
  * 返回 false 而不抛异常——调用方(`setLogToDefaultFile`)本就是「尽力而为」语义,
66
- * 抛异常会把应用启动带走。留一行 stderr 说明「哪条路没走通」。
194
+ * 抛异常会把应用启动带走。
67
195
  */
68
196
  @When[env == "ohos"]
69
197
  func enableLogFile(path: String, maxKB: Int64, keep: Int64): Bool {
70
198
  let _ = maxKB
71
199
  let _ = keep
72
- eprintln("[cj-tauri] log file sink unavailable on this platform (no C bridge): ${path}")
200
+ logd("[cj-tauri] log file sink unavailable on this platform (no C bridge); " +
201
+ "diagnostics go to hilog (tag=${HILOG_TAG}): ${path}")
73
202
  return false
74
203
  }
75
204
 
@@ -83,7 +212,7 @@ public func currentLogFilePath(): String {
83
212
  return cs.toString()
84
213
  }
85
214
 
86
- /** 鸿蒙侧没有落盘出口:恒为空串(与「未开启」同口径,调用方无需分支) */
215
+ /** 鸿蒙侧没有落盘文件:恒为空串(与「未开启」同口径,调用方无需分支) */
87
216
  @When[env == "ohos"]
88
217
  public func currentLogFilePath(): String {
89
218
  return ""
@@ -99,9 +228,8 @@ public func writeLogLine(line: String): Bool {
99
228
  return rc == 0
100
229
  }
101
230
 
102
- /** 鸿蒙侧:没有出口可写,返回 false(调用方据返回值如实回报,不冒充已写入) */
231
+ /** 鸿蒙侧:出口是 hilog,返回是否真的送出去了(调用方据返回值如实回报,不冒充已写入) */
103
232
  @When[env == "ohos"]
104
233
  public func writeLogLine(line: String): Bool {
105
- let _ = line
106
- return false
234
+ return hilogPrint(HILOG_INFO, line)
107
235
  }
package/src/logging.cj CHANGED
@@ -52,9 +52,9 @@ public func logBudgetFromEnv(name: String, dflt: Int64): Int64 {
52
52
  if (n > 0) {
53
53
  return n
54
54
  }
55
- eprintln("[cj-tauri] ${name}=\"${v}\" 不是正整数,按默认值 ${dflt} 处理")
55
+ logd("[cj-tauri] ${name}=\"${v}\" 不是正整数,按默认值 ${dflt} 处理")
56
56
  } catch (e: Exception) {
57
- eprintln("[cj-tauri] ${name}=\"${v}\" 解析失败,按默认值 ${dflt} 处理")
57
+ logd("[cj-tauri] ${name}=\"${v}\" 解析失败,按默认值 ${dflt} 处理")
58
58
  }
59
59
  }
60
60
  }
package/src/menu.cj CHANGED
@@ -127,7 +127,7 @@ public class MenuModel {
127
127
  for (item in items) {
128
128
  if (!MenuModel.wireSafe(item.id) || !MenuModel.wireSafe(item.label) ||
129
129
  !MenuModel.wireSafe(item.accelerator)) {
130
- eprintln("[cj-tauri] menu: item dropped from wire (id/label/accelerator contains tab or newline)")
130
+ logd("[cj-tauri] menu: item dropped from wire (id/label/accelerator contains tab or newline)")
131
131
  continue
132
132
  }
133
133
  out += MenuModel.tabs(depth) + MenuModel.kindCode(item.kind) + "\t" + item.id + "\t" +
package/src/plugin.cj CHANGED
@@ -290,14 +290,14 @@ public func warnUnauthorizedPlugins(plugins: ArrayList<Plugin>, caps: Capability
290
290
  for (p in plugins) {
291
291
  for (name in pluginCommandNames(p)) {
292
292
  if (!caps.canInvoke(name)) {
293
- eprintln("[cj-tauri] 插件 ${p.name()} 的命令 ${name} 尚未授权,前端调用会被拒绝")
294
- eprintln("[cj-tauri] 请在 capabilities 目录的 json 里把 \"${name}\" 加进 commands")
293
+ logd("[cj-tauri] 插件 ${p.name()} 的命令 ${name} 尚未授权,前端调用会被拒绝")
294
+ logd("[cj-tauri] 请在 capabilities 目录的 json 里把 \"${name}\" 加进 commands")
295
295
  }
296
296
  }
297
297
  for (name in pluginEventNames(p)) {
298
298
  if (!caps.canEmit(name)) {
299
- eprintln("[cj-tauri] 插件 ${p.name()} 的事件 ${name} 尚未授权,推送会被丢弃")
300
- eprintln("[cj-tauri] 请在 capabilities 目录的 json 里把 \"${name}\" 加进 events")
299
+ logd("[cj-tauri] 插件 ${p.name()} 的事件 ${name} 尚未授权,推送会被丢弃")
300
+ logd("[cj-tauri] 请在 capabilities 目录的 json 里把 \"${name}\" 加进 events")
301
301
  }
302
302
  }
303
303
  }
@@ -327,7 +327,7 @@ public func warnUnscopedPlugins(plugins: ArrayList<Plugin>, caps: CapabilityRegi
327
327
  if (caps.hasScopeForPlugin(p.name())) {
328
328
  continue
329
329
  }
330
- eprintln("[cj-tauri] 插件 ${p.name()} 的路径参数未声明 scope:按旧行为全量放行")
331
- eprintln("[cj-tauri] 建议在 capabilities 的 json 里加 \"scopes\": { \"${p.name()}\": { \"allow\": [\"<放行路径>\"] } }")
330
+ logd("[cj-tauri] 插件 ${p.name()} 的路径参数未声明 scope:按旧行为全量放行")
331
+ logd("[cj-tauri] 建议在 capabilities 的 json 里加 \"scopes\": { \"${p.name()}\": { \"allow\": [\"<放行路径>\"] } }")
332
332
  }
333
333
  }
@@ -157,11 +157,11 @@ func ohosRequest(method: String, url: String, headers: HashMap<String, String>,
157
157
  }
158
158
 
159
159
  if (let Some(msg) <- feed.failure) {
160
- eprintln("[cj-tauri] http transport failed (ohos): ${msg}")
160
+ logd("[cj-tauri] http transport failed (ohos): ${msg}")
161
161
  throw CommandException("http: request failed on HarmonyOS: ${msg}")
162
162
  }
163
163
  if (!feed.done) {
164
- eprintln("[cj-tauri] http transport timeout (ohos): ${waited}ms ${url}")
164
+ logd("[cj-tauri] http transport timeout (ohos): ${waited}ms ${url}")
165
165
  throw CommandException("http: no response within ${waited}ms on HarmonyOS")
166
166
  }
167
167
  return (feed.status, feed.contentType, feed.bytes)
@@ -162,7 +162,7 @@ public class HttpCommands <: CommandHandler {
162
162
  try {
163
163
  tail = String.fromUtf8(pending.toArray())
164
164
  } catch (e: Exception) {
165
- eprintln("[cj-tauri] http:postStream 尾部 ${pending.size} 字节不是合法 UTF-8(流被掐断),已丢弃")
165
+ logd("[cj-tauri] http:postStream 尾部 ${pending.size} 字节不是合法 UTF-8(流被掐断),已丢弃")
166
166
  }
167
167
  }
168
168
  ipc.emit("http:chunk", this.chunkPayload(status, ctype, tail, total, true, truncated))
@@ -280,7 +280,7 @@ public class HttpCommands <: CommandHandler {
280
280
  }
281
281
 
282
282
  private func rejectOutsideScope(url: String, why: String): Nothing {
283
- eprintln("[cj-tauri] scope denied (http): ${url} -> ${why}")
283
+ logd("[cj-tauri] scope denied (http): ${url} -> ${why}")
284
284
  throw CommandException("http: host is outside the authorized scope")
285
285
  }
286
286
 
@@ -155,7 +155,7 @@ func mqttRecord(sess: MqttSession, obj: JsonObject): Unit {
155
155
  }
156
156
  sess.dropped += from
157
157
  sess.recent = keep
158
- eprintln("[cj-tauri] mqtt: recent 缓冲超限,丢弃最旧 ${from} 条(累计 dropped=${sess.dropped})")
158
+ logd("[cj-tauri] mqtt: recent 缓冲超限,丢弃最旧 ${from} 条(累计 dropped=${sess.dropped})")
159
159
  }
160
160
  sess.lock.unlock()
161
161
  match (app) {
@@ -188,7 +188,7 @@ func mqttEmitState(sess: MqttSession): Unit {
188
188
  line = "state=${sess.state} host=${sess.host}:${sess.port} rx=${sess.rxCount} tx=${sess.txCount}" +
189
189
  " dropped=${sess.dropped}"
190
190
  sess.lock.unlock()
191
- eprintln("[cj-tauri] mqtt: ${line}")
191
+ logd("[cj-tauri] mqtt: ${line}")
192
192
  match (app) {
193
193
  case Some(a) => a.emit("mqtt:state", obj)
194
194
  case None => ()
@@ -225,7 +225,7 @@ func mqttFailSession(sess: MqttSession, reason: String): Unit {
225
225
  case None => ()
226
226
  }
227
227
  if (first) {
228
- eprintln("[cj-tauri] mqtt: ${reason}")
228
+ logd("[cj-tauri] mqtt: ${reason}")
229
229
  }
230
230
  mqttEmitState(sess)
231
231
  }
@@ -855,7 +855,7 @@ class MqttCommands <: CommandHandler {
855
855
  sleep(Duration.millisecond * MQTT_WAIT_STEP_MS)
856
856
  waited += MQTT_WAIT_STEP_MS
857
857
  }
858
- eprintln("[cj-tauri] mqtt: 上一条连接的读线程未在 ${MQTT_READER_EXIT_WAIT_MS}ms 内收尾,继续建新连接")
858
+ logd("[cj-tauri] mqtt: 上一条连接的读线程未在 ${MQTT_READER_EXIT_WAIT_MS}ms 内收尾,继续建新连接")
859
859
  }
860
860
 
861
861
  /** 取会话记下的失败原因(没有就用 fallback)——失败原因只有会话知道,别让页面去猜 */
@@ -188,7 +188,7 @@ func redisRecordMessage(sess: RedisSession, obj: JsonObject): Unit {
188
188
  }
189
189
  sess.dropped += from
190
190
  sess.recent = keep
191
- eprintln("[cj-tauri] redis: 订阅缓冲超限,丢弃最旧 ${from} 条(累计 dropped=${sess.dropped})")
191
+ logd("[cj-tauri] redis: 订阅缓冲超限,丢弃最旧 ${from} 条(累计 dropped=${sess.dropped})")
192
192
  }
193
193
  sess.lock.unlock()
194
194
  match (app) {
@@ -220,7 +220,7 @@ func redisEmitState(sess: RedisSession): Unit {
220
220
  obj.put("error", JsonString(sess.lastError))
221
221
  // 状态变迁同时落一行 stderr:事件通道页面没接住时(没声明 events / 页面在重载),
222
222
  // 「连上过没有、什么时候掉的」仍能端到端对账——与框架其余能力的取证口径一致(AGENTS §1)
223
- eprintln("[cj-tauri] redis state: state=${sess.state} host=${sess.host}:${sess.port} db=${sess.db}" +
223
+ logd("[cj-tauri] redis state: state=${sess.state} host=${sess.host}:${sess.port} db=${sess.db}" +
224
224
  " sub=${sess.subAlive} channels=${sess.channels.size} calls=${sess.calls} msgs=${sess.msgCount}" +
225
225
  " dropped=${sess.dropped}")
226
226
  sess.lock.unlock()
@@ -263,7 +263,7 @@ func redisFailSession(sess: RedisSession, reason: String): Unit {
263
263
  case None => ()
264
264
  }
265
265
  if (first) {
266
- eprintln("[cj-tauri] redis: ${reason}")
266
+ logd("[cj-tauri] redis: ${reason}")
267
267
  }
268
268
  redisEmitState(sess)
269
269
  }
@@ -360,7 +360,7 @@ func redisReplyJson(v: RespValue): JsonValue {
360
360
  func redisExpectOk(v: RespValue, what: String): RespValue {
361
361
  match (v) {
362
362
  case Failure(m) =>
363
- eprintln("[cj-tauri] redis command failed (${what}): ${m}")
363
+ logd("[cj-tauri] redis command failed (${what}): ${m}")
364
364
  throw CommandException("redis: ${what} 失败(${m})")
365
365
  case _ => return v
366
366
  }
@@ -371,7 +371,7 @@ func redisNumberReply(v: RespValue, what: String): Int64 {
371
371
  match (v) {
372
372
  case Number(n) => return n
373
373
  case Failure(m) =>
374
- eprintln("[cj-tauri] redis command failed (${what}): ${m}")
374
+ logd("[cj-tauri] redis command failed (${what}): ${m}")
375
375
  throw CommandException("redis: ${what} 失败(${m})")
376
376
  case _ => throw CommandException("redis: ${what} 期望整数回复,实际是 ${respBrief(v)}")
377
377
  }
@@ -384,7 +384,7 @@ func redisTextReply(v: RespValue, what: String): String {
384
384
  case Bulk(Some(b)) => return respSafeText(b)
385
385
  case Bulk(None) => return ""
386
386
  case Failure(m) =>
387
- eprintln("[cj-tauri] redis command failed (${what}): ${m}")
387
+ logd("[cj-tauri] redis command failed (${what}): ${m}")
388
388
  throw CommandException("redis: ${what} 失败(${m})")
389
389
  case _ => throw CommandException("redis: ${what} 期望文本回复,实际是 ${respBrief(v)}")
390
390
  }
@@ -416,7 +416,7 @@ func redisLogCall(sess: RedisSession, what: String, reply: RespValue): Unit {
416
416
  sess.calls += 1
417
417
  let n = sess.calls
418
418
  sess.lock.unlock()
419
- eprintln("[cj-tauri] redis call: ${what} -> ${redisBriefClipped(reply)} (n=${n})")
419
+ logd("[cj-tauri] redis call: ${what} -> ${redisBriefClipped(reply)} (n=${n})")
420
420
  }
421
421
 
422
422
  /**
@@ -553,7 +553,7 @@ func redisCallMany(sess: RedisSession, frames: ArrayList<Array<UInt8>>, what: St
553
553
  sess.calls += frames.size
554
554
  let n = sess.calls
555
555
  sess.lock.unlock()
556
- eprintln("[cj-tauri] redis call: PIPELINE ${what} n=${frames.size} 回执已按序读齐 (n=${n})")
556
+ logd("[cj-tauri] redis call: PIPELINE ${what} n=${frames.size} 回执已按序读齐 (n=${n})")
557
557
  } catch (e: Exception) {
558
558
  sess.callLock.unlock()
559
559
  throw e
@@ -872,7 +872,7 @@ class RedisCommands <: CommandHandler {
872
872
  throw e
873
873
  }
874
874
  redisEmitState(sess)
875
- eprintln("[cj-tauri] redis connect: host=${host} port=${port} db=${db} auth=${sess.authUsed} ok")
875
+ logd("[cj-tauri] redis connect: host=${host} port=${port} db=${db} auth=${sess.authUsed} ok")
876
876
  let out = JsonObject()
877
877
  out.put("ok", JsonBool(true))
878
878
  out.put("host", JsonString(host))
@@ -1604,7 +1604,7 @@ class RedisCommands <: CommandHandler {
1604
1604
  let patternsJson = redisStringArray(sess.patterns)
1605
1605
  sess.lock.unlock()
1606
1606
  if (!allAcked) {
1607
- eprintln("[cj-tauri] redis sub: 订阅回执未在 ${REDIS_SUB_ACK_TIMEOUT_MS}ms 内到齐" +
1607
+ logd("[cj-tauri] redis sub: 订阅回执未在 ${REDIS_SUB_ACK_TIMEOUT_MS}ms 内到齐" +
1608
1608
  "(pending=${pending}),如实上报,不假装订阅成功")
1609
1609
  }
1610
1610
  redisEmitState(sess)
@@ -1704,7 +1704,7 @@ class RedisCommands <: CommandHandler {
1704
1704
  case Some(s) => redisCloseQuiet(s)
1705
1705
  case None => ()
1706
1706
  }
1707
- eprintln("[cj-tauri] redis sub: 订阅已全部退掉,订阅连接与读线程已收")
1707
+ logd("[cj-tauri] redis sub: 订阅已全部退掉,订阅连接与读线程已收")
1708
1708
  } else {
1709
1709
  let _ = this.waitSubAcks(sess, REDIS_SUB_ACK_TIMEOUT_MS)
1710
1710
  }
@@ -1731,7 +1731,7 @@ class RedisCommands <: CommandHandler {
1731
1731
  let receivers = redisNumberReply(
1732
1732
  redisCallFrame(sess, respEncodeCommandRaw([redisRaw("PUBLISH"), redisRaw(channel), payload]), "PUBLISH"),
1733
1733
  "PUBLISH")
1734
- eprintln("[cj-tauri] redis publish: channel=${channel} bytes=${payload.size} receivers=${receivers}")
1734
+ logd("[cj-tauri] redis publish: channel=${channel} bytes=${payload.size} receivers=${receivers}")
1735
1735
  let out = JsonObject()
1736
1736
  out.put("channel", JsonString(channel))
1737
1737
  out.put("bytes", JsonInt(Int64(payload.size)))
@@ -1807,7 +1807,7 @@ class RedisCommands <: CommandHandler {
1807
1807
  sess.stopSubRequested = false
1808
1808
  sess.subAlive = true
1809
1809
  sess.lock.unlock()
1810
- eprintln("[cj-tauri] redis sub: 订阅连接已建立(读线程接管读侧)")
1810
+ logd("[cj-tauri] redis sub: 订阅连接已建立(读线程接管读侧)")
1811
1811
  spawn { => redisSubLoop(sess) }
1812
1812
  redisEmitState(sess)
1813
1813
  }
@@ -1882,7 +1882,7 @@ class RedisCommands <: CommandHandler {
1882
1882
  exited = true
1883
1883
  done = true
1884
1884
  } else if ((DateTime.now() - started).toMilliseconds() > REDIS_SUB_EXIT_WAIT_MS) {
1885
- eprintln("[cj-tauri] redis sub: 读线程未在 ${REDIS_SUB_EXIT_WAIT_MS}ms 内退出,收尾继续(不无限等)")
1885
+ logd("[cj-tauri] redis sub: 读线程未在 ${REDIS_SUB_EXIT_WAIT_MS}ms 内退出,收尾继续(不无限等)")
1886
1886
  done = true
1887
1887
  } else {
1888
1888
  sleep(Duration.millisecond * 20)
@@ -1923,7 +1923,7 @@ class RedisCommands <: CommandHandler {
1923
1923
  case None => ()
1924
1924
  }
1925
1925
  if (!exited) {
1926
- eprintln("[cj-tauri] redis: 旧会话的订阅线程未按时退出,socket 已关(状态泄漏一次,好过卡死命令)")
1926
+ logd("[cj-tauri] redis: 旧会话的订阅线程未按时退出,socket 已关(状态泄漏一次,好过卡死命令)")
1927
1927
  }
1928
1928
  }
1929
1929
  }
@@ -1998,7 +1998,7 @@ func redisSubLoop(sess: RedisSession): Unit {
1998
1998
  sess.subAlive = false
1999
1999
  sess.subPendingAcks = 0
2000
2000
  sess.lock.unlock()
2001
- eprintln("[cj-tauri] redis sub: 读线程结束(订阅连接已收)")
2001
+ logd("[cj-tauri] redis sub: 读线程结束(订阅连接已收)")
2002
2002
  redisEmitState(sess)
2003
2003
  }
2004
2004
 
@@ -2036,7 +2036,7 @@ func redisSubDrain(sess: RedisSession): Unit {
2036
2036
  func redisSubDispatch(sess: RedisSession, v: RespValue): Unit {
2037
2037
  let items = respItemsOrEmpty(v)
2038
2038
  if (items.size == 0) {
2039
- eprintln("[cj-tauri] redis sub: 收到空的推送数组(未处理)")
2039
+ logd("[cj-tauri] redis sub: 收到空的推送数组(未处理)")
2040
2040
  return
2041
2041
  }
2042
2042
  let kind = respValueText(items[0])
@@ -2060,9 +2060,9 @@ func redisSubDispatch(sess: RedisSession, v: RespValue): Unit {
2060
2060
  if (items.size >= 3) {
2061
2061
  count = respValueText(items[2])
2062
2062
  }
2063
- eprintln("[cj-tauri] redis sub: ${kind} ${who}(该连接当前订阅数=${count}, 待确认=${pending})")
2063
+ logd("[cj-tauri] redis sub: ${kind} ${who}(该连接当前订阅数=${count}, 待确认=${pending})")
2064
2064
  } else {
2065
- eprintln("[cj-tauri] redis sub: 收到认不出的推送形状 ${respBrief(v)}(未处理)")
2065
+ logd("[cj-tauri] redis sub: 收到认不出的推送形状 ${respBrief(v)}(未处理)")
2066
2066
  }
2067
2067
  }
2068
2068
 
@@ -2089,7 +2089,7 @@ func redisSubMessage(sess: RedisSession, pattern: String, channel: String, raw:
2089
2089
  obj.put("payloadHex", JsonString(respHexOfBytes(shown)))
2090
2090
  obj.put("bytes", JsonInt(total))
2091
2091
  obj.put("truncated", JsonBool(cut < total))
2092
- eprintln("[cj-tauri] redis message: channel=${channel} pattern=${redisClip(pattern, 32)}" +
2092
+ logd("[cj-tauri] redis message: channel=${channel} pattern=${redisClip(pattern, 32)}" +
2093
2093
  " bytes=${total} truncated=${cut < total}")
2094
2094
  redisRecordMessage(sess, obj)
2095
2095
  }
@@ -127,14 +127,14 @@ func sqliteAuthorizer(app: CPointer<Unit>, code: Int32, arg1: CString, arg2: CSt
127
127
  let _ = dbName
128
128
  let _ = triggerName
129
129
  if (code == SQLITE_ATTACH || code == SQLITE_DETACH) {
130
- eprintln("[cj-tauri] sqlite denied: attach/detach is not allowed (code=${code})")
130
+ logd("[cj-tauri] sqlite denied: attach/detach is not allowed (code=${code})")
131
131
  return SQLITE_DENY
132
132
  }
133
133
  if (code == SQLITE_FUNCTION) {
134
134
  // arg1 是被调用的函数名:只拒能加载原生代码的那个,其余内置函数照常放行
135
135
  let fnName = sqliteCString(arg1)
136
136
  if (fnName == "load_extension") {
137
- eprintln("[cj-tauri] sqlite denied: load_extension() is not allowed")
137
+ logd("[cj-tauri] sqlite denied: load_extension() is not allowed")
138
138
  return SQLITE_DENY
139
139
  }
140
140
  }
@@ -164,7 +164,7 @@ func sqliteCloseQuietly(db: CPointer<Unit>): Unit {
164
164
  }
165
165
  let rc = unsafe { sqlite3_close(db) }
166
166
  if (rc != SQLITE_OK) {
167
- eprintln("[cj-tauri] sqlite close returned ${rc}")
167
+ logd("[cj-tauri] sqlite close returned ${rc}")
168
168
  }
169
169
  }
170
170
 
@@ -113,7 +113,7 @@ public class StoreBackend {
113
113
  let parsed = JsonValue.fromStr(text)
114
114
  match (parsed.kind()) {
115
115
  case JsonKind.JsObject => this.root = parsed.asObject()
116
- case _ => eprintln("[cj-tauri] store 文件不是 JSON 对象,本轮从空开始:${this.path}")
116
+ case _ => logd("[cj-tauri] store 文件不是 JSON 对象,本轮从空开始:${this.path}")
117
117
  }
118
118
  } catch (e: Exception) {
119
119
  // 第一次跑就是这条路径——没有 store 文件是正常状态,不是错误
@@ -134,11 +134,11 @@ public class StoreBackend {
134
134
  } catch (e: Exception) {
135
135
  // rename 失败(跨目录/被占用等):回落直写目标文件,别让数据丢在 tmp 里
136
136
  File.writeTo(this.path, text.toArray())
137
- eprintln("[cj-tauri] store 原子替换失败已回落直写:${e}")
137
+ logd("[cj-tauri] store 原子替换失败已回落直写:${e}")
138
138
  }
139
139
  return true
140
140
  } catch (e: Exception) {
141
- eprintln("[cj-tauri] store 写盘失败:${e}(路径 ${this.path},本轮改动只在内存里)")
141
+ logd("[cj-tauri] store 写盘失败:${e}(路径 ${this.path},本轮改动只在内存里)")
142
142
  return false
143
143
  }
144
144
  }
@@ -185,7 +185,7 @@ public class WsCommands <: CommandHandler {
185
185
  sockOpt = Some(pair[0])
186
186
  } catch (e: Exception) {
187
187
  client.close()
188
- eprintln("[cj-tauri] ws: connect failed: ${e}")
188
+ logd("[cj-tauri] ws: connect failed: ${e}")
189
189
  throw CommandException("ws: connect failed: ${e.message}")
190
190
  }
191
191
  // 登记会话并起读线程
@@ -203,7 +203,7 @@ public class WsCommands <: CommandHandler {
203
203
  // 编译器判 unreachable pattern——零警告门禁下直接取用
204
204
  let sock = sockOpt.getOrThrow()
205
205
  spawn { => wsReaderThread(this.sess, sock, client, gen) }
206
- eprintln("[cj-tauri] ws: connected ${url} (host=${host})")
206
+ logd("[cj-tauri] ws: connected ${url} (host=${host})")
207
207
  wsEmitState(this.sess, CJ_WS_STATE_CONNECTED, "")
208
208
  let obj = JsonObject()
209
209
  obj.put("connected", JsonBool(true))
@@ -270,7 +270,7 @@ public class WsCommands <: CommandHandler {
270
270
  case None => ()
271
271
  }
272
272
  if (was) {
273
- eprintln("[cj-tauri] ws: closed by command")
273
+ logd("[cj-tauri] ws: closed by command")
274
274
  wsEmitState(this.sess, CJ_WS_STATE_CLOSED, "")
275
275
  }
276
276
  let obj = JsonObject()
@@ -309,7 +309,7 @@ public class WsCommands <: CommandHandler {
309
309
  }
310
310
 
311
311
  private func rejectOutsideScope(url: String, why: String): Nothing {
312
- eprintln("[cj-tauri] scope denied (ws): ${url} -> ${why}")
312
+ logd("[cj-tauri] scope denied (ws): ${url} -> ${why}")
313
313
  throw CommandException("ws: host is outside the authorized scope")
314
314
  }
315
315
 
@@ -347,7 +347,7 @@ func wsEmitState(sess: WsSession, state: String, err: String): Unit {
347
347
  obj.put("tx", JsonInt(sess.txCount))
348
348
  sess.lock.unlock()
349
349
  obj.put("error", JsonString(err))
350
- eprintln("[cj-tauri] ws: state=${state} error=${err}")
350
+ logd("[cj-tauri] ws: state=${state} error=${err}")
351
351
  wsEmit(sess, "ws:state", obj)
352
352
  }
353
353
 
@@ -421,7 +421,7 @@ func wsReaderThread(sess: WsSession, sock: WebSocket, client: Client, gen: Int64
421
421
  continue
422
422
  }
423
423
  if (buf.size + payload.size > CJ_WS_MAX_FRAME) {
424
- eprintln("[cj-tauri] ws: 分帧重组超限(>${CJ_WS_MAX_FRAME} 字节),断开连接")
424
+ logd("[cj-tauri] ws: 分帧重组超限(>${CJ_WS_MAX_FRAME} 字节),断开连接")
425
425
  break
426
426
  }
427
427
  if (ft == WebSocketFrameType.ContinuationWebFrame) {
@@ -455,7 +455,7 @@ func wsReaderThread(sess: WsSession, sock: WebSocket, client: Client, gen: Int64
455
455
  }
456
456
  sess.lock.unlock()
457
457
  if (mine) {
458
- eprintln("[cj-tauri] ws: connection closed by peer")
458
+ logd("[cj-tauri] ws: connection closed by peer")
459
459
  wsEmitState(sess, CJ_WS_STATE_CLOSED, "connection closed by peer")
460
460
  }
461
461
  // 资源兜底:连接已断或已被替换,double-close 的错吞掉即可
@@ -41,7 +41,7 @@ public class BackgroundProcess {
41
41
  */
42
42
  public func stop(): Unit {
43
43
  if (!hiddenPidKill(pid)) {
44
- eprintln("[cj-tauri] 终止子进程失败(pid=${pid})")
44
+ logd("[cj-tauri] 终止子进程失败(pid=${pid})")
45
45
  }
46
46
  }
47
47
  }
@@ -58,13 +58,13 @@ public class BackgroundProcess {
58
58
  * ```cangjie
59
59
  * match (launchHidden(bin, ["web", "--port", "8765"])) {
60
60
  * case Some(p) => backendPid = p.processId()
61
- * case None => eprintln("[app] 后端没起来")
61
+ * case None => logd("[app] 后端没起来")
62
62
  * }
63
63
  * ```
64
64
  */
65
65
  public func launchHidden(exePath: String, args: Array<String>): Option<BackgroundProcess> {
66
66
  if (exePath.isEmpty()) {
67
- eprintln("[cj-tauri] launchHidden: 程序路径为空")
67
+ logd("[cj-tauri] launchHidden: 程序路径为空")
68
68
  return None
69
69
  }
70
70
  let wire = match (joinHiddenArgs(args)) {
@@ -93,7 +93,7 @@ public func joinHiddenArgs(args: Array<String>): Option<String> {
93
93
  var first = true
94
94
  for (a in args) {
95
95
  if (let Some(_) <- a.indexOf(sep)) {
96
- eprintln("[cj-tauri] launchHidden: 参数里不允许出现 0x1F 分隔符(${a})")
96
+ logd("[cj-tauri] launchHidden: 参数里不允许出现 0x1F 分隔符(${a})")
97
97
  return None
98
98
  }
99
99
  if (!first) {
@@ -139,7 +139,7 @@ func spawnHiddenPid(exePath: String, argsWire: String): Int64 {
139
139
  @When[env == "ohos"]
140
140
  func spawnHiddenPid(exePath: String, argsWire: String): Int64 {
141
141
  let _ = argsWire
142
- eprintln("[cj-tauri] 本平台没有 C 桥,无法后台静默启动:${exePath}")
142
+ logd("[cj-tauri] 本平台没有 C 桥,无法后台静默启动:${exePath}")
143
143
  return 0
144
144
  }
145
145