@native-sdk/cli 0.8.4 → 0.9.1
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/build/app.zig +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +109 -1
- package/src/embed/root.zig +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +189 -4
- package/src/tooling/ts_core.zig +366 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +442 -27
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
//! The generated mobile wiring for a TypeScript app core — staged (never
|
|
2
|
+
//! written into the app) by the framework build beside the desktop entry
|
|
3
|
+
//! when the tree carries src/core.ts and the target is iOS or Android. The
|
|
4
|
+
//! embed static library's `app` module roots here: the file satisfies the
|
|
5
|
+
//! embed host's AppDef contract (`Model`, `Msg`, `initModel`,
|
|
6
|
+
//! `mobileOptions` — see `src/embed/ui_host.zig`) over the same staged
|
|
7
|
+
//! mirror (core.zig), markup (app.native), service registry (services.zig),
|
|
8
|
+
//! and carrier constant (service_carrier.zig) the desktop wiring uses.
|
|
9
|
+
//!
|
|
10
|
+
//! What differs from ts_core_main.zig is only the shell:
|
|
11
|
+
//!
|
|
12
|
+
//! scene the canonical single-surface mobile scene (window 1, one
|
|
13
|
+
//! gpu_surface labeled "mobile-surface") plus the app.zon
|
|
14
|
+
//! shell's declared platform chrome (tabs, primary action) —
|
|
15
|
+
//! the toolkit hosts project those as real system controls.
|
|
16
|
+
//! services the in-process pool is the ONLY carrier on mobile (no
|
|
17
|
+
//! child processes exist there); the build graph resolves
|
|
18
|
+
//! auto to in_process, and this file refuses a staged child
|
|
19
|
+
//! selection at comptime. The pool's marker/relay files live
|
|
20
|
+
//! in the OS app-data directory the shim installs through
|
|
21
|
+
//! `native_sdk_app_set_data_root` (the `serviceDataRoot`
|
|
22
|
+
//! hook below).
|
|
23
|
+
//! data dir a core exporting `envMsgs` with `NATIVE_SDK_APP_DATA_DIR`
|
|
24
|
+
//! receives the same shim-installed directory as a journaled
|
|
25
|
+
//! Msg right after the boot command.
|
|
26
|
+
//!
|
|
27
|
+
//! Model persistence (`persist`), boot images, and URL media caching are
|
|
28
|
+
//! not wired on mobile yet; the corresponding core commands degrade the
|
|
29
|
+
//! way the adapter documents (snapshots never write, views keep their
|
|
30
|
+
//! fallbacks, URL playback re-streams).
|
|
31
|
+
//!
|
|
32
|
+
//! Editing this file is never core-level work: it carries no app logic and
|
|
33
|
+
//! regenerates from the SDK on every build.
|
|
34
|
+
|
|
35
|
+
const std = @import("std");
|
|
36
|
+
const native_sdk = @import("native_sdk");
|
|
37
|
+
const manifest = @import("app_manifest_zon");
|
|
38
|
+
pub const core = @import("core.zig");
|
|
39
|
+
const services = @import("services.zig");
|
|
40
|
+
const service_carrier = @import("service_carrier.zig");
|
|
41
|
+
|
|
42
|
+
const Adapter = native_sdk.TsUiApp(core);
|
|
43
|
+
|
|
44
|
+
/// Re-exported for the embed host's AppDef contract (and any test that
|
|
45
|
+
/// reflects the core's real surface).
|
|
46
|
+
pub const Model = core.Model;
|
|
47
|
+
pub const Msg = core.Msg;
|
|
48
|
+
|
|
49
|
+
pub const app_markup = @embedFile("app.native");
|
|
50
|
+
|
|
51
|
+
comptime {
|
|
52
|
+
// The build graph resolves the carrier before staging this file; a
|
|
53
|
+
// staged child selection on a mobile target is a build-graph defect,
|
|
54
|
+
// not an app author's error.
|
|
55
|
+
if (services.enabled and service_carrier.kind == .child) {
|
|
56
|
+
@compileError("mobile TypeScript services run on the in-process pool; the child carrier cannot be staged here");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const use_pool = services.enabled and service_carrier.kind == .in_process;
|
|
61
|
+
const PoolTransport = native_sdk.ServicePool(services);
|
|
62
|
+
|
|
63
|
+
const app_data_dir_env = "NATIVE_SDK_APP_DATA_DIR";
|
|
64
|
+
|
|
65
|
+
const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
|
|
66
|
+
|
|
67
|
+
/// The canonical mobile surface plus the app's declared platform chrome.
|
|
68
|
+
const mobile_scene: native_sdk.app_manifest.ShellConfig = .{
|
|
69
|
+
.windows = native_sdk.embed.mobile_shell_scene.windows,
|
|
70
|
+
.chrome = shell_scene.chrome,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Adapter-held mobile state (container-level, like the adapter's own
|
|
74
|
+
// install stores — one live app per core module is the v1 contract): the
|
|
75
|
+
// pool, its executor, and the shim-installed app-data directory.
|
|
76
|
+
var pool_io_state: std.Io.Threaded = undefined;
|
|
77
|
+
var pool_transport: PoolTransport = undefined;
|
|
78
|
+
var data_root_buffer: [native_sdk.embed.max_mobile_asset_root_bytes]u8 = undefined;
|
|
79
|
+
var env_entries: [envMsgsLen()]Adapter.EnvValue = undefined;
|
|
80
|
+
var env_entry_count: usize = 0;
|
|
81
|
+
var env_value_copies: [envMsgsLen()][]u8 = undefined;
|
|
82
|
+
var env_value_copy_count: usize = 0;
|
|
83
|
+
var data_root_env_indices: [envMsgsLen()]usize = undefined;
|
|
84
|
+
var data_root_env_count: usize = 0;
|
|
85
|
+
|
|
86
|
+
/// The embed host calls `mobileOptions()` first (UiAppHost.create), so the
|
|
87
|
+
/// boot model is committed by the time `initModel` reads it.
|
|
88
|
+
pub fn initModel() Model {
|
|
89
|
+
return Adapter.Host.model().*;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub fn mobileOptions() Adapter.Options {
|
|
93
|
+
if (comptime @hasDecl(core.Model, "windows")) {
|
|
94
|
+
@compileError("model-declared secondary windows are a desktop shell capability; omit windows(model) from mobile targets");
|
|
95
|
+
}
|
|
96
|
+
var options: Adapter.Options = .{
|
|
97
|
+
.name = manifest.name,
|
|
98
|
+
.scene = mobile_scene,
|
|
99
|
+
.canvas_label = native_sdk.embed.mobile_gpu_surface_label,
|
|
100
|
+
.markup = .{ .source = app_markup },
|
|
101
|
+
// app.zon's theme pack and one-accent override, same as desktop.
|
|
102
|
+
.theme = comptime manifestThemePack(),
|
|
103
|
+
.theme_accent = comptime manifestThemeAccent(),
|
|
104
|
+
};
|
|
105
|
+
if (comptime @hasDecl(core, "commandMsg")) {
|
|
106
|
+
// Projected chrome (tabs, primary action) dispatches through the
|
|
107
|
+
// core's exported command mapper.
|
|
108
|
+
options.on_command = core.commandMsg;
|
|
109
|
+
}
|
|
110
|
+
return Adapter.mobileOptions(coreOptions(), options);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn coreOptions() Adapter.CoreOptions {
|
|
114
|
+
freeEnvValueCopies();
|
|
115
|
+
var core_options: Adapter.CoreOptions = .{};
|
|
116
|
+
if (comptime use_pool) {
|
|
117
|
+
// The pool's own executor: mobile has no `std.process.Init` to
|
|
118
|
+
// thread an Io from. Nothing starts before the first real request,
|
|
119
|
+
// so constructing the pool here keeps replay semantics intact.
|
|
120
|
+
pool_io_state = std.Io.Threaded.init(std.heap.page_allocator, .{});
|
|
121
|
+
pool_transport = PoolTransport.init(
|
|
122
|
+
std.heap.page_allocator,
|
|
123
|
+
pool_io_state.io(),
|
|
124
|
+
"",
|
|
125
|
+
.{ .max_workers = service_carrier.pool_workers },
|
|
126
|
+
);
|
|
127
|
+
core_options.host_calls = pool_transport.binding();
|
|
128
|
+
}
|
|
129
|
+
if (comptime services.enabled) {
|
|
130
|
+
core_options.service_results = .{
|
|
131
|
+
.index_fn = services.indexOf,
|
|
132
|
+
.streaming_fn = services.isStreaming,
|
|
133
|
+
.decode_fn = services.resultDecoder(core),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
env_entry_count = 0;
|
|
137
|
+
data_root_env_count = 0;
|
|
138
|
+
if (comptime @hasDecl(core, "envMsgs")) {
|
|
139
|
+
inline for (core.envMsgs) |entry| {
|
|
140
|
+
if (comptime std.mem.eql(u8, entry.env, app_data_dir_env)) {
|
|
141
|
+
// The embed host installs the authoritative app-data path
|
|
142
|
+
// after mobileOptions(), before start. Keep its compacted
|
|
143
|
+
// slot so serviceDataRoot can fill it without trusting an
|
|
144
|
+
// ambient value for this reserved variable.
|
|
145
|
+
data_root_env_indices[data_root_env_count] = env_entry_count;
|
|
146
|
+
data_root_env_count += 1;
|
|
147
|
+
env_entries[env_entry_count] = .{ .msg = entry.msg, .value = "" };
|
|
148
|
+
env_entry_count += 1;
|
|
149
|
+
} else if (std.c.getenv(entry.env)) |value| {
|
|
150
|
+
// Snapshot the process value at launch, matching the desktop
|
|
151
|
+
// runner. Keep an owned copy because later setenv calls may
|
|
152
|
+
// invalidate getenv storage before the first installing frame.
|
|
153
|
+
if (std.heap.page_allocator.dupe(u8, std.mem.span(value))) |copy| {
|
|
154
|
+
env_value_copies[env_value_copy_count] = copy;
|
|
155
|
+
env_value_copy_count += 1;
|
|
156
|
+
env_entries[env_entry_count] = .{ .msg = entry.msg, .value = copy };
|
|
157
|
+
env_entry_count += 1;
|
|
158
|
+
} else |_| {}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
core_options.env_values = env_entries[0..env_entry_count];
|
|
163
|
+
return core_options;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// Embed-host hook (`native_sdk_app_set_data_root`, before start): the
|
|
167
|
+
/// OS-owned app-data directory. The pool's cooperative-cancellation
|
|
168
|
+
/// markers and stream-relay files move here — the one writable directory
|
|
169
|
+
/// both mobile sandboxes guarantee — and a core's `envMsgs` request for
|
|
170
|
+
/// the data directory resolves to it.
|
|
171
|
+
pub fn serviceDataRoot(root: []const u8) void {
|
|
172
|
+
// UiAppHost validates this against the same exported ABI limit before
|
|
173
|
+
// invoking the hook, so every accepted path fits whole.
|
|
174
|
+
std.debug.assert(root.len <= data_root_buffer.len);
|
|
175
|
+
@memcpy(data_root_buffer[0..root.len], root);
|
|
176
|
+
const installed = data_root_buffer[0..root.len];
|
|
177
|
+
if (comptime use_pool) pool_transport.cwd = installed;
|
|
178
|
+
// Keep the whole projection out of a serviceDataRoot instantiation when
|
|
179
|
+
// this core exports no envMsgs. Zig still analyzes a runtime loop body
|
|
180
|
+
// over a zero-length array, so relying on data_root_env_count == 0 would
|
|
181
|
+
// leave `env_entries[index]` as an illegal index into [0]EnvValue.
|
|
182
|
+
if (comptime envMsgsLen() > 0) {
|
|
183
|
+
for (data_root_env_indices[0..data_root_env_count]) |index| {
|
|
184
|
+
env_entries[index].value = installed;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// Embed-host hook (destroy): the pool's shutdown already ran through the
|
|
190
|
+
/// effects binding; this returns its queues and executor.
|
|
191
|
+
pub fn serviceTeardown() void {
|
|
192
|
+
if (comptime use_pool) {
|
|
193
|
+
pool_transport.deinit();
|
|
194
|
+
pool_io_state.deinit();
|
|
195
|
+
}
|
|
196
|
+
freeEnvValueCopies();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fn freeEnvValueCopies() void {
|
|
200
|
+
for (env_value_copies[0..env_value_copy_count]) |copy| {
|
|
201
|
+
std.heap.page_allocator.free(copy);
|
|
202
|
+
}
|
|
203
|
+
env_value_copy_count = 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn envMsgsLen() usize {
|
|
207
|
+
comptime {
|
|
208
|
+
if (!@hasDecl(core, "envMsgs")) return 0;
|
|
209
|
+
return core.envMsgs.len;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// app.zon's theme pack, resolved at comptime (the desktop runner's
|
|
214
|
+
/// `manifestThemePack`, restated here because the mobile module never
|
|
215
|
+
/// links the runner).
|
|
216
|
+
fn manifestThemePack() native_sdk.canvas.ThemePack {
|
|
217
|
+
if (comptime !@hasField(@TypeOf(manifest), "theme")) return .house;
|
|
218
|
+
const name: []const u8 = manifest.theme;
|
|
219
|
+
return comptime native_sdk.canvas.ThemePack.fromName(name) orelse
|
|
220
|
+
@compileError("unknown app.zon theme \"" ++ name ++ "\" — expected one of: house, geist");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// app.zon's one-accent brand override, resolved at comptime (the desktop
|
|
224
|
+
/// runner's `manifestThemeAccent`).
|
|
225
|
+
fn manifestThemeAccent() ?native_sdk.canvas.Color {
|
|
226
|
+
if (comptime !@hasField(@TypeOf(manifest), "theme_accent")) return null;
|
|
227
|
+
const value: []const u8 = manifest.theme_accent;
|
|
228
|
+
return comptime parseHexColor(value) orelse
|
|
229
|
+
@compileError("invalid app.zon theme_accent \"" ++ value ++ "\" — expected a #rrggbb hex color");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
fn parseHexColor(comptime value: []const u8) ?native_sdk.canvas.Color {
|
|
233
|
+
comptime {
|
|
234
|
+
if (value.len != 7 or value[0] != '#') return null;
|
|
235
|
+
var channels: [3]u8 = undefined;
|
|
236
|
+
for (&channels, 0..) |*channel, index| {
|
|
237
|
+
channel.* = std.fmt.parseInt(u8, value[1 + index * 2 .. 3 + index * 2], 16) catch return null;
|
|
238
|
+
}
|
|
239
|
+
return native_sdk.canvas.Color.rgb8(channels[0], channels[1], channels[2]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -51,7 +51,11 @@ pub const fingerprint: u64 = layout_fingerprint.hash(layoutDescription(semantic_
|
|
|
51
51
|
/// enum). Declared-shape changes — new verbs, renamed actions, budget
|
|
52
52
|
/// or naming changes — need NO action here: the fingerprint moves on
|
|
53
53
|
/// its own.
|
|
54
|
-
|
|
54
|
+
/// Epoch 2: status-item snapshots gained stable item identifiers and
|
|
55
|
+
/// visibility, and `tray-action` gained the explicit
|
|
56
|
+
/// `<status-item-id> <menu-item-id>` form (the old one-id primary-item
|
|
57
|
+
/// shorthand remains valid).
|
|
58
|
+
pub const semantic_epoch: u32 = 2;
|
|
55
59
|
|
|
56
60
|
/// The canonical description the protocol fingerprint hashes: the
|
|
57
61
|
/// command vocabulary (the `Action` enum, reflected — names and values,
|
|
@@ -223,12 +223,18 @@ pub const TrayItem = struct {
|
|
|
223
223
|
command: []const u8 = "",
|
|
224
224
|
separator: bool = false,
|
|
225
225
|
enabled: bool = true,
|
|
226
|
+
detail: []const u8 = "",
|
|
227
|
+
role: platform.TrayItemRole = .command,
|
|
228
|
+
key: []const u8 = "",
|
|
229
|
+
modifiers: platform.ShortcutModifiers = .{},
|
|
226
230
|
};
|
|
227
231
|
|
|
228
232
|
/// The live status item (tray): current button title + dropdown items.
|
|
229
233
|
/// The macOS menu bar is outside every window capture, so this is the
|
|
230
234
|
/// only automation-visible evidence a model-driven tray exists.
|
|
231
235
|
pub const Tray = struct {
|
|
236
|
+
id: platform.StatusItemId = platform.primary_status_item_id,
|
|
237
|
+
visible: bool = true,
|
|
232
238
|
title: []const u8 = "",
|
|
233
239
|
items: []const TrayItem = &.{},
|
|
234
240
|
};
|
|
@@ -300,8 +306,8 @@ pub const Input = struct {
|
|
|
300
306
|
/// headroom.
|
|
301
307
|
text_layout_plan_budget: usize = 0,
|
|
302
308
|
text_layout_line_budget: usize = 0,
|
|
303
|
-
///
|
|
304
|
-
|
|
309
|
+
/// Every live status item, keyed by its stable identifier.
|
|
310
|
+
trays: []const Tray = &.{},
|
|
305
311
|
/// Live audio playback, when the app started any (null once stopped
|
|
306
312
|
/// or failed — an idle player is honest, not zeroed-out noise).
|
|
307
313
|
audio: ?Audio = null,
|
|
@@ -382,7 +388,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
382
388
|
},
|
|
383
389
|
);
|
|
384
390
|
if (view.kind == .gpu_surface) {
|
|
385
|
-
try writer.print(" gpu_size={d}x{d} gpu_scale={d} gpu_backend={s} gpu_pixel_format={s} gpu_present_mode={s} gpu_alpha_mode={s} gpu_color_space={s} gpu_vsync={any} gpu_status={s} gpu_present_path={s} gpu_frame={d} gpu_timestamp_ns={d} gpu_frame_interval_ns={d} gpu_input_timestamp_ns={d} gpu_input_latency_ns={d} gpu_input_latency_budget_ns={d} gpu_input_latency_budget_exceeded={d} gpu_input_latency_budget_ok={any} gpu_first_frame_latency_ns={d} gpu_first_frame_latency_budget_ns={d} gpu_first_frame_latency_budget_exceeded={d} gpu_first_frame_latency_budget_ok={any} gpu_nonblank={any} gpu_sample=0x{x:0>8}", .{
|
|
391
|
+
try writer.print(" gpu_size={d}x{d} gpu_scale={d} gpu_backend={s} gpu_pixel_format={s} gpu_present_mode={s} gpu_alpha_mode={s} gpu_color_space={s} gpu_vsync={any} gpu_status={s} gpu_present_path={s} gpu_frame={d} gpu_timestamp_ns={d} gpu_frame_interval_ns={d} gpu_input_count={d} gpu_input_timestamp_ns={d} gpu_input_latency_ns={d} gpu_input_latency_budget_ns={d} gpu_input_latency_budget_exceeded={d} gpu_input_latency_budget_ok={any} gpu_first_frame_latency_ns={d} gpu_first_frame_latency_budget_ns={d} gpu_first_frame_latency_budget_exceeded={d} gpu_first_frame_latency_budget_ok={any} gpu_nonblank={any} gpu_occluded={any} gpu_sample=0x{x:0>8}", .{
|
|
386
392
|
view.gpu_size.width,
|
|
387
393
|
view.gpu_size.height,
|
|
388
394
|
view.gpu_scale_factor,
|
|
@@ -397,6 +403,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
397
403
|
view.gpu_frame_index,
|
|
398
404
|
view.gpu_timestamp_ns,
|
|
399
405
|
view.gpu_frame_interval_ns,
|
|
406
|
+
view.gpu_input_event_count,
|
|
400
407
|
view.gpu_input_timestamp_ns,
|
|
401
408
|
view.gpu_input_latency_ns,
|
|
402
409
|
view.gpu_input_latency_budget_ns,
|
|
@@ -407,6 +414,7 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
407
414
|
view.gpu_first_frame_latency_budget_exceeded_count,
|
|
408
415
|
view.gpu_first_frame_latency_budget_ok,
|
|
409
416
|
view.gpu_frame_nonblank,
|
|
417
|
+
view.gpu_occluded,
|
|
410
418
|
view.gpu_sample_color,
|
|
411
419
|
});
|
|
412
420
|
// Packet-fallback telemetry: WHY the last packet attempt
|
|
@@ -587,18 +595,26 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
587
595
|
try writeWidgetContextMenu(widget, writer);
|
|
588
596
|
try writer.writeByte('\n');
|
|
589
597
|
}
|
|
590
|
-
|
|
591
|
-
try writer.print("tray title=\"{s}\" items={d}\n", .{ tray.title, tray.items.len });
|
|
598
|
+
for (input.trays) |tray| {
|
|
599
|
+
try writer.print("tray #{d} title=\"{s}\" visible={any} items={d}\n", .{ tray.id, tray.title, tray.visible, tray.items.len });
|
|
592
600
|
for (tray.items) |item| {
|
|
593
601
|
if (item.separator) {
|
|
594
602
|
try writer.writeAll(" tray-item separator\n");
|
|
595
603
|
continue;
|
|
596
604
|
}
|
|
597
|
-
try writer.print(" tray-item #{d} label=\"{s}\" command=\"{s}\" enabled={any}\n", .{
|
|
605
|
+
try writer.print(" tray-item #{d} label=\"{s}\" command=\"{s}\" enabled={any} detail=\"{s}\" role={s} key=\"{s}\" modifiers=(primary={any},command={any},control={any},option={any},shift={any})\n", .{
|
|
598
606
|
item.id,
|
|
599
607
|
item.label,
|
|
600
608
|
item.command,
|
|
601
609
|
item.enabled,
|
|
610
|
+
item.detail,
|
|
611
|
+
@tagName(item.role),
|
|
612
|
+
item.key,
|
|
613
|
+
item.modifiers.primary,
|
|
614
|
+
item.modifiers.command,
|
|
615
|
+
item.modifiers.control,
|
|
616
|
+
item.modifiers.option,
|
|
617
|
+
item.modifiers.shift,
|
|
602
618
|
});
|
|
603
619
|
}
|
|
604
620
|
}
|
|
@@ -907,17 +923,17 @@ test "snapshot emits tray title and dropdown items" {
|
|
|
907
923
|
const items = [_]TrayItem{
|
|
908
924
|
.{ .id = 1, .label = "Refresh", .command = "app.refresh" },
|
|
909
925
|
.{ .separator = true },
|
|
910
|
-
.{ .id = 10, .label = "Fix crash on resize", .command = "issue.select.0", .enabled = false },
|
|
926
|
+
.{ .id = 10, .label = "Fix crash on resize", .command = "issue.select.0", .enabled = false, .detail = "warning ⚠", .role = .agent, .key = "q", .modifiers = .{ .command = true } },
|
|
911
927
|
};
|
|
912
928
|
try writeText(.{
|
|
913
929
|
.windows = &windows,
|
|
914
|
-
.
|
|
930
|
+
.trays = &.{.{ .id = 7, .title = "ZN 3", .visible = false, .items = &items }},
|
|
915
931
|
}, &writer);
|
|
916
932
|
const text = writer.buffered();
|
|
917
|
-
try std.testing.expect(std.mem.indexOf(u8, text, "\ntray title=\"ZN 3\" items=3\n") != null);
|
|
918
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true\n") != null);
|
|
933
|
+
try std.testing.expect(std.mem.indexOf(u8, text, "\ntray #7 title=\"ZN 3\" visible=false items=3\n") != null);
|
|
934
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
919
935
|
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
|
|
920
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false\n") != null);
|
|
936
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false detail=\"warning ⚠\" role=agent key=\"q\" modifiers=(primary=false,command=true,control=false,option=false,shift=false)\n") != null);
|
|
921
937
|
|
|
922
938
|
// No tray -> no tray lines.
|
|
923
939
|
var empty_buffer: [512]u8 = undefined;
|
|
@@ -981,6 +997,7 @@ test "snapshot emits GPU surface frame proof" {
|
|
|
981
997
|
.gpu_frame_index = 4,
|
|
982
998
|
.gpu_timestamp_ns = 99,
|
|
983
999
|
.gpu_frame_interval_ns = 8,
|
|
1000
|
+
.gpu_input_event_count = 7,
|
|
984
1001
|
.gpu_input_timestamp_ns = 80,
|
|
985
1002
|
.gpu_input_latency_ns = 19,
|
|
986
1003
|
.gpu_input_latency_budget_ns = 16,
|
|
@@ -991,6 +1008,7 @@ test "snapshot emits GPU surface frame proof" {
|
|
|
991
1008
|
.gpu_first_frame_latency_budget_exceeded_count = 0,
|
|
992
1009
|
.gpu_first_frame_latency_budget_ok = true,
|
|
993
1010
|
.gpu_frame_nonblank = true,
|
|
1011
|
+
.gpu_occluded = true,
|
|
994
1012
|
.gpu_sample_color = 0xff336699,
|
|
995
1013
|
.canvas_revision = 2,
|
|
996
1014
|
.canvas_command_count = 5,
|
|
@@ -1088,6 +1106,7 @@ test "snapshot emits GPU surface frame proof" {
|
|
|
1088
1106
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_frame=4") != null);
|
|
1089
1107
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_timestamp_ns=99") != null);
|
|
1090
1108
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_frame_interval_ns=8") != null);
|
|
1109
|
+
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_count=7") != null);
|
|
1091
1110
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_timestamp_ns=80") != null);
|
|
1092
1111
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_latency_ns=19") != null);
|
|
1093
1112
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_input_latency_budget_ns=16") != null);
|
|
@@ -1098,6 +1117,7 @@ test "snapshot emits GPU surface frame proof" {
|
|
|
1098
1117
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_first_frame_latency_budget_exceeded=0") != null);
|
|
1099
1118
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_first_frame_latency_budget_ok=true") != null);
|
|
1100
1119
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_nonblank=true") != null);
|
|
1120
|
+
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_occluded=true") != null);
|
|
1101
1121
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "gpu_sample=0xff336699") != null);
|
|
1102
1122
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "canvas_revision=2") != null);
|
|
1103
1123
|
try std.testing.expect(std.mem.indexOf(u8, writer.buffered(), "canvas_commands=5") != null);
|
|
@@ -5,7 +5,18 @@
|
|
|
5
5
|
//! (window 1, label "mobile-surface").
|
|
6
6
|
|
|
7
7
|
const native_sdk = @import("native_sdk");
|
|
8
|
+
const mobile_build_options = @import("mobile_build_options");
|
|
9
|
+
const relational_migrations = @import("relational_migrations");
|
|
8
10
|
|
|
9
11
|
comptime {
|
|
10
|
-
native_sdk.embed.exportMobileCApi(native_sdk.embed.
|
|
12
|
+
native_sdk.embed.exportMobileCApi(native_sdk.embed.UiAppHostWithStorageAndCredentials(
|
|
13
|
+
@import("app"),
|
|
14
|
+
mobile_build_options.store_capability,
|
|
15
|
+
mobile_build_options.relational_capability,
|
|
16
|
+
&relational_migrations.migrations,
|
|
17
|
+
mobile_build_options.credentials_capability,
|
|
18
|
+
mobile_build_options.credentials_permission,
|
|
19
|
+
mobile_build_options.filesystem_permission,
|
|
20
|
+
mobile_build_options.credentials_service,
|
|
21
|
+
));
|
|
11
22
|
}
|
package/src/embed/c_api.zig
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
//! for a host type: the fixed WebView shell (`MobileHostApp`, this module's
|
|
5
5
|
//! re-exported default) or a user-app canvas host
|
|
6
6
|
//! (`ui_host.UiAppHost(AppDef)` in libs built via `addMobileLib`). A host
|
|
7
|
-
//! must expose `create`/`destroy`/`start`/`frame
|
|
7
|
+
//! must expose `create`/`destroy`/`start`/`frame` (`destroy` reports whether
|
|
8
|
+
//! callback context must survive), an `embedded`
|
|
8
9
|
//! `EmbeddedApp`, and the error/command/asset bookkeeping fields both
|
|
9
10
|
//! hosts share. `exportMobileCApi(Host)` exports every function under its
|
|
10
11
|
//! canonical symbol name for a static library root.
|
|
@@ -57,7 +58,16 @@ pub fn MobileCApi(comptime Host: type) type {
|
|
|
57
58
|
|
|
58
59
|
pub fn native_sdk_app_destroy(app: ?*anyopaque) callconv(.c) void {
|
|
59
60
|
const self = hostApp(Host, app) orelse return;
|
|
60
|
-
self.destroy();
|
|
61
|
+
_ = self.destroy();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Destroy the app and report whether teardown had to preserve the
|
|
65
|
+
/// host because a detached platform callback may still be running.
|
|
66
|
+
/// A mobile shim that owns the callback context must preserve that
|
|
67
|
+
/// context too when this returns 1.
|
|
68
|
+
pub fn native_sdk_app_destroy_with_status(app: ?*anyopaque) callconv(.c) c_int {
|
|
69
|
+
const self = hostApp(Host, app) orelse return 0;
|
|
70
|
+
return if (self.destroy()) 1 else 0;
|
|
61
71
|
}
|
|
62
72
|
|
|
63
73
|
pub fn native_sdk_app_start(app: ?*anyopaque) callconv(.c) void {
|
|
@@ -195,6 +205,20 @@ pub fn MobileCApi(comptime Host: type) type {
|
|
|
195
205
|
return 1;
|
|
196
206
|
}
|
|
197
207
|
|
|
208
|
+
/// Register or clear the mobile host's OS-backed credential store.
|
|
209
|
+
/// This supplies platform backing only; app.zon capability and
|
|
210
|
+
/// permission gates are still enforced by the runtime.
|
|
211
|
+
pub fn native_sdk_app_set_credential_service(app: ?*anyopaque, service: ?*const types.MobileCredentialService, context: ?*anyopaque) callconv(.c) c_int {
|
|
212
|
+
const self = hostApp(Host, app) orelse return 0;
|
|
213
|
+
const table: types.MobileCredentialService = if (service) |value| value.* else .{};
|
|
214
|
+
host.setCredentialService(self, table, context) catch |err| {
|
|
215
|
+
recordError(self, err);
|
|
216
|
+
return 0;
|
|
217
|
+
};
|
|
218
|
+
self.last_error = null;
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
|
|
198
222
|
/// One report from the shim's audio player (kind ordinals: 0
|
|
199
223
|
/// loaded, 1 position, 2 completed, 3 failed), dispatched into the
|
|
200
224
|
/// embedded runtime exactly like a desktop platform's `.audio`
|
|
@@ -242,6 +266,25 @@ pub fn MobileCApi(comptime Host: type) type {
|
|
|
242
266
|
return 1;
|
|
243
267
|
}
|
|
244
268
|
|
|
269
|
+
/// Supply the OS-owned app-data directory before start. Hosts call
|
|
270
|
+
/// this for every app; non-store host types accept it as a no-op so
|
|
271
|
+
/// the mobile ABI does not vary with capability shedding.
|
|
272
|
+
pub fn native_sdk_app_set_data_root(app: ?*anyopaque, path: ?[*]const u8, len: usize) callconv(.c) c_int {
|
|
273
|
+
const self = hostApp(Host, app) orelse return 0;
|
|
274
|
+
const dir = inputSlice(path, len) catch |err| {
|
|
275
|
+
recordError(self, err);
|
|
276
|
+
return 0;
|
|
277
|
+
};
|
|
278
|
+
if (comptime @hasDecl(Host, "setDataRoot")) {
|
|
279
|
+
self.setDataRoot(dir) catch |err| {
|
|
280
|
+
recordError(self, err);
|
|
281
|
+
return 0;
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
self.last_error = null;
|
|
285
|
+
return 1;
|
|
286
|
+
}
|
|
287
|
+
|
|
245
288
|
pub fn native_sdk_app_touch(app: ?*anyopaque, id: u64, phase: c_int, x: f32, y: f32, pressure: f32) callconv(.c) void {
|
|
246
289
|
const self = hostApp(Host, app) orelse return;
|
|
247
290
|
self.embedded.touch(id, phase, x, y, pressure) catch |err| {
|
|
@@ -748,6 +791,7 @@ const FixedShellApi = MobileCApi(MobileHostApp);
|
|
|
748
791
|
|
|
749
792
|
pub const native_sdk_app_create = FixedShellApi.native_sdk_app_create;
|
|
750
793
|
pub const native_sdk_app_destroy = FixedShellApi.native_sdk_app_destroy;
|
|
794
|
+
pub const native_sdk_app_destroy_with_status = FixedShellApi.native_sdk_app_destroy_with_status;
|
|
751
795
|
pub const native_sdk_app_start = FixedShellApi.native_sdk_app_start;
|
|
752
796
|
pub const native_sdk_app_activate = FixedShellApi.native_sdk_app_activate;
|
|
753
797
|
pub const native_sdk_app_deactivate = FixedShellApi.native_sdk_app_deactivate;
|
|
@@ -759,9 +803,11 @@ pub const native_sdk_app_gpu_frame_state = FixedShellApi.native_sdk_app_gpu_fram
|
|
|
759
803
|
pub const native_sdk_app_text_input_state = FixedShellApi.native_sdk_app_text_input_state;
|
|
760
804
|
pub const native_sdk_app_set_text_measure = FixedShellApi.native_sdk_app_set_text_measure;
|
|
761
805
|
pub const native_sdk_app_set_audio_service = FixedShellApi.native_sdk_app_set_audio_service;
|
|
806
|
+
pub const native_sdk_app_set_credential_service = FixedShellApi.native_sdk_app_set_credential_service;
|
|
762
807
|
pub const native_sdk_app_audio_event = FixedShellApi.native_sdk_app_audio_event;
|
|
763
808
|
pub const native_sdk_app_set_image_service = FixedShellApi.native_sdk_app_set_image_service;
|
|
764
809
|
pub const native_sdk_app_set_automation_dir = FixedShellApi.native_sdk_app_set_automation_dir;
|
|
810
|
+
pub const native_sdk_app_set_data_root = FixedShellApi.native_sdk_app_set_data_root;
|
|
765
811
|
pub const native_sdk_app_touch = FixedShellApi.native_sdk_app_touch;
|
|
766
812
|
pub const native_sdk_app_scroll = FixedShellApi.native_sdk_app_scroll;
|
|
767
813
|
pub const native_sdk_app_key = FixedShellApi.native_sdk_app_key;
|
|
@@ -350,10 +350,9 @@ pub fn mobileTextRangeEnd(range: ?canvas.TextRange) isize {
|
|
|
350
350
|
const value = range orelse return -1;
|
|
351
351
|
return mobileOptionalIndex(value.end);
|
|
352
352
|
}
|
|
353
|
-
///
|
|
354
|
-
///
|
|
355
|
-
///
|
|
353
|
+
/// Monotonic nanoseconds for embed input and frame timestamps. These values
|
|
354
|
+
/// participate in GPU latency and frame-interval subtraction, so they must
|
|
355
|
+
/// share the duration clock used by desktop hosts and runtime presentation.
|
|
356
356
|
pub fn nowNanoseconds() u64 {
|
|
357
|
-
|
|
358
|
-
return if (ns > 0) @intCast(ns) else 0;
|
|
357
|
+
return runtime.monotonicNanoseconds();
|
|
359
358
|
}
|