cj-tauri 0.8.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +3 -3
  2. package/cjpm.toml +52 -25
  3. package/cli/cjpm.toml +1 -1
  4. package/cli/src/doctor.cj +304 -0
  5. package/cli/src/main.cj +33 -7
  6. package/cli/src/project.cj +59 -1
  7. package/cli/src/resolve.cj +348 -304
  8. package/cli/src/scaffold.cj +139 -22
  9. package/cli/templates/ohos-pc/AppScope/app.json5 +13 -0
  10. package/cli/templates/ohos-pc/AppScope/resources/base/element/string.json +8 -0
  11. package/cli/templates/ohos-pc/AppScope/resources/base/media/background.png +0 -0
  12. package/cli/templates/ohos-pc/AppScope/resources/base/media/foreground.png +0 -0
  13. package/cli/templates/ohos-pc/AppScope/resources/base/media/layered_image.json +6 -0
  14. package/cli/templates/ohos-pc/README.md +79 -0
  15. package/cli/templates/ohos-pc/build-hap.sh +190 -0
  16. package/cli/templates/ohos-pc/build-profile.json5 +46 -0
  17. package/cli/templates/ohos-pc/entry/build-profile.json5 +26 -0
  18. package/cli/templates/ohos-pc/entry/cjpm.toml +43 -0
  19. package/cli/templates/ohos-pc/entry/hvigorfile.ts +6 -0
  20. package/cli/templates/ohos-pc/entry/oh-package.json5 +9 -0
  21. package/cli/templates/ohos-pc/entry/src/main/cangjie/ability_stage.cj +17 -0
  22. package/cli/templates/ohos-pc/entry/src/main/cangjie/app_host.cj +94 -0
  23. package/cli/templates/ohos-pc/entry/src/main/cangjie/index.cj +167 -0
  24. package/cli/templates/ohos-pc/entry/src/main/cangjie/main_ability.cj +139 -0
  25. package/cli/templates/ohos-pc/entry/src/main/module.json5 +49 -0
  26. package/cli/templates/ohos-pc/entry/src/main/resources/base/element/color.json +8 -0
  27. package/cli/templates/ohos-pc/entry/src/main/resources/base/element/string.json +16 -0
  28. package/cli/templates/ohos-pc/entry/src/main/resources/base/media/background.png +0 -0
  29. package/cli/templates/ohos-pc/entry/src/main/resources/base/media/foreground.png +0 -0
  30. package/cli/templates/ohos-pc/entry/src/main/resources/base/media/layered_image.json +6 -0
  31. package/cli/templates/ohos-pc/entry/src/main/resources/base/media/startIcon.png +0 -0
  32. package/cli/templates/ohos-pc/entry/src/main/resources/base/profile/main_pages.json +2 -0
  33. package/cli/templates/ohos-pc/entry/src/main/resources/rawfile/capabilities.json +6 -0
  34. package/cli/templates/ohos-pc/entry/src/main/resources/rawfile/index.html +92 -0
  35. package/cli/templates/ohos-pc/hvigor/hvigor-config.json5 +5 -0
  36. package/cli/templates/ohos-pc/hvigorfile.ts +6 -0
  37. package/cli/templates/ohos-pc/oh-package.json5 +10 -0
  38. package/native/build_linux.sh +30 -2
  39. package/native/build_win.bat +62 -61
  40. package/native/core/bridge_core.c +1626 -0
  41. package/native/{bridge_core.h → core/bridge_core.h} +246 -6
  42. package/native/platforms/harmonyos/README.md +106 -0
  43. package/native/platforms/linux/bridge_linux.c +2485 -0
  44. package/native/platforms/windows/bridge_win.c +3248 -0
  45. package/native/tests/test_bridge_core.c +528 -1
  46. package/package.json +12 -3
  47. package/prebuilt/win32-x64/cj-tauri.exe +0 -0
  48. package/src/api_system.cj +10 -2
  49. package/src/app.cj +248 -85
  50. package/src/arkweb_proxy.cj +56 -0
  51. package/src/arkweb_script.cj +154 -0
  52. package/src/capability.cj +140 -0
  53. package/src/clipboard_bridge.cj +55 -0
  54. package/src/dragdrop.cj +26 -0
  55. package/src/embedded_assets.cj +98 -0
  56. package/src/hexutil.cj +53 -0
  57. package/src/host.cj +197 -26
  58. package/src/host_arkweb.cj +740 -0
  59. package/src/host_factory.cj +48 -0
  60. package/src/host_webkit.cj +202 -26
  61. package/src/host_webview2.cj +176 -3
  62. package/src/hotkey.cj +66 -0
  63. package/src/ipc_hub.cj +49 -0
  64. package/src/ipc_message.cj +2 -1
  65. package/src/jsutil.cj +33 -0
  66. package/src/log_bridge.cj +107 -0
  67. package/src/logging.cj +127 -0
  68. package/src/menu.cj +197 -196
  69. package/src/plugin.cj +40 -0
  70. package/src/plugins/clipboard/plugin_clipboard.cj +144 -0
  71. package/src/{plugin_dialog.cj → plugins/dialog/plugin_dialog.cj} +74 -17
  72. package/src/plugins/fs/plugin_fs.cj +194 -0
  73. package/src/plugins/http/plugin_http.cj +459 -0
  74. package/src/plugins/log/plugin_log.cj +105 -0
  75. package/src/{plugin_menu.cj → plugins/menu/plugin_menu.cj} +4 -2
  76. package/src/plugins/mqtt/mqtt_codec.cj +661 -0
  77. package/src/plugins/mqtt/plugin_mqtt.cj +1446 -0
  78. package/src/plugins/notification/plugin_notification.cj +146 -0
  79. package/src/plugins/plugins.cj +5 -0
  80. package/src/plugins/redis/plugin_redis.cj +2409 -0
  81. package/src/plugins/redis/redis_codec.cj +556 -0
  82. package/src/{plugin_serial.cj → plugins/serial/plugin_serial.cj} +442 -489
  83. package/src/{serial_bridge.cj → plugins/serial/serial_bridge.cj} +185 -184
  84. package/src/{plugin_shell.cj → plugins/shell/plugin_shell.cj} +230 -228
  85. package/src/plugins/sqlite/plugin_sqlite.cj +697 -0
  86. package/src/plugins/sqlite/sqlite_ffi.cj +206 -0
  87. package/src/plugins/store/plugin_store.cj +287 -0
  88. package/src/plugins/ws/plugin_ws.cj +470 -0
  89. package/src/process_hidden.cj +174 -0
  90. package/src/scope.cj +391 -0
  91. package/src/shell_event.cj +69 -68
  92. package/src/tests/capability_test.cj +53 -0
  93. package/src/tests/fake_host.cj +85 -20
  94. package/src/tests/ipc_hub_test.cj +13 -0
  95. package/src/tests/jsutil_test.cj +62 -0
  96. package/src/tests/logging_test.cj +62 -0
  97. package/src/tests/mqtt_codec_test.cj +405 -0
  98. package/src/tests/plugin_clipboard_test.cj +222 -0
  99. package/src/tests/plugin_dialog_test.cj +98 -4
  100. package/src/tests/plugin_http_test.cj +124 -0
  101. package/src/tests/plugin_menu_test.cj +1 -0
  102. package/src/tests/plugin_notification_test.cj +205 -0
  103. package/src/tests/plugin_serial_test.cj +269 -267
  104. package/src/tests/plugin_shell_test.cj +189 -188
  105. package/src/tests/plugin_sqlite_test.cj +230 -0
  106. package/src/tests/plugin_store_test.cj +260 -0
  107. package/src/tests/plugin_test.cj +542 -524
  108. package/src/tests/plugin_ws_test.cj +40 -0
  109. package/src/tests/process_hidden_test.cj +129 -0
  110. package/src/tests/redis_codec_test.cj +396 -0
  111. package/src/tests/scope_test.cj +350 -0
  112. package/src/tests/shell_event_test.cj +0 -1
  113. package/src/tests/system_host_test.cj +81 -79
  114. package/src/tests/urlutil_test.cj +53 -0
  115. package/src/tests/version_test.cj +75 -65
  116. package/src/tray.cj +90 -0
  117. package/src/urlutil.cj +159 -0
  118. package/src/version.cj +23 -2
  119. package/src/window.cj +51 -42
  120. package/native/bridge_core.c +0 -797
  121. package/native/bridge_linux.c +0 -1268
  122. package/native/bridge_win.c +0 -1633
  123. package/src/plugin_fs.cj +0 -118
  124. /package/native/{bridge_js.h → core/bridge_js.h} +0 -0
@@ -0,0 +1,146 @@
1
+ package cjTauri.plugins.notification
2
+
3
+ import cjTauri.*
4
+
5
+ import std.collection.*
6
+ import stdx.encoding.json.*
7
+
8
+ /**
9
+ * 官方插件 notification:系统通知(对标 Tauri 的 notification 插件,RFC-003 第 3 期)
10
+ *
11
+ * 命令:notification:notify
12
+ * 权限:**不自动放行**,应用要在 capabilities 里显式声明:
13
+ * "commands": ["notification:notify"]
14
+ * "permissions": ["notification:default"]
15
+ * 前端:window.__CJ_TAURI__.notification.notify({ title, body })
16
+ *
17
+ * 实现落 C 桥 `cj_bridge_notification_notify`:Linux 走 freedesktop Notifications
18
+ * (会话总线);**Windows 桩阶段返回 -4 未实现**——命令如实报失败,`system:host` 的能力位
19
+ * 同口径不置 CJ_CAP_NOTIFICATION,不假装成功(AGENTS §1 的如实交付口径)。
20
+ *
21
+ * 「发后即忘」:提交即返回,通知显示与否不回传(freedesktop 协议本就没有同步回执)。
22
+ */
23
+ public class NotificationPlugin <: Plugin {
24
+ private let handler: NotificationCommands = NotificationCommands()
25
+
26
+ public init() {}
27
+
28
+ public func name(): String {
29
+ return "notification"
30
+ }
31
+
32
+ public func commands(): HashMap<String, CommandHandler> {
33
+ let m = HashMap<String, CommandHandler>()
34
+ m.add("notify", this.handler)
35
+ return m
36
+ }
37
+
38
+ /**
39
+ * 命名权限集(v1.1):只有一条命令,default 与明文等价——保留集名是为了
40
+ * 应用清单写法统一(全部走 permissions 数组)。
41
+ */
42
+ public func permissions(): HashMap<String, ArrayList<String>> {
43
+ let m = HashMap<String, ArrayList<String>>()
44
+ let all = ArrayList<String>()
45
+ all.add("notify")
46
+ m.add("default", all)
47
+ return m
48
+ }
49
+
50
+ /**
51
+ * 前端 shim:往桥对象上挂一个 notification 命名空间(与 dialog 同款)
52
+ */
53
+ public func jsShim(): String {
54
+ return "(function () { var t = window.__CJ_TAURI__ || (window.__CJ_TAURI__ = {});" +
55
+ " t.notification = {" +
56
+ " notify: function (o) { return window.__CJ_TAURI__.invoke('notification:notify', o || {}); }" +
57
+ " }; })();\n"
58
+ }
59
+
60
+ public func setup(app: TauriApp): Unit {
61
+ // 多窗口按报文里的 label 解析宿主(与 dialog 插件同一口径):固定 `app.webviewHost()`
62
+ // 会让第二扇窗的通知全部落到默认窗那一个宿主上(2026-10-20 dialog 实机取证同款)。
63
+ this.handler.attachHostResolver({ label => app.hostOf(label) })
64
+ }
65
+ }
66
+
67
+ /**
68
+ * 通知命令处理器:notify 收 { title, body? }。body 省略 / null 都合法。
69
+ */
70
+ public class NotificationCommands <: CommandHandler {
71
+ private var host: Option<WebViewHost> = None
72
+
73
+ /* 按 label 解析宿主(多窗口的正路):单槽 `host` 只记着装配时那一个宿主,
74
+ 多窗口下用它就是「所有窗的通知都发给默认窗那一个宿主」。 */
75
+ private var hostByWindow: Option<(String) -> Option<WebViewHost>> = None
76
+
77
+ public init() {}
78
+
79
+ /** 由 NotificationPlugin.setup() 调用(单窗口 / 单测用;这个槽不带窗口身份) */
80
+ public func attachHost(h: WebViewHost): Unit {
81
+ this.host = Some(h)
82
+ }
83
+
84
+ /** 装配「label → 宿主」解析器;由 NotificationPlugin.setup() 传入 `app.hostOf` */
85
+ public func attachHostResolver(resolve: (String) -> Option<WebViewHost>): Unit {
86
+ this.hostByWindow = Some(resolve)
87
+ }
88
+
89
+ public func handle(cmd: String, args: JsonObject, ipc: IpcContext): JsonValue {
90
+ match (cmd) {
91
+ case "notification:notify" =>
92
+ let title = this.requireString(args, "title")
93
+ let body = this.optionalString(args, "body")
94
+ if (this.requireHost(ipc).notify(title, body)) {
95
+ return JsonNull()
96
+ }
97
+ throw CommandException(
98
+ "notification: 发送失败(宿主未就绪 / 本平台未实现 / 桌面环境不可用)")
99
+ case _ => throw CommandException("unknown notification command: ${cmd}")
100
+ }
101
+ }
102
+
103
+ /**
104
+ * 取**发起这条命令的窗口**的宿主
105
+ *
106
+ * 多窗口下必须按 `ipc.window` 解析:用装配时那一个宿主,第二扇窗的通知会落到默认窗的宿主上。
107
+ * 解析器在场而窗口没登记时**如实报错**,不回落到单槽(与 dialog 插件同一口径)。
108
+ */
109
+ private func requireHost(ipc: IpcContext): WebViewHost {
110
+ match (this.hostByWindow) {
111
+ case Some(resolve) => match (resolve(ipc.window)) {
112
+ case Some(h) => return h
113
+ case None => throw CommandException(
114
+ "notification: 窗口 \"${ipc.window}\" 没有登记宿主(addWindow(); 默认窗在 run() 之前也可用)")
115
+ }
116
+ case None => ()
117
+ }
118
+ match (this.host) {
119
+ case Some(h) => h
120
+ case None => throw CommandException(
121
+ "notification: 宿主未装配(用 .plugin(NotificationPlugin()) 装配插件后才可用)")
122
+ }
123
+ }
124
+
125
+ private func requireString(args: JsonObject, key: String): String {
126
+ match (args.get(key)) {
127
+ case Some(v) => match (v.kind()) {
128
+ case JsonKind.JsString => return v.asString().getValue()
129
+ case _ => throw CommandException("notification: argument \"${key}\" must be a string")
130
+ }
131
+ case None => throw CommandException("notification: missing argument \"${key}\"")
132
+ }
133
+ }
134
+
135
+ /** 可选字符串参数:缺失 / null 都按空串(body 可省) */
136
+ private func optionalString(args: JsonObject, key: String): String {
137
+ match (args.get(key)) {
138
+ case Some(v) => match (v.kind()) {
139
+ case JsonKind.JsString => return v.asString().getValue()
140
+ case JsonKind.JsNull => return ""
141
+ case _ => throw CommandException("notification: argument \"${key}\" must be a string")
142
+ }
143
+ case None => return ""
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,5 @@
1
+ package cjTauri.plugins
2
+
3
+ // 扫描锚点:cjpm 只在目录里有 .cj 文件时才递归扫描子目录——本文件为空占位,
4
+ // 保证 src/plugins/<名字>/ 的各插件子包(package cjTauri.plugins.<名字>)能被编进产物。
5
+ // 插件实现一律放各自的子包目录,别往这里平铺(check-static 第 6b-2 项盯着)。