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/bin/cj-tauri.js +87 -0
- package/cjpm.toml +1 -1
- package/cli/cjpm.toml +1 -1
- package/cli/src/doctor.cj +1 -1
- package/cli/src/manifest.cj +5 -2
- package/cli/src/project.cj +1 -1
- package/cli/templates/ohos-skeleton/entry/cjpm.toml +7 -1
- package/package.json +1 -1
- package/src/app.cj +1 -1
- package/src/app_events.cj +5 -5
- package/src/app_host_ops.cj +8 -8
- package/src/app_run.cj +8 -8
- package/src/capability.cj +3 -3
- package/src/capability_loader.cj +8 -8
- package/src/embedded_assets.cj +5 -5
- package/src/host.cj +6 -6
- package/src/host_arkweb.cj +31 -31
- package/src/host_webkit.cj +7 -7
- package/src/host_webview2.cj +6 -6
- package/src/ipc_hub.cj +8 -8
- package/src/launch.cj +1 -1
- package/src/log_bridge.cj +141 -13
- package/src/logging.cj +2 -2
- package/src/menu.cj +1 -1
- package/src/plugin.cj +6 -6
- package/src/plugins/http/http_ohos.cj +2 -2
- package/src/plugins/http/plugin_http.cj +2 -2
- package/src/plugins/mqtt/plugin_mqtt.cj +4 -4
- package/src/plugins/redis/plugin_redis.cj +20 -20
- package/src/plugins/sqlite/sqlite_ffi.cj +3 -3
- package/src/plugins/store/plugin_store.cj +3 -3
- package/src/plugins/ws/plugin_ws.cj +7 -7
- package/src/process_hidden.cj +5 -5
- package/src/tests/logging_test.cj +66 -0
- package/src/tests/plugin_store_test.cj +1 -1
- package/src/tests/scope_test.cj +2 -2
- package/src/tray.cj +2 -2
- package/src/version.cj +1 -1
package/src/host_arkweb.cj
CHANGED
|
@@ -89,7 +89,7 @@ public class ArkWebRuntime {
|
|
|
89
89
|
*/
|
|
90
90
|
public static func configure(filesDir: String): Unit {
|
|
91
91
|
if (filesDir.size == 0) {
|
|
92
|
-
|
|
92
|
+
logd("[cj-tauri] ArkWebRuntime.configure: filesDir is empty, run(html) will be rejected")
|
|
93
93
|
return
|
|
94
94
|
}
|
|
95
95
|
ArkWebRuntime.sandboxDir = filesDir
|
|
@@ -98,10 +98,10 @@ public class ArkWebRuntime {
|
|
|
98
98
|
let r = chdir(cpath)
|
|
99
99
|
LibC.free(cpath)
|
|
100
100
|
if (r != 0) {
|
|
101
|
-
|
|
101
|
+
logd("[cj-tauri] chdir(${filesDir}) failed: errno=${r}(相对路径落盘仍以原 cwd 为基准)")
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
logd("[cj-tauri] ArkWeb sandbox: ${filesDir}")
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/** 登记一个宿主(构造时调;同一 label 重复登记=替换,与进程级唯一窗口的语义一致) */
|
|
@@ -254,7 +254,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
254
254
|
public init(label: String) {
|
|
255
255
|
this.windowLabel = label
|
|
256
256
|
ArkWebRuntime.register(this)
|
|
257
|
-
|
|
257
|
+
logd("[cj-tauri] ArkWeb host created: label=\"${label}\"")
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
public func label(): String {
|
|
@@ -272,7 +272,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
272
272
|
public func start(html: String): Unit {
|
|
273
273
|
this.pageHtml = html
|
|
274
274
|
this.pageUrl = this.writeHtmlToSandbox(html)
|
|
275
|
-
|
|
275
|
+
logd("[cj-tauri] ArkWeb page: label=\"${this.windowLabel}\" source=inline url=\"${this.pageUrl}\"")
|
|
276
276
|
}
|
|
277
277
|
|
|
278
278
|
/**
|
|
@@ -284,7 +284,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
284
284
|
public func startUrl(url: String): Unit {
|
|
285
285
|
this.pageHtml = ""
|
|
286
286
|
this.pageUrl = url
|
|
287
|
-
|
|
287
|
+
logd("[cj-tauri] ArkWeb page: label=\"${this.windowLabel}\" source=url url=\"${url}\"")
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
/**
|
|
@@ -339,18 +339,18 @@ public class ArkWebHost <: WebViewHost {
|
|
|
339
339
|
// 鸿蒙应用窗口由 Ability 的 WindowStage 决定,逻辑尺寸概念与桌面不同:
|
|
340
340
|
// 这里如实说明不生效,而不是假装设成功(能力位也不含任何窗口控制位)。
|
|
341
341
|
let _ = config
|
|
342
|
-
|
|
342
|
+
logd("[cj-tauri] ArkWeb: window config is managed by WindowStage on this platform (ignored)")
|
|
343
343
|
}
|
|
344
344
|
|
|
345
345
|
public func setDevTools(enabled: Bool): Unit {
|
|
346
346
|
this.devToolsEnabled = enabled
|
|
347
347
|
// 真正调 setWebDebuggingAccess 的时机在 UI 侧(controller 就绪之后)。
|
|
348
|
-
|
|
348
|
+
logd("[cj-tauri] ArkWeb: web debugging requested: ${enabled}")
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
public func openDevTools(): Unit {
|
|
352
352
|
// ArkWeb 的调试走「设备侧 Web 调试」通道,没有桌面那种独立 DevTools 窗口。
|
|
353
|
-
|
|
353
|
+
logd("[cj-tauri] ArkWeb: openDevTools is not available on this platform (use web debugging)")
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
/* ---- 菜单:框架存模型,应用侧用 bindMenu 画(见 arkweb_menu.cj 的类注释) ---- */
|
|
@@ -369,7 +369,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
369
369
|
rows = countMenuItems(parsed)
|
|
370
370
|
this.menuItemCount = rows
|
|
371
371
|
}
|
|
372
|
-
|
|
372
|
+
logd("[cj-tauri] ArkWeb: menu applied (${wire.size} bytes, ${rows} item(s), app-side bindMenu)")
|
|
373
373
|
}
|
|
374
374
|
|
|
375
375
|
/**
|
|
@@ -391,7 +391,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
|
-
|
|
394
|
+
logd("[cj-tauri] ArkWeb: menu item state id=\"${id}\" enabled=${enabled} checked=${checked} hit=${hit}")
|
|
395
395
|
}
|
|
396
396
|
|
|
397
397
|
/**
|
|
@@ -439,11 +439,11 @@ public class ArkWebHost <: WebViewHost {
|
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
if (!found) {
|
|
442
|
-
|
|
442
|
+
logd("[cj-tauri] ArkWeb: menu click ignored (id=\"${id}\" is not in the current menu)")
|
|
443
443
|
return
|
|
444
444
|
}
|
|
445
445
|
this.menuClickCount++
|
|
446
|
-
|
|
446
|
+
logd("[cj-tauri] ArkWeb: menu clicked id=\"${id}\" enabled=${enabled} checked=${checked}")
|
|
447
447
|
this.shellHandler("{\"kind\":\"menu\",\"id\":\"${arkWebJsonEscape(id)}\",\"enabled\":${enabled}," +
|
|
448
448
|
"\"checked\":${checked}}")
|
|
449
449
|
}
|
|
@@ -455,7 +455,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
455
455
|
public func setDragDropPolicy(enabled: Bool, files: Bool): Unit {
|
|
456
456
|
let _ = enabled
|
|
457
457
|
let _ = files
|
|
458
|
-
|
|
458
|
+
logd("[cj-tauri] ArkWeb: drag/drop policy unsupported (host capability bit is 0)")
|
|
459
459
|
}
|
|
460
460
|
|
|
461
461
|
public func setGlobalHotkeys(wire: String): Unit {
|
|
@@ -469,7 +469,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
469
469
|
public func setWindowVisible(visible: Bool): Unit {
|
|
470
470
|
this.visible = visible
|
|
471
471
|
// 可见性由 ArkUI 的组件树决定(`visibility` 属性),宿主只记状态供 UI 侧读取。
|
|
472
|
-
|
|
472
|
+
logd("[cj-tauri] ArkWeb: window visible -> ${visible}")
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
public func setMinimizeToTray(enabled: Bool): Unit {
|
|
@@ -500,7 +500,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
500
500
|
let _ = save
|
|
501
501
|
let _ = title
|
|
502
502
|
let _ = filter
|
|
503
|
-
|
|
503
|
+
logd("[cj-tauri] ArkWeb: native file dialog unsupported (needs a picker module)")
|
|
504
504
|
return ""
|
|
505
505
|
}
|
|
506
506
|
|
|
@@ -511,7 +511,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
511
511
|
|
|
512
512
|
public func showFolderDialog(title: String): String {
|
|
513
513
|
let _ = title
|
|
514
|
-
|
|
514
|
+
logd("[cj-tauri] ArkWeb: native folder dialog unsupported (needs a picker module)")
|
|
515
515
|
return ""
|
|
516
516
|
}
|
|
517
517
|
|
|
@@ -527,7 +527,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
527
527
|
*/
|
|
528
528
|
public func showMessageDialog(kind: String, title: String, message: String): Bool {
|
|
529
529
|
if (this.disposed) {
|
|
530
|
-
|
|
530
|
+
logd("[cj-tauri] ArkWeb dialog rejected: label=\"${this.windowLabel}\" (host disposed)")
|
|
531
531
|
return false
|
|
532
532
|
}
|
|
533
533
|
var id: Int64 = 0
|
|
@@ -538,7 +538,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
538
538
|
this.pendingDialogs.add(ArkWebDialogRequest(id, kind, title, message))
|
|
539
539
|
this.awaitingDialogs.add(id)
|
|
540
540
|
}
|
|
541
|
-
|
|
541
|
+
logd(
|
|
542
542
|
"[cj-tauri] ArkWeb dialog queued: label=\"${this.windowLabel}\" id=${id} kind=\"${kind}\" title=\"${title}\""
|
|
543
543
|
)
|
|
544
544
|
var waited: Int64 = 0
|
|
@@ -553,7 +553,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
553
553
|
}
|
|
554
554
|
}
|
|
555
555
|
if (answered) {
|
|
556
|
-
|
|
556
|
+
logd(
|
|
557
557
|
"[cj-tauri] ArkWeb dialog answered: label=\"${this.windowLabel}\" id=${id} confirmed=${confirmed}"
|
|
558
558
|
)
|
|
559
559
|
return confirmed
|
|
@@ -566,7 +566,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
566
566
|
this.dropPendingDialog(id)
|
|
567
567
|
this.dialogAnswers.remove(id)
|
|
568
568
|
}
|
|
569
|
-
|
|
569
|
+
logd(
|
|
570
570
|
"[cj-tauri] ArkWeb dialog timed out: label=\"${this.windowLabel}\" id=${id} after ${CJ_ARKWEB_DIALOG_WAIT_MS}ms (UI side never answered; this is NOT a user cancel)"
|
|
571
571
|
)
|
|
572
572
|
return false
|
|
@@ -605,12 +605,12 @@ public class ArkWebHost <: WebViewHost {
|
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
607
|
if (accepted) {
|
|
608
|
-
|
|
608
|
+
logd(
|
|
609
609
|
"[cj-tauri] ArkWeb dialog answer: label=\"${this.windowLabel}\" id=${id} confirmed=${confirmed}"
|
|
610
610
|
)
|
|
611
611
|
return
|
|
612
612
|
}
|
|
613
|
-
|
|
613
|
+
logd(
|
|
614
614
|
"[cj-tauri] ArkWeb dialog answer dropped: label=\"${this.windowLabel}\" id=${id} confirmed=${confirmed} (no longer awaiting)"
|
|
615
615
|
)
|
|
616
616
|
}
|
|
@@ -649,7 +649,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
649
649
|
public func notify(title: String, body: String): Bool {
|
|
650
650
|
let _ = title
|
|
651
651
|
let _ = body
|
|
652
|
-
|
|
652
|
+
logd("[cj-tauri] ArkWeb: notification unsupported (host capability bit is 0)")
|
|
653
653
|
return false
|
|
654
654
|
}
|
|
655
655
|
|
|
@@ -680,7 +680,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
680
680
|
}
|
|
681
681
|
this.quitFlag = true
|
|
682
682
|
ArkWebRuntime.requestQuit()
|
|
683
|
-
|
|
683
|
+
logd("[cj-tauri] ArkWeb: quit requested: label=\"${this.windowLabel}\" (app should terminateSelf)")
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
public func setMessageHandler(handler: (String) -> Unit): Unit {
|
|
@@ -697,7 +697,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
697
697
|
}
|
|
698
698
|
this.disposed = true
|
|
699
699
|
ArkWebRuntime.unregister(this.windowLabel)
|
|
700
|
-
|
|
700
|
+
logd(
|
|
701
701
|
"[cj-tauri] ArkWeb host disposed: label=\"${this.windowLabel}\" pageBegin=${this.pageBeginCount} pageEnd=${this.pageEndCount} jsIn=${this.jsInCount} dialogRequested=${this.dialogRequestCount} dialogAnswered=${this.dialogAnswerCount}"
|
|
702
702
|
)
|
|
703
703
|
}
|
|
@@ -786,7 +786,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
786
786
|
synchronized(ArkWebRuntime.queueLock) {
|
|
787
787
|
this.pageBeginCount += 1
|
|
788
788
|
}
|
|
789
|
-
|
|
789
|
+
logd("[cj-tauri] ArkWeb page begin: label=\"${this.windowLabel}\" count=${this.pageBeginCount}")
|
|
790
790
|
}
|
|
791
791
|
|
|
792
792
|
/** 页面加载结束(UI 侧回调);`system:host` 的取证就看这两个计数是否对得上 */
|
|
@@ -794,7 +794,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
794
794
|
synchronized(ArkWebRuntime.queueLock) {
|
|
795
795
|
this.pageEndCount += 1
|
|
796
796
|
}
|
|
797
|
-
|
|
797
|
+
logd("[cj-tauri] ArkWeb page end: label=\"${this.windowLabel}\" count=${this.pageEndCount}")
|
|
798
798
|
}
|
|
799
799
|
|
|
800
800
|
/**
|
|
@@ -812,7 +812,7 @@ public class ArkWebHost <: WebViewHost {
|
|
|
812
812
|
// 桥脚本产生,形状固定;解析失败会把 reload 静默丢掉,反而更难查。
|
|
813
813
|
match (raw.indexOf("\"type\":\"reload\"")) {
|
|
814
814
|
case Some(_) =>
|
|
815
|
-
|
|
815
|
+
logd("[cj-tauri] ArkWeb: reload requested by page: label=\"${this.windowLabel}\"")
|
|
816
816
|
this.reload()
|
|
817
817
|
return
|
|
818
818
|
case None => ()
|
|
@@ -860,14 +860,14 @@ public class ArkWebHost <: WebViewHost {
|
|
|
860
860
|
*/
|
|
861
861
|
private func writeHtmlToSandbox(html: String): String {
|
|
862
862
|
if (ArkWebRuntime.sandboxDir.size == 0) {
|
|
863
|
-
|
|
863
|
+
logd("[cj-tauri] ArkWeb: run(html) rejected: ArkWebRuntime.configure(filesDir) was not called")
|
|
864
864
|
return ""
|
|
865
865
|
}
|
|
866
866
|
let path = "${ArkWebRuntime.sandboxDir}/cj-tauri-${this.windowLabel}.html"
|
|
867
867
|
try {
|
|
868
868
|
File.writeTo(path, this.injectBootstrap(html).toArray())
|
|
869
869
|
} catch (e: Exception) {
|
|
870
|
-
|
|
870
|
+
logd("[cj-tauri] ArkWeb: failed to write page to sandbox: ${path}: ${e.message}")
|
|
871
871
|
return ""
|
|
872
872
|
}
|
|
873
873
|
return "file://${path}"
|
package/src/host_webkit.cj
CHANGED
|
@@ -231,7 +231,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
231
231
|
// 本窗口的 shell 事件(菜单点击等)回调:TauriApp 装配时经 setShellHandler 覆盖它做分发,
|
|
232
232
|
// 未覆盖时只留一行 stderr——菜单点了没人管,至少能在日志里看见。
|
|
233
233
|
public var shellHandler: (String) -> Unit = { json =>
|
|
234
|
-
|
|
234
|
+
logd("[cj-tauri] shell event (no handler): ${json}")
|
|
235
235
|
}
|
|
236
236
|
// 窗口配置(标题 / 尺寸),start() 前由 TauriApp 注入
|
|
237
237
|
private var config: WindowConfig = WindowConfig()
|
|
@@ -359,7 +359,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
359
359
|
let rc = cj_bridge_set_titlebar_subtitle(this.handle, LibC.mallocCString(text))
|
|
360
360
|
if (rc != 0) {
|
|
361
361
|
// 能力位说支持、这次却没写进去:留一行凭证(宿主未就绪 / 文本超 1024 字节)
|
|
362
|
-
|
|
362
|
+
logd("[cj-tauri] titlebar subtitle rejected: rc=${rc}")
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
}
|
|
@@ -409,7 +409,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
409
409
|
}
|
|
410
410
|
case None =>
|
|
411
411
|
// 外观修饰失败不该拦着开窗,但要在日志里留凭证
|
|
412
|
-
|
|
412
|
+
logd("[cj-tauri] setOwnerWindow(${ownerLabel}): 该窗口尚未登记,跳过")
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
|
|
@@ -510,7 +510,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
510
510
|
rc = cj_bridge_clipboard_write_text(this.handle, LibC.mallocCString(text))
|
|
511
511
|
}
|
|
512
512
|
if (rc != 0) {
|
|
513
|
-
|
|
513
|
+
logd("[cj-tauri] clipboard write failed: code=${rc}")
|
|
514
514
|
}
|
|
515
515
|
return rc == 0
|
|
516
516
|
}
|
|
@@ -560,7 +560,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
560
560
|
}
|
|
561
561
|
if (rc != 0) {
|
|
562
562
|
// -4 = 本平台未实现:这是静态事实,stderr 一行说清,不算异常
|
|
563
|
-
|
|
563
|
+
logd("[cj-tauri] notification failed: code=${rc}")
|
|
564
564
|
}
|
|
565
565
|
return rc == 0
|
|
566
566
|
}
|
|
@@ -692,7 +692,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
692
692
|
if (released) {
|
|
693
693
|
this.handle = CPointer<Unit>()
|
|
694
694
|
} else {
|
|
695
|
-
|
|
695
|
+
logd("[cj-tauri] dispose: 宿主线程未结束,句柄保留(可再调一次 dispose 重试)")
|
|
696
696
|
}
|
|
697
697
|
}
|
|
698
698
|
}
|
|
@@ -704,6 +704,6 @@ func hostOnMessage(json: CString): Unit {
|
|
|
704
704
|
try {
|
|
705
705
|
HostGlobals.onMessage(json.toString())
|
|
706
706
|
} catch (e: Exception) {
|
|
707
|
-
|
|
707
|
+
logd("[cj-tauri] host callback error: ${e}")
|
|
708
708
|
}
|
|
709
709
|
}
|
package/src/host_webview2.cj
CHANGED
|
@@ -233,7 +233,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
233
233
|
// 本窗口的 shell 事件(菜单点击等)回调:TauriApp 装配时经 setShellHandler 覆盖它做分发,
|
|
234
234
|
// 未覆盖时只留一行 stderr——菜单点了没人管,至少能在日志里看见。
|
|
235
235
|
public var shellHandler: (String) -> Unit = { json =>
|
|
236
|
-
|
|
236
|
+
logd("[cj-tauri] shell event (no handler): ${json}")
|
|
237
237
|
}
|
|
238
238
|
// 窗口配置(标题 / 尺寸),start() 前由 TauriApp 注入
|
|
239
239
|
private var config: WindowConfig = WindowConfig()
|
|
@@ -411,7 +411,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
411
411
|
}
|
|
412
412
|
case None =>
|
|
413
413
|
// 外观修饰失败不该拦着开窗,但要在日志里留凭证
|
|
414
|
-
|
|
414
|
+
logd("[cj-tauri] setOwnerWindow(${ownerLabel}): 该窗口尚未登记,跳过")
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
|
|
@@ -510,7 +510,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
510
510
|
rc = cj_bridge_clipboard_write_text(this.handle, LibC.mallocCString(text))
|
|
511
511
|
}
|
|
512
512
|
if (rc != 0) {
|
|
513
|
-
|
|
513
|
+
logd("[cj-tauri] clipboard write failed: code=${rc}")
|
|
514
514
|
}
|
|
515
515
|
return rc == 0
|
|
516
516
|
}
|
|
@@ -560,7 +560,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
560
560
|
}
|
|
561
561
|
if (rc != 0) {
|
|
562
562
|
// Windows 桩阶段返回 -4(未实现):静态事实,stderr 一行说清,不算异常
|
|
563
|
-
|
|
563
|
+
logd("[cj-tauri] notification failed: code=${rc}")
|
|
564
564
|
}
|
|
565
565
|
return rc == 0
|
|
566
566
|
}
|
|
@@ -693,7 +693,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
693
693
|
if (released) {
|
|
694
694
|
this.handle = CPointer<Unit>()
|
|
695
695
|
} else {
|
|
696
|
-
|
|
696
|
+
logd("[cj-tauri] dispose: 宿主线程未结束,句柄保留(可再调一次 dispose 重试)")
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
}
|
|
@@ -705,6 +705,6 @@ func hostOnMessage(json: CString): Unit {
|
|
|
705
705
|
try {
|
|
706
706
|
HostGlobals.onMessage(json.toString())
|
|
707
707
|
} catch (e: Exception) {
|
|
708
|
-
|
|
708
|
+
logd("[cj-tauri] host callback error: ${e}")
|
|
709
709
|
}
|
|
710
710
|
}
|
package/src/ipc_hub.cj
CHANGED
|
@@ -174,7 +174,7 @@ public class IpcHub {
|
|
|
174
174
|
match (this.capabilities.scopeForPlugin(plugin)) {
|
|
175
175
|
case Some(rule) =>
|
|
176
176
|
if (!scopeAllows(rule, resolved)) {
|
|
177
|
-
|
|
177
|
+
logd("[cj-tauri] scope denied (${plugin}): ${rawPath} -> ${resolved}")
|
|
178
178
|
throw CommandException("${plugin}: path is outside the authorized scope")
|
|
179
179
|
}
|
|
180
180
|
case None => ()
|
|
@@ -221,7 +221,7 @@ public class IpcHub {
|
|
|
221
221
|
}
|
|
222
222
|
// 两条解析都不认:只要报文里读得出 id 就回一条 reject——前端那条 promise 否则会永久 pending,
|
|
223
223
|
// 比一条明确的报错难排查得多(前端 invoke 没有超时参数)。
|
|
224
|
-
|
|
224
|
+
logd("[cj-tauri] invalid IPC message: ${raw}")
|
|
225
225
|
if (let Some(id) <- IpcMessage.peekId(raw)) {
|
|
226
226
|
// 报文非法时读不出窗口,只能广播一份:id 只会挂在某一个页面的 pending 上,
|
|
227
227
|
// 别的窗口的 _dispatch 找不到它、忽略即可——这样发起方那条 promise 才不会永久 pending。
|
|
@@ -300,10 +300,10 @@ public class IpcHub {
|
|
|
300
300
|
// 应用级拒绝(作者主动抛的业务失败)也要留痕:前端可能压根没接 catch,
|
|
301
301
|
// 只回 reject 的话「这条命令失败了」在页面之外毫无线索——事件监听器路早有同款日志。
|
|
302
302
|
// 与下面的非预期失败分开措辞,便于 `grep command rejected` / `grep command failed` 分流。
|
|
303
|
-
|
|
303
|
+
logd("[cj-tauri] command rejected (${req.cmd}): ${e.message}")
|
|
304
304
|
this.reject(req.id, e.message, req.window)
|
|
305
305
|
} catch (e: Exception) {
|
|
306
|
-
|
|
306
|
+
logd("[cj-tauri] command failed (${req.cmd}): ${e}")
|
|
307
307
|
this.reject(req.id, "command failed: ${e}", req.window)
|
|
308
308
|
}
|
|
309
309
|
}
|
|
@@ -325,7 +325,7 @@ public class IpcHub {
|
|
|
325
325
|
*/
|
|
326
326
|
private func handleEmit(req: EmitRequest): Unit {
|
|
327
327
|
if (!this.capabilities.canEmit(req.event)) {
|
|
328
|
-
|
|
328
|
+
logd("[cj-tauri] event not allowed: ${req.event}")
|
|
329
329
|
this.reject(req.id, "event not allowed: ${req.event}", req.window)
|
|
330
330
|
return
|
|
331
331
|
}
|
|
@@ -341,7 +341,7 @@ public class IpcHub {
|
|
|
341
341
|
try {
|
|
342
342
|
h(req.payload)
|
|
343
343
|
} catch (e: Exception) {
|
|
344
|
-
|
|
344
|
+
logd("[cj-tauri] event listener failed (${req.event}): ${e}")
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
case None => ()
|
|
@@ -368,7 +368,7 @@ public class IpcHub {
|
|
|
368
368
|
*/
|
|
369
369
|
public func emitLatest(event: String, payload: JsonValue, window: String): Unit {
|
|
370
370
|
if (!this.capabilities.canEmit(event)) {
|
|
371
|
-
|
|
371
|
+
logd("[cj-tauri] event not allowed: ${event}")
|
|
372
372
|
return
|
|
373
373
|
}
|
|
374
374
|
this.jsSink(IpcMessage.eventLatest(event, payload, window), window)
|
|
@@ -382,7 +382,7 @@ public class IpcHub {
|
|
|
382
382
|
*/
|
|
383
383
|
public func emitToWindow(event: String, payload: JsonValue, window: String): Unit {
|
|
384
384
|
if (!this.capabilities.canEmit(event)) {
|
|
385
|
-
|
|
385
|
+
logd("[cj-tauri] event not allowed: ${event}")
|
|
386
386
|
return
|
|
387
387
|
}
|
|
388
388
|
this.jsSink(IpcMessage.event(event, payload, window), window)
|
package/src/launch.cj
CHANGED
|
@@ -29,7 +29,7 @@ public func launch(spec: AppSpec): Unit {
|
|
|
29
29
|
|
|
30
30
|
/** 注入上下文的变体:测试给假上下文;鸿蒙侧给 Platform.mobile(filesDir) */
|
|
31
31
|
public func launchWith(spec: AppSpec, context: AppContext): Unit {
|
|
32
|
-
|
|
32
|
+
logd("[cj-tauri] launch:${spec.name}(os=${context.target.os} display=${context.target.display})")
|
|
33
33
|
let app = assemble(spec)
|
|
34
34
|
app.run(spec.pageSource)
|
|
35
35
|
}
|
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
|
-
*
|
|
6
|
+
* 日志出口桥(RFC-003 第 5 期 + 2026-11-12 鸿蒙 hilog 收口)。
|
|
6
7
|
*
|
|
7
|
-
*
|
|
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
|
-
*
|
|
16
|
-
* 应用进程 signal:11,AbilityStage.onCreate
|
|
17
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
/**
|
|
231
|
+
/** 鸿蒙侧:出口是 hilog,返回是否真的送出去了(调用方据返回值如实回报,不冒充已写入) */
|
|
103
232
|
@When[env == "ohos"]
|
|
104
233
|
public func writeLogLine(line: String): Bool {
|
|
105
|
-
|
|
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
|
-
|
|
55
|
+
logd("[cj-tauri] ${name}=\"${v}\" 不是正整数,按默认值 ${dflt} 处理")
|
|
56
56
|
} catch (e: Exception) {
|
|
57
|
-
|
|
57
|
+
logd("[cj-tauri] ${name}=\"${v}\" 解析失败,按默认值 ${dflt} 处理")
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
}
|