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.
- 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/native/core/bridge_core.c +8 -5
- package/native/core/bridge_core.h +5 -2
- package/native/platforms/linux/bridge_linux.c +6 -3
- package/native/platforms/windows/bridge_win.c +44 -9
- package/native/tests/test_bridge_core.c +27 -3
- 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 +31 -10
- package/src/host_webview2.cj +31 -9
- 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/embedded_assets.cj
CHANGED
|
@@ -16,12 +16,12 @@ package cjTauri
|
|
|
16
16
|
*/
|
|
17
17
|
public func extractEmbeddedAssets(dir: String): Int64 {
|
|
18
18
|
if (dir.isEmpty()) {
|
|
19
|
-
|
|
19
|
+
logd("[cj-tauri] extractEmbeddedAssets: 目录为空")
|
|
20
20
|
return -1
|
|
21
21
|
}
|
|
22
22
|
let n = extractAssetsBridge(dir)
|
|
23
23
|
if (n < 0) {
|
|
24
|
-
|
|
24
|
+
logd("[cj-tauri] 释放内嵌资源失败:${dir}")
|
|
25
25
|
}
|
|
26
26
|
return n
|
|
27
27
|
}
|
|
@@ -47,7 +47,7 @@ func extractAssetsBridge(dir: String): Int64 {
|
|
|
47
47
|
@When[env == "ohos"]
|
|
48
48
|
func extractAssetsBridge(dir: String): Int64 {
|
|
49
49
|
let _ = dir
|
|
50
|
-
|
|
50
|
+
logd("[cj-tauri] 本平台没有 C 桥,无内嵌资源可释放")
|
|
51
51
|
return 0
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -68,12 +68,12 @@ func extractAssetsBridge(dir: String): Int64 {
|
|
|
68
68
|
*/
|
|
69
69
|
public func preloadEmbeddedLibrary(path: String): Bool {
|
|
70
70
|
if (path.isEmpty()) {
|
|
71
|
-
|
|
71
|
+
logd("[cj-tauri] preloadEmbeddedLibrary: 路径为空")
|
|
72
72
|
return false
|
|
73
73
|
}
|
|
74
74
|
let ok = preloadLibraryBridge(path)
|
|
75
75
|
if (!ok) {
|
|
76
|
-
|
|
76
|
+
logd("[cj-tauri] 预加载动态库失败:${path}")
|
|
77
77
|
}
|
|
78
78
|
return ok
|
|
79
79
|
}
|
package/src/host.cj
CHANGED
|
@@ -626,10 +626,10 @@ func dialogOnResult(host: CPointer<Unit>, path: CString): Unit {
|
|
|
626
626
|
try {
|
|
627
627
|
match (HostGlobals.hostRouteOf(host)) {
|
|
628
628
|
case Some(r) => r.onDialog(path.toString())
|
|
629
|
-
case None =>
|
|
629
|
+
case None => logd("[cj-tauri] dialog callback: 未登记的宿主句柄(已丢弃)")
|
|
630
630
|
}
|
|
631
631
|
} catch (e: Exception) {
|
|
632
|
-
|
|
632
|
+
logd("[cj-tauri] dialog callback error: ${e}")
|
|
633
633
|
}
|
|
634
634
|
}
|
|
635
635
|
|
|
@@ -644,10 +644,10 @@ func hostOnDestroy(host: CPointer<Unit>): Unit {
|
|
|
644
644
|
try {
|
|
645
645
|
match (HostGlobals.hostRouteOf(host)) {
|
|
646
646
|
case Some(r) => r.onDestroy()
|
|
647
|
-
case None =>
|
|
647
|
+
case None => logd("[cj-tauri] destroy callback: 未登记的宿主句柄(已忽略)")
|
|
648
648
|
}
|
|
649
649
|
} catch (e: Exception) {
|
|
650
|
-
|
|
650
|
+
logd("[cj-tauri] destroy callback error: ${e}")
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
653
|
|
|
@@ -667,7 +667,7 @@ func shellOnEvent(host: CPointer<Unit>, json: CString): Unit {
|
|
|
667
667
|
case None => () // 未登记(旧宿主已注销 / 非本进程句柄):静默,别在热路径上刷屏
|
|
668
668
|
}
|
|
669
669
|
} catch (e: Exception) {
|
|
670
|
-
|
|
670
|
+
logd("[cj-tauri] shell callback error: ${e}")
|
|
671
671
|
}
|
|
672
672
|
}
|
|
673
673
|
|
|
@@ -733,7 +733,7 @@ func hostHandleEquals(a: CPointer<Unit>, b: CPointer<Unit>): Bool {
|
|
|
733
733
|
let _ = b
|
|
734
734
|
if (!HOST_ROUTE_WARNED) {
|
|
735
735
|
HOST_ROUTE_WARNED = true
|
|
736
|
-
|
|
736
|
+
logd("[cj-tauri] host route by handle unavailable on this platform: injected host keeps its own callbacks")
|
|
737
737
|
}
|
|
738
738
|
return false
|
|
739
739
|
}
|
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
|
@@ -25,10 +25,14 @@ foreign func cj_bridge_create(): CPointer<Unit>
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* 释放宿主编:对空指针安全、幂等;调用后该句柄不可再用
|
|
28
|
+
*
|
|
29
|
+
* 返回值是**契约的一部分**(issue #8):1 = 已回收,句柄随即失效;0 = 宿主线程还没收工,
|
|
30
|
+
* 平台状态与句柄都被留着,调用方应稍后重试。别把 0 当成功——那等于把「窗口还在、
|
|
31
|
+
* IPC 全哑」这件事静默丢掉,之后再没有第二次机会。
|
|
28
32
|
*/
|
|
29
33
|
@When[os == "Linux" && env != "ohos"]
|
|
30
34
|
@C
|
|
31
|
-
foreign func cj_bridge_destroy(h: CPointer<Unit>):
|
|
35
|
+
foreign func cj_bridge_destroy(h: CPointer<Unit>): Int32
|
|
32
36
|
|
|
33
37
|
@When[os == "Linux" && env != "ohos"]
|
|
34
38
|
@C
|
|
@@ -227,7 +231,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
227
231
|
// 本窗口的 shell 事件(菜单点击等)回调:TauriApp 装配时经 setShellHandler 覆盖它做分发,
|
|
228
232
|
// 未覆盖时只留一行 stderr——菜单点了没人管,至少能在日志里看见。
|
|
229
233
|
public var shellHandler: (String) -> Unit = { json =>
|
|
230
|
-
|
|
234
|
+
logd("[cj-tauri] shell event (no handler): ${json}")
|
|
231
235
|
}
|
|
232
236
|
// 窗口配置(标题 / 尺寸),start() 前由 TauriApp 注入
|
|
233
237
|
private var config: WindowConfig = WindowConfig()
|
|
@@ -355,7 +359,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
355
359
|
let rc = cj_bridge_set_titlebar_subtitle(this.handle, LibC.mallocCString(text))
|
|
356
360
|
if (rc != 0) {
|
|
357
361
|
// 能力位说支持、这次却没写进去:留一行凭证(宿主未就绪 / 文本超 1024 字节)
|
|
358
|
-
|
|
362
|
+
logd("[cj-tauri] titlebar subtitle rejected: rc=${rc}")
|
|
359
363
|
}
|
|
360
364
|
}
|
|
361
365
|
}
|
|
@@ -405,7 +409,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
405
409
|
}
|
|
406
410
|
case None =>
|
|
407
411
|
// 外观修饰失败不该拦着开窗,但要在日志里留凭证
|
|
408
|
-
|
|
412
|
+
logd("[cj-tauri] setOwnerWindow(${ownerLabel}): 该窗口尚未登记,跳过")
|
|
409
413
|
}
|
|
410
414
|
}
|
|
411
415
|
|
|
@@ -506,7 +510,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
506
510
|
rc = cj_bridge_clipboard_write_text(this.handle, LibC.mallocCString(text))
|
|
507
511
|
}
|
|
508
512
|
if (rc != 0) {
|
|
509
|
-
|
|
513
|
+
logd("[cj-tauri] clipboard write failed: code=${rc}")
|
|
510
514
|
}
|
|
511
515
|
return rc == 0
|
|
512
516
|
}
|
|
@@ -556,7 +560,7 @@ public class WebKitHost <: WebViewHost {
|
|
|
556
560
|
}
|
|
557
561
|
if (rc != 0) {
|
|
558
562
|
// -4 = 本平台未实现:这是静态事实,stderr 一行说清,不算异常
|
|
559
|
-
|
|
563
|
+
logd("[cj-tauri] notification failed: code=${rc}")
|
|
560
564
|
}
|
|
561
565
|
return rc == 0
|
|
562
566
|
}
|
|
@@ -669,10 +673,27 @@ public class WebKitHost <: WebViewHost {
|
|
|
669
673
|
if (this.handle.isNull()) {
|
|
670
674
|
return
|
|
671
675
|
}
|
|
672
|
-
|
|
673
|
-
|
|
676
|
+
// 宿主线程还在收尾(GTK/WebKit 的拆解是整串多线程收尾,C 侧每次最多等 5s)时,
|
|
677
|
+
// cj_bridge_destroy 回 0 表示**没回收**:句柄必须留着再试一次——直接置空就等于
|
|
678
|
+
// 把「没释放干净」这件事一起丢掉(issue #8 的那一轮就是这么静默过去的)。
|
|
679
|
+
var released = false
|
|
680
|
+
var tries = 0
|
|
681
|
+
while (tries < 2 && !released) {
|
|
682
|
+
unsafe {
|
|
683
|
+
released = cj_bridge_destroy(this.handle) != 0
|
|
684
|
+
}
|
|
685
|
+
if (!released) {
|
|
686
|
+
tries += 1
|
|
687
|
+
if (tries < 2) {
|
|
688
|
+
sleep(Duration.millisecond * 500)
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
if (released) {
|
|
693
|
+
this.handle = CPointer<Unit>()
|
|
694
|
+
} else {
|
|
695
|
+
logd("[cj-tauri] dispose: 宿主线程未结束,句柄保留(可再调一次 dispose 重试)")
|
|
674
696
|
}
|
|
675
|
-
this.handle = CPointer<Unit>()
|
|
676
697
|
}
|
|
677
698
|
}
|
|
678
699
|
|
|
@@ -683,6 +704,6 @@ func hostOnMessage(json: CString): Unit {
|
|
|
683
704
|
try {
|
|
684
705
|
HostGlobals.onMessage(json.toString())
|
|
685
706
|
} catch (e: Exception) {
|
|
686
|
-
|
|
707
|
+
logd("[cj-tauri] host callback error: ${e}")
|
|
687
708
|
}
|
|
688
709
|
}
|
package/src/host_webview2.cj
CHANGED
|
@@ -24,10 +24,14 @@ foreign func cj_bridge_create(): CPointer<Unit>
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* 释放宿主编:对空指针安全、幂等;调用后该句柄不可再用
|
|
27
|
+
*
|
|
28
|
+
* 返回值是**契约的一部分**(issue #8):1 = 已回收,句柄随即失效;0 = 宿主线程还没收工,
|
|
29
|
+
* 平台状态与句柄都被留着,调用方应稍后重试。别把 0 当成功——那等于把「窗口还在、
|
|
30
|
+
* IPC 全哑」这件事静默丢掉,之后再没有第二次机会。
|
|
27
31
|
*/
|
|
28
32
|
@When[os == "Windows"]
|
|
29
33
|
@C
|
|
30
|
-
foreign func cj_bridge_destroy(h: CPointer<Unit>):
|
|
34
|
+
foreign func cj_bridge_destroy(h: CPointer<Unit>): Int32
|
|
31
35
|
|
|
32
36
|
@When[os == "Windows"]
|
|
33
37
|
@C
|
|
@@ -229,7 +233,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
229
233
|
// 本窗口的 shell 事件(菜单点击等)回调:TauriApp 装配时经 setShellHandler 覆盖它做分发,
|
|
230
234
|
// 未覆盖时只留一行 stderr——菜单点了没人管,至少能在日志里看见。
|
|
231
235
|
public var shellHandler: (String) -> Unit = { json =>
|
|
232
|
-
|
|
236
|
+
logd("[cj-tauri] shell event (no handler): ${json}")
|
|
233
237
|
}
|
|
234
238
|
// 窗口配置(标题 / 尺寸),start() 前由 TauriApp 注入
|
|
235
239
|
private var config: WindowConfig = WindowConfig()
|
|
@@ -407,7 +411,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
407
411
|
}
|
|
408
412
|
case None =>
|
|
409
413
|
// 外观修饰失败不该拦着开窗,但要在日志里留凭证
|
|
410
|
-
|
|
414
|
+
logd("[cj-tauri] setOwnerWindow(${ownerLabel}): 该窗口尚未登记,跳过")
|
|
411
415
|
}
|
|
412
416
|
}
|
|
413
417
|
|
|
@@ -506,7 +510,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
506
510
|
rc = cj_bridge_clipboard_write_text(this.handle, LibC.mallocCString(text))
|
|
507
511
|
}
|
|
508
512
|
if (rc != 0) {
|
|
509
|
-
|
|
513
|
+
logd("[cj-tauri] clipboard write failed: code=${rc}")
|
|
510
514
|
}
|
|
511
515
|
return rc == 0
|
|
512
516
|
}
|
|
@@ -556,7 +560,7 @@ public class WebView2Host <: WebViewHost {
|
|
|
556
560
|
}
|
|
557
561
|
if (rc != 0) {
|
|
558
562
|
// Windows 桩阶段返回 -4(未实现):静态事实,stderr 一行说清,不算异常
|
|
559
|
-
|
|
563
|
+
logd("[cj-tauri] notification failed: code=${rc}")
|
|
560
564
|
}
|
|
561
565
|
return rc == 0
|
|
562
566
|
}
|
|
@@ -669,10 +673,28 @@ public class WebView2Host <: WebViewHost {
|
|
|
669
673
|
if (this.handle.isNull()) {
|
|
670
674
|
return
|
|
671
675
|
}
|
|
672
|
-
|
|
673
|
-
|
|
676
|
+
// 宿主线程还在收尾(WebView2 的 controller Close / view_close 都是同步 COM 调用,
|
|
677
|
+
// 可能卡到数秒;C 侧每次最多等 5s)时,cj_bridge_destroy 回 0 表示**没回收**:
|
|
678
|
+
// 句柄必须留着再试一次——直接置空就等于把「没释放干净」这件事一起丢掉
|
|
679
|
+
// (issue #8 的那一轮就是这么静默过去的)。
|
|
680
|
+
var released = false
|
|
681
|
+
var tries = 0
|
|
682
|
+
while (tries < 2 && !released) {
|
|
683
|
+
unsafe {
|
|
684
|
+
released = cj_bridge_destroy(this.handle) != 0
|
|
685
|
+
}
|
|
686
|
+
if (!released) {
|
|
687
|
+
tries += 1
|
|
688
|
+
if (tries < 2) {
|
|
689
|
+
sleep(Duration.millisecond * 500)
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
if (released) {
|
|
694
|
+
this.handle = CPointer<Unit>()
|
|
695
|
+
} else {
|
|
696
|
+
logd("[cj-tauri] dispose: 宿主线程未结束,句柄保留(可再调一次 dispose 重试)")
|
|
674
697
|
}
|
|
675
|
-
this.handle = CPointer<Unit>()
|
|
676
698
|
}
|
|
677
699
|
}
|
|
678
700
|
|
|
@@ -683,6 +705,6 @@ func hostOnMessage(json: CString): Unit {
|
|
|
683
705
|
try {
|
|
684
706
|
HostGlobals.onMessage(json.toString())
|
|
685
707
|
} catch (e: Exception) {
|
|
686
|
-
|
|
708
|
+
logd("[cj-tauri] host callback error: ${e}")
|
|
687
709
|
}
|
|
688
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
|
}
|