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
package/src/plugin_fs.cj DELETED
@@ -1,118 +0,0 @@
1
- package cjTauri
2
-
3
- import std.collection.*
4
- import std.fs.*
5
- import stdx.encoding.json.*
6
-
7
- /**
8
- * 官方插件 fs:文件读写(纯仓颉,零 C 桥改动,RFC-001 §7.3)
9
- *
10
- * 命令:fs:readText / fs:writeText / fs:exists
11
- * 权限:**不自动放行**,应用要在 capabilities 里显式声明,两种写法等价:
12
- * "commands": ["fs:readText", "fs:exists"] // 明文逐条(旧写法,一直支持)
13
- * "permissions": ["fs:readonly"] // 命名权限集(v1.1,一次放行一组)
14
- * 前端:window.__CJ_TAURI__.fs.readText({ path: "notes.txt" })
15
- */
16
- public class FsPlugin <: Plugin {
17
- public init() {}
18
-
19
- public func name(): String {
20
- return "fs"
21
- }
22
-
23
- public func commands(): HashMap<String, CommandHandler> {
24
- let m = HashMap<String, CommandHandler>()
25
- m.add("readText", FsCommands())
26
- m.add("writeText", FsCommands())
27
- m.add("exists", FsCommands())
28
- return m
29
- }
30
-
31
- /**
32
- * 命名权限集(v1.1,对标 Tauri v2 的 fs:default / fs:allow-read-text-file)。
33
- *
34
- * readonly 只含读相关两条:只想读文件的应用引用它即可,**写能力不会被顺带打开**;
35
- * 要写文件必须显式引用 default(或把 fs:writeText 写成明文)——最小权限不打折。
36
- * 集内写短名(readText),框架自动补成 fs:readText。
37
- */
38
- public func permissions(): HashMap<String, ArrayList<String>> {
39
- let m = HashMap<String, ArrayList<String>>()
40
- let ro = ArrayList<String>()
41
- ro.add("readText")
42
- ro.add("exists")
43
- m.add("readonly", ro)
44
- let all = ArrayList<String>()
45
- all.add("readText")
46
- all.add("writeText")
47
- all.add("exists")
48
- m.add("default", all)
49
- return m
50
- }
51
-
52
- /**
53
- * 前端 shim:往桥对象上挂一个 fs 命名空间。
54
- * 只动 __CJ_TAURI__ 的一个命名空间,不碰 invoke / listen / emit,也不注册全局变量。
55
- */
56
- public func jsShim(): String {
57
- return "(function () { var t = window.__CJ_TAURI__ || (window.__CJ_TAURI__ = {});" +
58
- " t.fs = {" +
59
- " readText: function (args) { return window.__CJ_TAURI__.invoke('fs:readText', args); }," +
60
- " writeText: function (args) { return window.__CJ_TAURI__.invoke('fs:writeText', args); }," +
61
- " exists: function (args) { return window.__CJ_TAURI__.invoke('fs:exists', args); }" +
62
- " }; })();\n"
63
- }
64
- }
65
-
66
- /**
67
- * fs 插件的命令处理器(三个命令共用一份,按全名分派,与内置 SystemCommands 同形)
68
- */
69
- class FsCommands <: CommandHandler {
70
- public init() {}
71
-
72
- public func handle(cmd: String, args: JsonObject, ipc: IpcContext): JsonValue {
73
- let _ = ipc
74
- match (cmd) {
75
- case "fs:readText" => this.readText(args)
76
- case "fs:writeText" => this.writeText(args)
77
- case "fs:exists" => this.exists(args)
78
- case _ => throw CommandException("unknown fs command: ${cmd}")
79
- }
80
- }
81
-
82
- /** 取必需的字符串参数;缺失或类型不对时抛业务错误,前端拿到的是可读原文 */
83
- private func requireString(args: JsonObject, key: String): String {
84
- match (args.get(key)) {
85
- case Some(v) => match (v.kind()) {
86
- case JsonKind.JsString => return v.asString().getValue()
87
- case _ => throw CommandException("fs: argument \"${key}\" must be a string")
88
- }
89
- case None => throw CommandException("fs: missing argument \"${key}\"")
90
- }
91
- }
92
-
93
- private func readText(args: JsonObject): JsonValue {
94
- let path = this.requireString(args, "path")
95
- try {
96
- return JsonString(String.fromUtf8(File.readFrom(path)))
97
- } catch (e: Exception) {
98
- throw CommandException("fs:readText failed: ${e}")
99
- }
100
- }
101
-
102
- private func writeText(args: JsonObject): JsonValue {
103
- let path = this.requireString(args, "path")
104
- let contents = this.requireString(args, "contents")
105
- try {
106
- // File.writeTo 是覆盖写:文件已存在会截断,不存在则创建——不需要先删(与 File.create 不同)
107
- File.writeTo(path, contents.toArray())
108
- return JsonBool(true)
109
- } catch (e: Exception) {
110
- throw CommandException("fs:writeText failed: ${e}")
111
- }
112
- }
113
-
114
- private func exists(args: JsonObject): JsonValue {
115
- let path = this.requireString(args, "path")
116
- return JsonBool(exists(path))
117
- }
118
- }
File without changes