cj-tauri 2.0.0 → 2.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.
- package/README.md +113 -99
- package/bin/cj-tauri.js +287 -287
- package/cjpm.toml +63 -52
- package/cli/cjpm.toml +22 -22
- package/cli/src/doctor.cj +308 -306
- package/cli/src/main.cj +129 -129
- package/cli/src/manifest.cj +632 -558
- package/cli/src/manifest_test.cj +87 -0
- package/cli/src/project.cj +770 -770
- package/cli/src/resolve.cj +348 -348
- package/cli/src/scaffold.cj +369 -369
- package/cli/src/sync.cj +526 -526
- package/cli/src/util.cj +168 -168
- package/cli/templates/app/README.md +51 -48
- package/cli/templates/app/assets/capabilities/default.json +7 -7
- package/cli/templates/app/assets/ui/index.html +120 -118
- package/cli/templates/app/cj-tauri.toml +32 -22
- package/cli/templates/app/cjpm.toml +34 -34
- package/cli/templates/app/src/main.cj +101 -90
- package/cli/templates/app-react/README.md +56 -56
- package/cli/templates/app-react/assets/capabilities/default.json +7 -7
- package/cli/templates/app-react/assets/ui/index.html +25 -25
- package/cli/templates/app-react/assets/ui/package.json +19 -19
- package/cli/templates/app-react/assets/ui/src/App.css +67 -67
- package/cli/templates/app-react/assets/ui/src/App.jsx +124 -124
- package/cli/templates/app-react/assets/ui/src/main.jsx +6 -6
- package/cli/templates/app-react/assets/ui/vite.config.js +24 -24
- package/cli/templates/app-react/cj-tauri.toml +33 -23
- package/cli/templates/app-react/cjpm.toml +34 -34
- package/cli/templates/app-react/src/main.cj +91 -91
- package/cli/templates/app-vue/README.md +56 -56
- package/cli/templates/app-vue/assets/capabilities/default.json +7 -7
- package/cli/templates/app-vue/assets/ui/index.html +25 -25
- package/cli/templates/app-vue/assets/ui/package.json +18 -18
- package/cli/templates/app-vue/assets/ui/src/App.vue +176 -176
- package/cli/templates/app-vue/assets/ui/src/main.js +4 -4
- package/cli/templates/app-vue/assets/ui/vite.config.js +24 -24
- package/cli/templates/app-vue/cj-tauri.toml +33 -23
- package/cli/templates/app-vue/cjpm.toml +34 -34
- package/cli/templates/app-vue/src/main.cj +91 -91
- package/cli/templates/ohos-skeleton/AppScope/app.json5 +13 -13
- package/cli/templates/ohos-skeleton/AppScope/resources/base/element/string.json +8 -8
- package/cli/templates/ohos-skeleton/AppScope/resources/base/media/layered_image.json +6 -6
- package/cli/templates/ohos-skeleton/README.md +84 -79
- package/cli/templates/ohos-skeleton/build-hap.sh +15 -0
- package/cli/templates/ohos-skeleton/build-profile.json5 +46 -46
- package/cli/templates/ohos-skeleton/entry/build-profile.json5 +26 -26
- package/cli/templates/ohos-skeleton/entry/cjpm.toml +51 -43
- package/cli/templates/ohos-skeleton/entry/hvigorfile.ts +6 -6
- package/cli/templates/ohos-skeleton/entry/oh-package.json5 +9 -9
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/ability_stage.cj +17 -17
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/app_host.cj +94 -94
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/dialog_host.cj +217 -0
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/index.cj +527 -167
- package/cli/templates/ohos-skeleton/entry/src/main/cangjie/main_ability.cj +139 -139
- package/cli/templates/ohos-skeleton/entry/src/main/module.json5 +57 -49
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/element/color.json +8 -8
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/element/string.json +16 -16
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/media/layered_image.json +6 -6
- package/cli/templates/ohos-skeleton/entry/src/main/resources/base/profile/main_pages.json +2 -2
- package/cli/templates/ohos-skeleton/entry/src/main/resources/rawfile/capabilities.json +6 -6
- package/cli/templates/ohos-skeleton/entry/src/main/resources/rawfile/index.html +92 -92
- package/cli/templates/ohos-skeleton/hvigor/hvigor-config.json5 +5 -5
- package/cli/templates/ohos-skeleton/hvigorfile.ts +6 -6
- package/cli/templates/ohos-skeleton/oh-package.json5 +10 -10
- package/native/build_win.bat +62 -62
- package/native/core/bridge_core.c +1681 -1626
- package/native/core/bridge_core.h +675 -618
- package/native/core/bridge_js.h +108 -108
- package/native/platforms/harmonyos/README.md +115 -6
- package/native/platforms/linux/bridge_linux.c +2787 -2485
- package/native/platforms/windows/bridge_win.c +3740 -3248
- package/native/tests/gtk_threading_probe.c +143 -143
- package/native/tests/test_bridge_core.c +1339 -1228
- package/package.json +53 -53
- package/prebuilt/linux-x64/cj-tauri +0 -0
- package/src/api_system.cj +67 -67
- package/src/app.cj +325 -969
- package/src/app_events.cj +166 -0
- package/src/app_host_ops.cj +287 -0
- package/src/app_run.cj +283 -0
- package/src/app_spec.cj +76 -76
- package/src/arkweb_menu.cj +216 -0
- package/src/arkweb_script.cj +142 -142
- package/src/capability.cj +409 -409
- package/src/clipboard_bridge.cj +178 -0
- package/src/dialog_spec.cj +79 -0
- package/src/dragdrop.cj +26 -26
- package/src/embedded_assets.cj +98 -98
- package/src/host.cj +752 -607
- package/src/host_arkweb.cj +924 -778
- package/src/host_webkit.cj +663 -570
- package/src/host_webview2.cj +663 -570
- package/src/hotkey.cj +66 -66
- package/src/ipc_hub.cj +337 -337
- package/src/ipc_message.cj +286 -286
- package/src/launch.cj +62 -62
- package/src/logging.cj +127 -127
- package/src/menu.cj +197 -197
- package/src/platform/platform_app_context.cj +77 -77
- package/src/platform/platform_assets.cj +33 -33
- package/src/platform/platform_discover.cj +176 -176
- package/src/platform/platform_env.cj +29 -29
- package/src/platform/platform_feature.cj +31 -31
- package/src/platform/platform_page_source.cj +87 -87
- package/src/platform/platform_target_info.cj +32 -32
- package/src/platform_host_provider.cj +87 -87
- package/src/plugin.cj +333 -333
- package/src/plugins/clipboard/plugin_clipboard.cj +152 -152
- package/src/plugins/dialog/plugin_dialog.cj +209 -209
- package/src/plugins/fs/plugin_fs.cj +105 -1
- package/src/plugins/http/http_backend.cj +131 -0
- package/src/plugins/http/http_desktop.cj +195 -0
- package/src/plugins/http/http_ohos.cj +204 -0
- package/src/plugins/http/plugin_http.cj +310 -459
- package/src/plugins/log/plugin_log.cj +105 -105
- package/src/plugins/menu/plugin_menu.cj +158 -158
- package/src/plugins/notification/plugin_notification.cj +154 -154
- package/src/plugins/serial/plugin_serial.cj +458 -454
- package/src/plugins/serial/serial_bridge.cj +194 -194
- package/src/plugins/serial/serial_manager_ohos.cj +92 -0
- package/src/plugins/serial/serial_ohos.cj +529 -0
- package/src/plugins/shell/plugin_shell.cj +258 -258
- package/src/plugins/sqlite/plugin_sqlite.cj +705 -710
- package/src/plugins/sqlite/sqlite_ffi.cj +206 -211
- package/src/plugins/ws/plugin_ws.cj +488 -470
- package/src/process_hidden.cj +174 -174
- package/src/scope.cj +391 -391
- package/src/shell_event.cj +69 -69
- package/src/tests/app_spec_test.cj +126 -127
- package/src/tests/capability_test.cj +243 -243
- package/src/tests/dialog_spec_test.cj +73 -0
- package/src/tests/fake_host.cj +201 -201
- package/src/tests/ipc_hub_test.cj +487 -487
- package/src/tests/logging_test.cj +62 -62
- package/src/tests/platform_contract_test.cj +251 -251
- package/src/tests/plugin_clipboard_test.cj +222 -222
- package/src/tests/plugin_dialog_test.cj +237 -237
- package/src/tests/plugin_fs_test.cj +207 -0
- package/src/tests/plugin_http_test.cj +124 -124
- package/src/tests/plugin_notification_test.cj +205 -205
- package/src/tests/plugin_serial_test.cj +48 -0
- package/src/tests/plugin_test.cj +605 -585
- package/src/tests/plugin_ws_test.cj +40 -40
- package/src/tests/process_hidden_test.cj +129 -129
- package/src/tests/scope_test.cj +350 -350
- package/src/tests/system_host_test.cj +99 -81
- package/src/tests/urlutil_test.cj +53 -53
- package/src/tests/version_test.cj +75 -75
- package/src/tests/window_registry_test.cj +123 -123
- package/src/tray.cj +90 -90
- package/src/urlutil.cj +159 -159
- package/src/version.cj +44 -44
- package/src/window.cj +51 -51
- package/src/window_registry.cj +116 -116
- package/prebuilt/win32-x64/cj-tauri.exe +0 -0
- package/src/plugins/serial/serial_ohos_stub.cj +0 -61
- package/src/plugins/sqlite/sqlite_ohos_stub.cj +0 -91
|
@@ -1,118 +1,120 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>{{PROJECT_NAME}}</title>
|
|
6
|
-
<style>
|
|
7
|
-
:root { color-scheme: dark; }
|
|
8
|
-
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: #16161d;
|
|
9
|
-
color: #e6e6e6; margin: 0; min-height: 100vh;
|
|
10
|
-
display: flex; flex-direction: column; align-items: center; justify-content: center; }
|
|
11
|
-
.card { background: #1f2029; border: 1px solid #2e3140; border-radius: 14px;
|
|
12
|
-
padding: 28px 32px; width: min(460px, 86vw);
|
|
13
|
-
box-shadow: 0 12px 32px rgba(0,0,0,.45); }
|
|
14
|
-
h1 { margin: 0 0 4px; font-size: 22px; color: #7ce7ff; }
|
|
15
|
-
.sub { margin: 0 0 20px; font-size: 13px; color: #9aa0b4; }
|
|
16
|
-
.row { display: flex; gap: 8px; margin: 14px 0; }
|
|
17
|
-
input, button { font-size: 15px; padding: 9px 12px; border-radius: 9px; border: 1px solid transparent; }
|
|
18
|
-
input { flex: 1; background: #141821; color: #e6e6e6; border-color: #2e3140; }
|
|
19
|
-
input:focus { outline: none; border-color: #4a7fd4; }
|
|
20
|
-
button { background: #e94560; color: #fff; cursor: pointer; font-weight: 600; }
|
|
21
|
-
button:hover { opacity: .88; }
|
|
22
|
-
button.ghost { background: #2b3040; }
|
|
23
|
-
.result { margin-top: 6px; min-height: 24px; font-size: 15px; color: #50fa7b; word-break: break-all; }
|
|
24
|
-
.tick { margin-top: 10px; font-size: 13px; color: #8be9fd; min-height: 18px; }
|
|
25
|
-
.chk { margin-top: 12px; font-size: 13px; color: #9aa0b4;
|
|
26
|
-
display: flex; align-items: center; gap: 6px; }
|
|
27
|
-
.chk input { flex: none; }
|
|
28
|
-
.foot { margin-top: 18px; font-size: 12px; color: #6b7186; }
|
|
29
|
-
</style>
|
|
30
|
-
</head>
|
|
31
|
-
<body>
|
|
32
|
-
<div class="card">
|
|
33
|
-
<h1>{{PROJECT_NAME}}</h1>
|
|
34
|
-
<p class="sub">仓颉后端 + 系统 WebView 前端 · invoke / listen 双向 IPC · capability 安全模型</p>
|
|
35
|
-
|
|
36
|
-
<div class="row">
|
|
37
|
-
<input id="name" placeholder="输入名字" value="world">
|
|
38
|
-
<button id="greet">greet</button>
|
|
39
|
-
</div>
|
|
40
|
-
<div class="row">
|
|
41
|
-
<button id="timer" class="ghost">启动后端事件推送</button>
|
|
42
|
-
<button id="version" class="ghost">system:version</button>
|
|
43
|
-
</div>
|
|
44
|
-
|
|
45
|
-
<div class="chk">
|
|
46
|
-
<input type="checkbox" id="sidebar" checked>
|
|
47
|
-
<label for="sidebar">侧边栏(对应原生菜单「视图 → 侧边栏」)</label>
|
|
48
|
-
</div>
|
|
49
|
-
|
|
50
|
-
<div id="result" class="result">等待 invoke…</div>
|
|
51
|
-
<div id="tick" class="tick"></div>
|
|
52
|
-
<div id="menu" class="tick"></div>
|
|
53
|
-
<div class="foot">越权命令(未在 capabilities/default.json 声明)会被后端拒绝</div>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<script>
|
|
57
|
-
// 注入的桥(对标 @tauri-apps/api):window.__CJ_TAURI__
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
</
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>{{PROJECT_NAME}}</title>
|
|
6
|
+
<style>
|
|
7
|
+
:root { color-scheme: dark; }
|
|
8
|
+
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: #16161d;
|
|
9
|
+
color: #e6e6e6; margin: 0; min-height: 100vh;
|
|
10
|
+
display: flex; flex-direction: column; align-items: center; justify-content: center; }
|
|
11
|
+
.card { background: #1f2029; border: 1px solid #2e3140; border-radius: 14px;
|
|
12
|
+
padding: 28px 32px; width: min(460px, 86vw);
|
|
13
|
+
box-shadow: 0 12px 32px rgba(0,0,0,.45); }
|
|
14
|
+
h1 { margin: 0 0 4px; font-size: 22px; color: #7ce7ff; }
|
|
15
|
+
.sub { margin: 0 0 20px; font-size: 13px; color: #9aa0b4; }
|
|
16
|
+
.row { display: flex; gap: 8px; margin: 14px 0; }
|
|
17
|
+
input, button { font-size: 15px; padding: 9px 12px; border-radius: 9px; border: 1px solid transparent; }
|
|
18
|
+
input { flex: 1; background: #141821; color: #e6e6e6; border-color: #2e3140; }
|
|
19
|
+
input:focus { outline: none; border-color: #4a7fd4; }
|
|
20
|
+
button { background: #e94560; color: #fff; cursor: pointer; font-weight: 600; }
|
|
21
|
+
button:hover { opacity: .88; }
|
|
22
|
+
button.ghost { background: #2b3040; }
|
|
23
|
+
.result { margin-top: 6px; min-height: 24px; font-size: 15px; color: #50fa7b; word-break: break-all; }
|
|
24
|
+
.tick { margin-top: 10px; font-size: 13px; color: #8be9fd; min-height: 18px; }
|
|
25
|
+
.chk { margin-top: 12px; font-size: 13px; color: #9aa0b4;
|
|
26
|
+
display: flex; align-items: center; gap: 6px; }
|
|
27
|
+
.chk input { flex: none; }
|
|
28
|
+
.foot { margin-top: 18px; font-size: 12px; color: #6b7186; }
|
|
29
|
+
</style>
|
|
30
|
+
</head>
|
|
31
|
+
<body>
|
|
32
|
+
<div class="card">
|
|
33
|
+
<h1>{{PROJECT_NAME}}</h1>
|
|
34
|
+
<p class="sub">仓颉后端 + 系统 WebView 前端 · invoke / listen 双向 IPC · capability 安全模型</p>
|
|
35
|
+
|
|
36
|
+
<div class="row">
|
|
37
|
+
<input id="name" placeholder="输入名字" value="world">
|
|
38
|
+
<button id="greet">greet</button>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="row">
|
|
41
|
+
<button id="timer" class="ghost">启动后端事件推送</button>
|
|
42
|
+
<button id="version" class="ghost">system:version</button>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div class="chk">
|
|
46
|
+
<input type="checkbox" id="sidebar" checked>
|
|
47
|
+
<label for="sidebar">侧边栏(对应原生菜单「视图 → 侧边栏」)</label>
|
|
48
|
+
</div>
|
|
49
|
+
|
|
50
|
+
<div id="result" class="result">等待 invoke…</div>
|
|
51
|
+
<div id="tick" class="tick"></div>
|
|
52
|
+
<div id="menu" class="tick"></div>
|
|
53
|
+
<div class="foot">越权命令(未在 capabilities/default.json 声明)会被后端拒绝</div>
|
|
54
|
+
</div>
|
|
55
|
+
|
|
56
|
+
<script>
|
|
57
|
+
// 注入的桥(对标 @tauri-apps/api):window.__CJ_TAURI__
|
|
58
|
+
// ③ 改页面从这看起:tauri.invoke 调后端命令、tauri.listen 收后端事件
|
|
59
|
+
// (新命令记得在 src/main.cj 实现,并在 assets/capabilities/default.json 放行)
|
|
60
|
+
function withBridge(cb) {
|
|
61
|
+
if (window.__CJ_TAURI__) { cb(window.__CJ_TAURI__); return; }
|
|
62
|
+
setTimeout(function () { withBridge(cb); }, 50);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
withBridge(function (tauri) {
|
|
66
|
+
var result = document.getElementById('result');
|
|
67
|
+
var tick = document.getElementById('tick');
|
|
68
|
+
|
|
69
|
+
function show(text, ok) {
|
|
70
|
+
result.textContent = text;
|
|
71
|
+
result.style.color = ok === false ? '#ff6b81' : '#50fa7b';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// JS → 仓颉
|
|
75
|
+
document.getElementById('greet').onclick = function () {
|
|
76
|
+
var name = document.getElementById('name').value || 'world';
|
|
77
|
+
tauri.invoke('greet', { name: name })
|
|
78
|
+
.then(function (data) { show('invoke OK: ' + data); })
|
|
79
|
+
.catch(function (err) { show('invoke FAIL: ' + err.message, false); });
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
document.getElementById('version').onclick = function () {
|
|
83
|
+
tauri.invoke('system:version')
|
|
84
|
+
.then(function (data) { show('system:version -> ' + JSON.stringify(data)); })
|
|
85
|
+
.catch(function (err) { show('system:version FAIL: ' + err.message, false); });
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// 仓颉 → JS(事件推送)
|
|
89
|
+
document.getElementById('timer').onclick = function () {
|
|
90
|
+
tauri.invoke('timer')
|
|
91
|
+
.then(function (d) { show('后端: ' + d); })
|
|
92
|
+
.catch(function (err) { show('timer FAIL: ' + err.message, false); });
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
tauri.listen('tick', function (payload) {
|
|
96
|
+
tick.textContent = '收到后端事件 tick #' + payload.n;
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// 原生菜单 → 页面:菜单被点后宿主推事件过来(capabilities 里要声明 menu:click)
|
|
100
|
+
var menuLine = document.getElementById('menu');
|
|
101
|
+
tauri.listen('menu:click', function (payload) {
|
|
102
|
+
menuLine.textContent = '菜单被点: ' + payload.id +
|
|
103
|
+
'(enabled=' + payload.enabled + ', checked=' + payload.checked + ')';
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// 页面 → 原生菜单:menu 插件的前端 shim(window.__CJ_TAURI__.menu,注入在 document start)
|
|
107
|
+
document.getElementById('sidebar').onchange = function (e) {
|
|
108
|
+
if (!tauri.menu) {
|
|
109
|
+
show('未注入 menu 插件 shim(页面来自 runUrl 时插件 JS 不在本进程)', false);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
var checked = e.target.checked;
|
|
113
|
+
tauri.menu.setChecked({ id: 'view.sidebar', checked: checked })
|
|
114
|
+
.then(function () { show('原生菜单「侧边栏」已同步为 ' + checked); })
|
|
115
|
+
.catch(function (err) { show('menu.setChecked FAIL: ' + err.message, false); });
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
</script>
|
|
119
|
+
</body>
|
|
120
|
+
</html>
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
# cj-tauri 应用清单——整个工程的单一真相(RFC-002 §7)。
|
|
2
|
-
# cj-tauri sync 从这里派生 targets/ 骨架(desktop/ohos);cj-tauri check 校验它并检测骨架漂移。
|
|
3
|
-
[app]
|
|
4
|
-
name = "{{PROJECT_NAME}}"
|
|
5
|
-
version = "0.1.0"
|
|
6
|
-
# 应用标识:桌面是安装 ID,鸿蒙直接是 bundleName(每段须字母开头、只含字母数字下划线)
|
|
7
|
-
id = "{{BUNDLE_NAME}}"
|
|
8
|
-
# 业务包名(cjpm 约束①:toml 模块名必须等于源包名)
|
|
9
|
-
package = "{{PACKAGE_NAME}}"
|
|
10
|
-
|
|
11
|
-
[[windows]]
|
|
12
|
-
label = "main"
|
|
13
|
-
title = "{{PROJECT_NAME}}"
|
|
14
|
-
width = 1000
|
|
15
|
-
height = 700
|
|
16
|
-
|
|
17
|
-
[assets]
|
|
18
|
-
# 骨架 launcher 加载的页面(相对资产根 assets/);dev 模式自动改写到 Vite dev server
|
|
19
|
-
page = "ui/index.html"
|
|
20
|
-
|
|
21
|
-
[capabilities]
|
|
22
|
-
dir = "assets/capabilities"
|
|
1
|
+
# cj-tauri 应用清单——整个工程的单一真相(RFC-002 §7)。
|
|
2
|
+
# cj-tauri sync 从这里派生 targets/ 骨架(desktop/ohos);cj-tauri check 校验它并检测骨架漂移。
|
|
3
|
+
[app]
|
|
4
|
+
name = "{{PROJECT_NAME}}"
|
|
5
|
+
version = "0.1.0"
|
|
6
|
+
# 应用标识:桌面是安装 ID,鸿蒙直接是 bundleName(每段须字母开头、只含字母数字下划线)
|
|
7
|
+
id = "{{BUNDLE_NAME}}"
|
|
8
|
+
# 业务包名(cjpm 约束①:toml 模块名必须等于源包名)
|
|
9
|
+
package = "{{PACKAGE_NAME}}"
|
|
10
|
+
|
|
11
|
+
[[windows]]
|
|
12
|
+
label = "main"
|
|
13
|
+
title = "{{PROJECT_NAME}}"
|
|
14
|
+
width = 1000
|
|
15
|
+
height = 700
|
|
16
|
+
|
|
17
|
+
[assets]
|
|
18
|
+
# 骨架 launcher 加载的页面(相对资产根 assets/);dev 模式自动改写到 Vite dev server
|
|
19
|
+
page = "ui/index.html"
|
|
20
|
+
|
|
21
|
+
[capabilities]
|
|
22
|
+
dir = "assets/capabilities"
|
|
23
|
+
|
|
24
|
+
[links]
|
|
25
|
+
# 各目标端**追加**的链接选项(拼在框架默认值之后;留空 = 只用默认)。
|
|
26
|
+
# 什么时候需要它:要调的原生能力在仓颉 SDK 里没有绑定,只能 FFI 直连系统库——
|
|
27
|
+
# 符号必须出现在最终链接那一侧,而那份 cjpm.toml 是 sync 生成的、不能手改。
|
|
28
|
+
# 例:鸿蒙读设备电量走系统 C API(ohbattery_info.h),写 ohos = "-lohbattery_info"
|
|
29
|
+
# 三端分开写是因为同一个库在三端上名字通常不同(-lfoo / foo.lib / -lfoo_ndk.z)。
|
|
30
|
+
desktop-linux = ""
|
|
31
|
+
desktop-windows = ""
|
|
32
|
+
ohos = ""
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
# 业务包:业务代码的唯一真相(RFC-002 §7.3——骨架永远是外壳,业务只有一份)。
|
|
2
|
-
# output-type = "static":桌面骨架(targets/desktop)与鸿蒙入口(targets/ohos/entry)
|
|
3
|
-
# 都以 path 依赖引用本包——同一份业务代码,多个目标各编各的产物。
|
|
4
|
-
[package]
|
|
5
|
-
cjc-version = "{{CJC_VERSION}}"
|
|
6
|
-
name = "{{PACKAGE_NAME}}"
|
|
7
|
-
description = "{{PROJECT_NAME}} - cj-tauri 业务包"
|
|
8
|
-
version = "0.1.0"
|
|
9
|
-
target-dir = ""
|
|
10
|
-
output-type = "static"
|
|
11
|
-
compile-option = ""
|
|
12
|
-
override-compile-option = ""
|
|
13
|
-
link-option = ""
|
|
14
|
-
package-configuration = {}
|
|
15
|
-
|
|
16
|
-
[dependencies]
|
|
17
|
-
# cj-tauri 框架本体(由 cj-tauri create 写入的本机路径;换机器重跑 create 或手改)
|
|
18
|
-
cjTauri = { path = "{{FRAMEWORK_ROOT_TOML}}" }
|
|
19
|
-
|
|
20
|
-
[target.x86_64-unknown-linux-gnu.bin-dependencies]
|
|
21
|
-
path-option = ["${CANGJIE_STDX}"]
|
|
22
|
-
|
|
23
|
-
[target.x86_64-w64-mingw32.bin-dependencies]
|
|
24
|
-
path-option = ["${CANGJIE_STDX}"]
|
|
25
|
-
|
|
26
|
-
[target.aarch64-linux-ohos]
|
|
27
|
-
# 鸿蒙目标:交叉编译工具链与 sysroot 由 DevEco 仓颉套件提供,路径全部走环境变量
|
|
28
|
-
# (与框架根 cjpm.toml 同口径;末尾 --dy-std 不可省,原因见框架根 toml 的鸿蒙段注释)
|
|
29
|
-
compile-option = "-B \"${DEVECO_CANGJIE_HOME}/build-tools/third_party/llvm/bin\" -B \"${DEVECO_OH_NATIVE_HOME}/sysroot/usr/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/sysroot/usr/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/llvm/lib/clang/15.0.4/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/llvm/lib/aarch64-linux-ohos\" --sysroot \"${DEVECO_OH_NATIVE_HOME}/sysroot\" --dy-std"
|
|
30
|
-
|
|
31
|
-
[target.aarch64-linux-ohos.bin-dependencies]
|
|
32
|
-
# stdx 必须用鸿蒙版(CANGJIE_STDX_OHOS,桌面版 ABI 不通);CANGJIE_OHOS_LIBS 指 DevEco
|
|
33
|
-
# 套件的 api/lib/linux_ohos_aarch64_cjnative/ohos(仓颉标准库 + ohos API 绑定)
|
|
34
|
-
path-option = ["${CANGJIE_STDX_OHOS}", "${CANGJIE_OHOS_LIBS}", "${AARCH64_MACRO_LIBS}", "${AARCH64_KIT_LIBS}"]
|
|
1
|
+
# 业务包:业务代码的唯一真相(RFC-002 §7.3——骨架永远是外壳,业务只有一份)。
|
|
2
|
+
# output-type = "static":桌面骨架(targets/desktop)与鸿蒙入口(targets/ohos/entry)
|
|
3
|
+
# 都以 path 依赖引用本包——同一份业务代码,多个目标各编各的产物。
|
|
4
|
+
[package]
|
|
5
|
+
cjc-version = "{{CJC_VERSION}}"
|
|
6
|
+
name = "{{PACKAGE_NAME}}"
|
|
7
|
+
description = "{{PROJECT_NAME}} - cj-tauri 业务包"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
target-dir = ""
|
|
10
|
+
output-type = "static"
|
|
11
|
+
compile-option = ""
|
|
12
|
+
override-compile-option = ""
|
|
13
|
+
link-option = ""
|
|
14
|
+
package-configuration = {}
|
|
15
|
+
|
|
16
|
+
[dependencies]
|
|
17
|
+
# cj-tauri 框架本体(由 cj-tauri create 写入的本机路径;换机器重跑 create 或手改)
|
|
18
|
+
cjTauri = { path = "{{FRAMEWORK_ROOT_TOML}}" }
|
|
19
|
+
|
|
20
|
+
[target.x86_64-unknown-linux-gnu.bin-dependencies]
|
|
21
|
+
path-option = ["${CANGJIE_STDX}"]
|
|
22
|
+
|
|
23
|
+
[target.x86_64-w64-mingw32.bin-dependencies]
|
|
24
|
+
path-option = ["${CANGJIE_STDX}"]
|
|
25
|
+
|
|
26
|
+
[target.aarch64-linux-ohos]
|
|
27
|
+
# 鸿蒙目标:交叉编译工具链与 sysroot 由 DevEco 仓颉套件提供,路径全部走环境变量
|
|
28
|
+
# (与框架根 cjpm.toml 同口径;末尾 --dy-std 不可省,原因见框架根 toml 的鸿蒙段注释)
|
|
29
|
+
compile-option = "-B \"${DEVECO_CANGJIE_HOME}/build-tools/third_party/llvm/bin\" -B \"${DEVECO_OH_NATIVE_HOME}/sysroot/usr/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/sysroot/usr/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/llvm/lib/clang/15.0.4/lib/aarch64-linux-ohos\" -L \"${DEVECO_OH_NATIVE_HOME}/llvm/lib/aarch64-linux-ohos\" --sysroot \"${DEVECO_OH_NATIVE_HOME}/sysroot\" --dy-std"
|
|
30
|
+
|
|
31
|
+
[target.aarch64-linux-ohos.bin-dependencies]
|
|
32
|
+
# stdx 必须用鸿蒙版(CANGJIE_STDX_OHOS,桌面版 ABI 不通);CANGJIE_OHOS_LIBS 指 DevEco
|
|
33
|
+
# 套件的 api/lib/linux_ohos_aarch64_cjnative/ohos(仓颉标准库 + ohos API 绑定)
|
|
34
|
+
path-option = ["${CANGJIE_STDX_OHOS}", "${CANGJIE_OHOS_LIBS}", "${AARCH64_MACRO_LIBS}", "${AARCH64_KIT_LIBS}"]
|
|
@@ -1,90 +1,101 @@
|
|
|
1
|
-
package {{PACKAGE_NAME}}
|
|
2
|
-
|
|
3
|
-
import cjTauri.*
|
|
4
|
-
import cjTauri.plugins.menu.*
|
|
5
|
-
import stdx.encoding.json.*
|
|
6
|
-
import std.collection.*
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
})
|
|
90
|
-
|
|
1
|
+
package {{PACKAGE_NAME}}
|
|
2
|
+
|
|
3
|
+
import cjTauri.*
|
|
4
|
+
import cjTauri.plugins.menu.*
|
|
5
|
+
import stdx.encoding.json.*
|
|
6
|
+
import std.collection.*
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* ── 把这个骨架变成你的应用,改三处就够了 ──────────────────────────────
|
|
10
|
+
* ① 写命令:照下面的 GreetCommand 抄一个,并在 build() 里 register;
|
|
11
|
+
* ② 放行:assets/capabilities/default.json 的 commands 里加上命令名
|
|
12
|
+
* (只写代码不放行 = 前端拿到 command not allowed);
|
|
13
|
+
* ③ 改页面:assets/ui/index.html 里用 tauri.invoke 调你的命令。
|
|
14
|
+
* 进阶(插件 / 菜单 / 多窗口)见项目根的 docs/使用文档.md 与 docs/RFC-插件体系.md。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* ① 写命令从这抄:实现 CommandHandler,再在下面 build() 里 register
|
|
19
|
+
* greet 命令(对标 tauri command)
|
|
20
|
+
* 前端:tauri.invoke("greet", { name: "..." })
|
|
21
|
+
*/
|
|
22
|
+
public class GreetCommand <: CommandHandler {
|
|
23
|
+
public init() {}
|
|
24
|
+
|
|
25
|
+
public func handle(cmd: String, args: JsonObject, ipc: IpcContext): JsonValue {
|
|
26
|
+
var name = "world"
|
|
27
|
+
if (let Some(n) <- args.get("name")) {
|
|
28
|
+
match (n.kind()) {
|
|
29
|
+
case JsonKind.JsString => name = n.asString().getValue()
|
|
30
|
+
case _ => ()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return JsonString("Hello, ${name}! 来自仓颉后端")
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 定时器命令:启动后台线程,每秒向前端推一个 tick 事件(验证 仓颉 → JS 通道)
|
|
39
|
+
* 前端:tauri.listen("tick", cb) + tauri.invoke("timer")
|
|
40
|
+
*/
|
|
41
|
+
public class TimerCommand <: CommandHandler {
|
|
42
|
+
private var counter: Int64 = 0
|
|
43
|
+
private var started: Bool = false
|
|
44
|
+
|
|
45
|
+
public init() {}
|
|
46
|
+
|
|
47
|
+
public func handle(cmd: String, args: JsonObject, ipc: IpcContext): JsonValue {
|
|
48
|
+
if (!this.started) {
|
|
49
|
+
this.started = true
|
|
50
|
+
spawn {
|
|
51
|
+
while (true) {
|
|
52
|
+
sleep(Duration.second)
|
|
53
|
+
this.counter += 1
|
|
54
|
+
var payload = JsonObject()
|
|
55
|
+
payload.put("n", JsonInt(this.counter))
|
|
56
|
+
ipc.emit("tick", payload)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return JsonString("timer started")
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 演示菜单:一个普通项 + 一个带勾选项的子菜单
|
|
66
|
+
*
|
|
67
|
+
* 两个方向都在页面上看得到:
|
|
68
|
+
* 菜单 → 页面:点「打个招呼」,宿主把事件推给前端(页面 listen("menu:click") 显示 id)
|
|
69
|
+
* 页面 → 菜单:勾选页面上的复选框,走 menu 插件改「侧边栏」这一项的勾选状态
|
|
70
|
+
*/
|
|
71
|
+
func demoMenu(): MenuModel {
|
|
72
|
+
var view = ArrayList<MenuItem>()
|
|
73
|
+
view.add(MenuItem.checkbox("view.sidebar", "侧边栏", true))
|
|
74
|
+
var items = ArrayList<MenuItem>()
|
|
75
|
+
items.add(MenuItem.normal("file.hello", "打个招呼"))
|
|
76
|
+
items.add(MenuItem.submenu("视图", view))
|
|
77
|
+
return MenuModel(items)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 业务装配点(RFC-002 §4.1):骨架的 launcher(targets/ 下各目标的 src)调用它取 AppSpec。
|
|
82
|
+
*
|
|
83
|
+
* 零平台知识:不碰宿主、不知道页面文件路径、不知道能力目录——那些由清单
|
|
84
|
+
* (cj-tauri.toml)决定,launcher 按清单覆盖(page/window/assets/capabilities)。
|
|
85
|
+
* build() 负责业务自己的部分:命令注册、菜单、插件。
|
|
86
|
+
*/
|
|
87
|
+
public func build(): AppSpec {
|
|
88
|
+
return AppSpec()
|
|
89
|
+
.window(WindowConfig("{{PROJECT_NAME}}", 1000, 700))
|
|
90
|
+
// menu 插件:给前端挂 window.__CJ_TAURI__.menu.setEnabled / setChecked
|
|
91
|
+
// (插件只声明「我提供什么」,**不自动放行**——要能调,就在 capabilities 里引用
|
|
92
|
+
// permissions: ["menu:state"],或逐条写 commands)
|
|
93
|
+
.plugin(MenuPlugin())
|
|
94
|
+
.wire({ app =>
|
|
95
|
+
// ① 新命令在这里 register;② 别忘了去 capabilities/default.json 放行
|
|
96
|
+
app.register("greet", GreetCommand())
|
|
97
|
+
app.register("timer", TimerCommand())
|
|
98
|
+
// 菜单栏必须在 run 之前挂:预置类宿主能力要赶在页面加载前定稿
|
|
99
|
+
app.setMenu(demoMenu())
|
|
100
|
+
})
|
|
101
|
+
}
|