cj-tauri 2.2.0 → 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.
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
 
@@ -1,6 +1,7 @@
1
1
  package cjTauri.tests
2
2
 
3
3
  import cjTauri.*
4
+ import std.collection.*
4
5
  import std.unittest.*
5
6
  import std.unittest.testmacro.*
6
7
 
@@ -60,3 +61,68 @@ func testLogPathOrDefaultPrefersEnvOverPlatformDir(): Unit {
60
61
  @Expect(d.contains("cj-tauri"), true)
61
62
  @Expect(d == defaultLogPath("music"), true)
62
63
  }
64
+
65
+ /*
66
+ * 鸿蒙 hilog 分片器(2026-11-12):hilog 对单条日志有长度上限,框架的超长诊断行要切多条送出去。
67
+ * 分片器与平台无关、无 FFI 依赖,所以在本机能验——鸿蒙分支其余部分编不了(本机 SDK 只有
68
+ * linux / windows 两个目标),能本地验证的部分别留成「未验证」。
69
+ */
70
+
71
+ @Test
72
+ func testHilogSplitKeepsShortLineIntact(): Unit {
73
+ @Expect(hilogSplit("", 1000).size, 1)
74
+ @Expect(hilogSplit("", 1000)[0], "")
75
+ @Expect(hilogSplit("abc", 1000).size, 1)
76
+ // 恰好等于预算也是单片:不因「相等」多切一条空的出来
77
+ @Expect(hilogSplit("abcdefgh", 8).size, 1)
78
+ }
79
+
80
+ @Test
81
+ func testHilogSplitChunksLongAsciiLine(): Unit {
82
+ let sb = StringBuilder()
83
+ for (_ in 0..2500) {
84
+ sb.append("x")
85
+ }
86
+ let line = sb.toString()
87
+ let parts = hilogSplit(line, 1000)
88
+ @Expect(parts.size, 3)
89
+ var joined = ""
90
+ for (p in parts) {
91
+ @Expect(p.size <= 1000, true)
92
+ joined = joined + p
93
+ }
94
+ @Expect(joined, line) // 不丢内容、不改内容:取证要对得上原文
95
+ }
96
+
97
+ @Test
98
+ func testHilogSplitNeverCutsInsideUtf8Char(): Unit {
99
+ // 400 个汉字 = 1200 字节;1000 字节预算硬切就落在第 334 个汉字中间
100
+ let sb = StringBuilder()
101
+ for (_ in 0..400) {
102
+ sb.append("汉")
103
+ }
104
+ let line = sb.toString()
105
+ let parts = hilogSplit(line, 1000)
106
+ @Expect(parts.size, 2)
107
+ var joined = ""
108
+ for (p in parts) {
109
+ // 分片器内部走 String.fromUtf8(非法 UTF-8 会抛),这里再钉住两条可观测性质
110
+ @Expect(p.size <= 1000, true)
111
+ @Expect(p.size % 3, 0) // 汉字 3 字节:每片都落在整字边界上
112
+ joined = joined + p
113
+ }
114
+ @Expect(joined, line)
115
+ }
116
+
117
+ @Test
118
+ func testHilogSplitSurvivesTinyBudget(): Unit {
119
+ // 预算比一个汉字还小:按 4 字节下限走,仍须是合法 UTF-8 且能拼回原文
120
+ let line = "仓颉日志"
121
+ let parts = hilogSplit(line, 2)
122
+ var joined = ""
123
+ for (p in parts) {
124
+ joined = joined + p
125
+ }
126
+ @Expect(joined, line)
127
+ @Expect(parts.size > 0, true)
128
+ }
@@ -212,7 +212,7 @@ func testStoreConcurrentWritersKeepFileValid(): Unit {
212
212
  while (j < 25) {
213
213
  let r = s.set(tag, JsonInt(n * 100 + j))
214
214
  if (!r) {
215
- eprintln("[store-test] ${tag} 第 ${j} 轮写盘失败")
215
+ logd("[store-test] ${tag} 第 ${j} 轮写盘失败")
216
216
  }
217
217
  j++
218
218
  }
@@ -298,7 +298,7 @@ func testScopeSymlinkEscapeIsDenied(): Unit {
298
298
  try {
299
299
  SymbolicLink.create("${base}/target/scope-sym/escape.txt", to: outside)
300
300
  } catch (e: Exception) {
301
- eprintln("[skip] testScopeSymlinkEscapeIsDenied: 本机无法创建符号链接(${e.message})")
301
+ logd("[skip] testScopeSymlinkEscapeIsDenied: 本机无法创建符号链接(${e.message})")
302
302
  removeIfExists(outside)
303
303
  return
304
304
  }
@@ -323,7 +323,7 @@ func testScopeSymlinkInsideIsAllowed(): Unit {
323
323
  try {
324
324
  SymbolicLink.create("${base}/target/scope-sym2/link.txt", to: "${base}/target/scope-sym2/inner.txt")
325
325
  } catch (e: Exception) {
326
- eprintln("[skip] testScopeSymlinkInsideIsAllowed: 本机无法创建符号链接(${e.message})")
326
+ logd("[skip] testScopeSymlinkInsideIsAllowed: 本机无法创建符号链接(${e.message})")
327
327
  return
328
328
  }
329
329
  let ctx = fsCtxWithScopes([scopeCwdPath() + "/target/**"], [])
package/src/tray.cj CHANGED
@@ -51,7 +51,7 @@ public class TrayModel {
51
51
  let flat = ArrayList<MenuItem>()
52
52
  for (it in this.items) {
53
53
  if (TrayModel.isSubmenu(it.kind)) {
54
- eprintln("[cj-tauri] tray: submenu item dropped (v1 tray menu is flat): ${it.label}")
54
+ logd("[cj-tauri] tray: submenu item dropped (v1 tray menu is flat): ${it.label}")
55
55
  continue
56
56
  }
57
57
  flat.add(it)
@@ -60,7 +60,7 @@ public class TrayModel {
60
60
  var icon = this.icon
61
61
  var tooltip = this.tooltip
62
62
  if (TrayModel.hasStructChar(icon) || TrayModel.hasStructChar(tooltip)) {
63
- eprintln("[cj-tauri] tray: icon/tooltip contains tab or newline - dropped to empty")
63
+ logd("[cj-tauri] tray: icon/tooltip contains tab or newline - dropped to empty")
64
64
  icon = ""
65
65
  tooltip = ""
66
66
  }
package/src/version.cj CHANGED
@@ -9,7 +9,7 @@ package cjTauri
9
9
  * - cli/src/project.cj 的 cliVersion()
10
10
  * - CHANGELOG.md 顶部第一个已发版段
11
11
  */
12
- public let CJ_TAURI_VERSION = "2.2.0"
12
+ public let CJ_TAURI_VERSION = "2.3.0"
13
13
 
14
14
  /**
15
15
  * IPC 报文协议版本(报文形状是跨层契约,加版本字段是协议治理惯例):事件 / 回执信封的 `protocol` 字段