@native-sdk/cli 0.8.3 → 0.9.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/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -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/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -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 +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -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 +84 -18
- package/packages/core/src/frontend.ts +204 -34
- 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/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -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 +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -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 +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- 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 +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -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 +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- 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 +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- 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 +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -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 +414 -23
- 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,211 @@
|
|
|
1
|
+
//! Tier-2 record-store effect coverage: the public Zig surface remains inert
|
|
2
|
+
//! command data until Effects performs it, and every SQLite answer returns as
|
|
3
|
+
//! the same routed/journaled host-result message family used by TS cores.
|
|
4
|
+
|
|
5
|
+
const std = @import("std");
|
|
6
|
+
const effects_mod = @import("effects.zig");
|
|
7
|
+
const record_store = @import("record_store.zig");
|
|
8
|
+
|
|
9
|
+
const Msg = union(enum) { result: effects_mod.EffectHostResult };
|
|
10
|
+
const Fx = effects_mod.Effects(Msg);
|
|
11
|
+
|
|
12
|
+
fn takeResult(fx: *Fx) !effects_mod.EffectHostResult {
|
|
13
|
+
for (0..100_000) |_| {
|
|
14
|
+
if (fx.takeMsg()) |msg| return msg.result;
|
|
15
|
+
std.Thread.yield() catch {};
|
|
16
|
+
}
|
|
17
|
+
return error.TestExpectedMsg;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
test "record-store effects round-trip CRUD and preserve empty versus missing" {
|
|
21
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
22
|
+
defer store.deinit();
|
|
23
|
+
var fx = Fx.init(std.testing.allocator);
|
|
24
|
+
defer fx.deinit();
|
|
25
|
+
fx.bindRecordStore(store.binding());
|
|
26
|
+
|
|
27
|
+
fx.storeSet(.{ .key = 1, .record_key = "doc/1", .bytes = "", .on_result = Fx.hostMsg(.result) });
|
|
28
|
+
const set = try takeResult(&fx);
|
|
29
|
+
try std.testing.expect(set.ok);
|
|
30
|
+
try std.testing.expectEqual(@as(usize, 0), set.bytes.len);
|
|
31
|
+
|
|
32
|
+
fx.storeGet(.{ .key = 2, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
33
|
+
const hit = try takeResult(&fx);
|
|
34
|
+
try std.testing.expect(hit.ok);
|
|
35
|
+
try std.testing.expectEqualSlices(u8, &.{1}, hit.bytes);
|
|
36
|
+
|
|
37
|
+
fx.storeDelete(.{ .key = 3, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
38
|
+
try std.testing.expect((try takeResult(&fx)).ok);
|
|
39
|
+
fx.storeGet(.{ .key = 4, .record_key = "doc/1", .on_result = Fx.hostMsg(.result) });
|
|
40
|
+
const miss = try takeResult(&fx);
|
|
41
|
+
try std.testing.expect(miss.ok);
|
|
42
|
+
try std.testing.expectEqualSlices(u8, &.{0}, miss.bytes);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test "record-store effects apply setMany atomically and page prefix scans" {
|
|
46
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
47
|
+
defer store.deinit();
|
|
48
|
+
var fx = Fx.init(std.testing.allocator);
|
|
49
|
+
defer fx.deinit();
|
|
50
|
+
fx.bindRecordStore(store.binding());
|
|
51
|
+
|
|
52
|
+
const entries = [_]Fx.StoreEntry{
|
|
53
|
+
.{ .key = "chat/1", .bytes = "one" },
|
|
54
|
+
.{ .key = "chat/2", .bytes = "two" },
|
|
55
|
+
.{ .key = "other/1", .bytes = "skip" },
|
|
56
|
+
};
|
|
57
|
+
fx.storeSetMany(.{ .key = 10, .entries = &entries, .on_result = Fx.hostMsg(.result) });
|
|
58
|
+
try std.testing.expect((try takeResult(&fx)).ok);
|
|
59
|
+
|
|
60
|
+
fx.storeScan(.{ .key = 11, .prefix = "chat/", .limit = 1, .on_result = Fx.hostMsg(.result) });
|
|
61
|
+
const page = try takeResult(&fx);
|
|
62
|
+
try std.testing.expect(page.ok);
|
|
63
|
+
var cursor: usize = 0;
|
|
64
|
+
try std.testing.expectEqual(@as(u32, 1), readU32(page.bytes, &cursor));
|
|
65
|
+
try std.testing.expectEqualStrings("chat/1", readField(page.bytes, &cursor));
|
|
66
|
+
try std.testing.expectEqualStrings("one", readField(page.bytes, &cursor));
|
|
67
|
+
try std.testing.expectEqualStrings("chat/1", readField(page.bytes, &cursor));
|
|
68
|
+
try std.testing.expectEqual(page.bytes.len, cursor);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
test "a synchronous get in the same command walk observes the preceding write" {
|
|
72
|
+
var store = try record_store.Store.openMemory(std.testing.allocator);
|
|
73
|
+
defer store.deinit();
|
|
74
|
+
var fx = Fx.init(std.testing.allocator);
|
|
75
|
+
defer fx.deinit();
|
|
76
|
+
fx.bindRecordStore(store.binding());
|
|
77
|
+
|
|
78
|
+
fx.storeSet(.{ .key = 12, .record_key = "ordered/key", .bytes = "visible", .on_result = Fx.hostMsg(.result) });
|
|
79
|
+
fx.storeGet(.{ .key = 13, .record_key = "ordered/key", .on_result = Fx.hostMsg(.result) });
|
|
80
|
+
|
|
81
|
+
const first = try takeResult(&fx);
|
|
82
|
+
const second = try takeResult(&fx);
|
|
83
|
+
try std.testing.expect(first.ok);
|
|
84
|
+
try std.testing.expect(second.ok);
|
|
85
|
+
const read = if (first.key == 13) first else second;
|
|
86
|
+
try std.testing.expect(read.ok);
|
|
87
|
+
try std.testing.expectEqualSlices(u8, "visible", read.bytes[1..]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test "record-store effects reject bounds and absent capability loudly" {
|
|
91
|
+
var fx = Fx.init(std.testing.allocator);
|
|
92
|
+
defer fx.deinit();
|
|
93
|
+
fx.storeGet(.{ .key = 20, .record_key = "missing", .on_result = Fx.hostMsg(.result) });
|
|
94
|
+
const absent = try takeResult(&fx);
|
|
95
|
+
try std.testing.expect(!absent.ok);
|
|
96
|
+
try std.testing.expectEqualStrings("rejected", absent.bytes);
|
|
97
|
+
|
|
98
|
+
var oversized_key: [record_store.max_key_bytes + 1]u8 = undefined;
|
|
99
|
+
@memset(&oversized_key, 'k');
|
|
100
|
+
fx.storeGet(.{ .key = 21, .record_key = &oversized_key, .on_result = Fx.hostMsg(.result) });
|
|
101
|
+
const bounded = try takeResult(&fx);
|
|
102
|
+
try std.testing.expect(!bounded.ok);
|
|
103
|
+
try std.testing.expectEqualStrings("bad_key", bounded.bytes);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test "record-store requests have capacity independent of generic effects" {
|
|
107
|
+
var fx = Fx.init(std.testing.allocator);
|
|
108
|
+
defer fx.deinit();
|
|
109
|
+
fx.executor = .fake;
|
|
110
|
+
|
|
111
|
+
for (0..effects_mod.max_effects) |index| {
|
|
112
|
+
fx.hostRequest(.{
|
|
113
|
+
.key = 100 + index,
|
|
114
|
+
.name = "fixture.request",
|
|
115
|
+
.on_result = Fx.hostMsg(.result),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
for (0..effects_mod.max_store_effects) |index| {
|
|
119
|
+
fx.storeGet(.{
|
|
120
|
+
.key = 1_000 + index,
|
|
121
|
+
.record_key = "fixture/key",
|
|
122
|
+
.on_result = Fx.hostMsg(.result),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
try std.testing.expectEqual(
|
|
126
|
+
effects_mod.max_effects + effects_mod.max_store_effects,
|
|
127
|
+
fx.pendingHostCount(),
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
fx.storeGet(.{
|
|
131
|
+
.key = 2_000,
|
|
132
|
+
.record_key = "fixture/overflow",
|
|
133
|
+
.on_result = Fx.hostMsg(.result),
|
|
134
|
+
});
|
|
135
|
+
const refused = try takeResult(&fx);
|
|
136
|
+
try std.testing.expect(!refused.ok);
|
|
137
|
+
try std.testing.expectEqualStrings("rejected", refused.bytes);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
test "record-store keys replace on reissue and cancel silently" {
|
|
141
|
+
var fx = Fx.init(std.testing.allocator);
|
|
142
|
+
defer fx.deinit();
|
|
143
|
+
fx.executor = .fake;
|
|
144
|
+
|
|
145
|
+
fx.storeGet(.{ .key = 30, .record_key = "old/key", .on_result = Fx.hostMsg(.result) });
|
|
146
|
+
fx.storeGet(.{ .key = 30, .record_key = "new/key", .on_result = Fx.hostMsg(.result) });
|
|
147
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
148
|
+
const replacement = fx.pendingHostAt(0).?;
|
|
149
|
+
try std.testing.expectEqualStrings("core.store.get", replacement.name);
|
|
150
|
+
var payload_at: usize = 4;
|
|
151
|
+
try std.testing.expectEqualStrings("new/key", readField(replacement.payload, &payload_at));
|
|
152
|
+
try std.testing.expectEqual(replacement.payload.len, payload_at);
|
|
153
|
+
try fx.feedHostResult(30, true, &.{ 1, 'n', 'e', 'w' });
|
|
154
|
+
const result = try takeResult(&fx);
|
|
155
|
+
try std.testing.expectEqual(@as(u64, 30), result.key);
|
|
156
|
+
try std.testing.expectEqualSlices(u8, &.{ 1, 'n', 'e', 'w' }, result.bytes);
|
|
157
|
+
|
|
158
|
+
fx.storeScan(.{ .key = 31, .prefix = "chat/", .on_result = Fx.hostMsg(.result) });
|
|
159
|
+
try std.testing.expectEqual(@as(usize, 1), fx.pendingHostCount());
|
|
160
|
+
fx.cancel(31);
|
|
161
|
+
try std.testing.expectEqual(@as(usize, 0), fx.pendingHostCount());
|
|
162
|
+
try std.testing.expectError(error.EffectNotFound, fx.feedHostResult(31, true, &.{ 0, 0, 0, 0, 0, 0, 0, 0 }));
|
|
163
|
+
try std.testing.expect(fx.takeMsg() == null);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
test "draining a store terminal retires a producer preempted after enqueue" {
|
|
167
|
+
var fx = Fx.init(std.testing.allocator);
|
|
168
|
+
defer fx.deinit();
|
|
169
|
+
fx.executor = .fake;
|
|
170
|
+
|
|
171
|
+
const key = 32;
|
|
172
|
+
fx.storeGet(.{ .key = key, .record_key = "doc/32", .on_result = Fx.hostMsg(.result) });
|
|
173
|
+
try fx.feedHostResult(key, true, &.{0});
|
|
174
|
+
|
|
175
|
+
// Reconstruct the real write worker's preemption window exactly:
|
|
176
|
+
// `storeWorkerMain` publishes the terminal entry, then stores
|
|
177
|
+
// `.draining`. A consumer can acquire the queue between those two
|
|
178
|
+
// operations and observe the queued result while the slot still says
|
|
179
|
+
// `.running`. The fake feed stores first, so rewind just that state.
|
|
180
|
+
for (&fx.slots) |*slot| {
|
|
181
|
+
if (slot.kind == .store and slot.key == key) slot.state.store(.running, .release);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const result = try takeResult(&fx);
|
|
185
|
+
try std.testing.expect(result.ok);
|
|
186
|
+
try std.testing.expectEqualSlices(u8, &.{0}, result.bytes);
|
|
187
|
+
|
|
188
|
+
// Delivery is the key-freeing instant. The drain must publish the
|
|
189
|
+
// terminal state itself rather than depending on the preempted worker
|
|
190
|
+
// to resume before update handles the result.
|
|
191
|
+
for (&fx.slots) |*slot| {
|
|
192
|
+
if (slot.kind != .store or slot.key != key) continue;
|
|
193
|
+
try std.testing.expectEqual(.draining, slot.state.load(.acquire));
|
|
194
|
+
try std.testing.expect(slot.fetch_buffer == null);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
return error.TestExpectedStoreSlot;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
fn readU32(bytes: []const u8, cursor: *usize) u32 {
|
|
201
|
+
const value = std.mem.readInt(u32, bytes[cursor.*..][0..4], .little);
|
|
202
|
+
cursor.* += 4;
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn readField(bytes: []const u8, cursor: *usize) []const u8 {
|
|
207
|
+
const len: usize = @intCast(readU32(bytes, cursor));
|
|
208
|
+
const field = bytes[cursor.*..][0..len];
|
|
209
|
+
cursor.* += len;
|
|
210
|
+
return field;
|
|
211
|
+
}
|
package/src/runtime/flow.zig
CHANGED
|
@@ -185,6 +185,7 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
185
185
|
const runtime_index = try WindowViewMethods().reserveWindow(self, window.id, window.label, window.resolvedTitle(app_info.app_name), null, true, .allow_source_less);
|
|
186
186
|
self.windows[runtime_index].activate_on_show = window.activate_on_show;
|
|
187
187
|
self.windows[runtime_index].info.focused = window.activate_on_show and window.show == .immediate;
|
|
188
|
+
self.windows[runtime_index].info.hidden = window.show == .hidden;
|
|
188
189
|
self.windows[runtime_index].main_focused = self.windows[runtime_index].info.focused;
|
|
189
190
|
self.windows[runtime_index].info.frame = window.default_frame;
|
|
190
191
|
self.windows[runtime_index].main_frame = geometry.RectF.init(0, 0, window.default_frame.width, window.default_frame.height);
|
|
@@ -444,6 +445,13 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
444
445
|
.window_id = command.window_id,
|
|
445
446
|
});
|
|
446
447
|
},
|
|
448
|
+
.tray_command => |command| {
|
|
449
|
+
try dispatchCommand(self, app, .{
|
|
450
|
+
.name = command.name,
|
|
451
|
+
.source = .tray,
|
|
452
|
+
.window_id = command.window_id,
|
|
453
|
+
});
|
|
454
|
+
},
|
|
447
455
|
.timer => |timer_event| {
|
|
448
456
|
try dispatchEvent(self, app, .{ .timer = timer_event });
|
|
449
457
|
},
|
|
@@ -1016,7 +1024,12 @@ pub fn RuntimeFlow(comptime Runtime: type) type {
|
|
|
1016
1024
|
self.command_count += 1;
|
|
1017
1025
|
const enable = std.mem.eql(u8, command.value, "on");
|
|
1018
1026
|
if (!enable and !std.mem.eql(u8, command.value, "off")) return error.InvalidCommand;
|
|
1019
|
-
if (enable and !self.frame_profile.enabled)
|
|
1027
|
+
if (enable and !self.frame_profile.enabled) {
|
|
1028
|
+
self.frame_profile.reset();
|
|
1029
|
+
for (self.views[0..self.view_count]) |*view| {
|
|
1030
|
+
view.gpu_frame_profile_timestamp_ns = 0;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1020
1033
|
self.frame_profile.enabled = enable;
|
|
1021
1034
|
self.invalidateFor(.command, null);
|
|
1022
1035
|
},
|
|
@@ -45,10 +45,13 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
45
45
|
// interval, useless for drop detection). Profiling-gated;
|
|
46
46
|
// a dropped frame shows as max >> p50 on this channel.
|
|
47
47
|
if (self.frame_profile.enabled) {
|
|
48
|
-
const previous_timestamp_ns = self.views[index].
|
|
48
|
+
const previous_timestamp_ns = self.views[index].gpu_frame_profile_timestamp_ns;
|
|
49
49
|
if (previous_timestamp_ns > 0 and frame_event.timestamp_ns > previous_timestamp_ns) {
|
|
50
50
|
self.frame_profile.recordNs(.interval, frame_event.timestamp_ns - previous_timestamp_ns);
|
|
51
51
|
}
|
|
52
|
+
self.views[index].gpu_frame_profile_timestamp_ns = frame_event.timestamp_ns;
|
|
53
|
+
} else {
|
|
54
|
+
self.views[index].gpu_frame_profile_timestamp_ns = 0;
|
|
52
55
|
}
|
|
53
56
|
self.views[index].gpu_timestamp_ns = frame_event.timestamp_ns;
|
|
54
57
|
self.views[index].recordGpuSurfaceFrameInterval(frame_event.frame_interval_ns);
|
|
@@ -106,12 +109,14 @@ pub fn RuntimeGpuSurfaceEvents(comptime Runtime: type) type {
|
|
|
106
109
|
// state 60 times a second.
|
|
107
110
|
const first_frame_latency_recorded = !first_frame_latency_was_recorded and self.views[index].gpu_first_frame_latency_recorded;
|
|
108
111
|
if (self.views[index].gpu_frame_nonblank != frame_event.nonblank or
|
|
112
|
+
self.views[index].gpu_occluded != frame_event.occluded or
|
|
109
113
|
self.views[index].gpu_backend != frame_event.backend or
|
|
110
114
|
first_frame_latency_recorded)
|
|
111
115
|
{
|
|
112
116
|
self.invalidateFor(.state, self.views[index].frame);
|
|
113
117
|
}
|
|
114
118
|
self.views[index].gpu_frame_nonblank = frame_event.nonblank;
|
|
119
|
+
self.views[index].gpu_occluded = frame_event.occluded;
|
|
115
120
|
self.views[index].gpu_sample_color = frame_event.sample_color;
|
|
116
121
|
self.views[index].gpu_backend = frame_event.backend;
|
|
117
122
|
self.views[index].gpu_pixel_format = frame_event.pixel_format;
|
|
@@ -307,6 +307,48 @@ test "runtime dispatches tray item commands" {
|
|
|
307
307
|
try std.testing.expectError(error.InvalidTrayOptions, harness.runtime.updateTrayMenu(&.{.{ .label = "Missing id", .command = "app.missing-id" }}));
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
test "runtime dispatches named tray lifecycle commands with tray source" {
|
|
311
|
+
const TestApp = struct {
|
|
312
|
+
command_count: u32 = 0,
|
|
313
|
+
last_name: []const u8 = "",
|
|
314
|
+
last_source: CommandSource = .runtime,
|
|
315
|
+
last_window_id: platform.WindowId = 0,
|
|
316
|
+
|
|
317
|
+
fn app(self: *@This()) App {
|
|
318
|
+
return .{ .context = self, .name = "tray-lifecycle-command", .source = platform.WebViewSource.html("<p>Tray</p>"), .event_fn = event };
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
fn event(context: *anyopaque, runtime: *Runtime, event_value: Event) anyerror!void {
|
|
322
|
+
_ = runtime;
|
|
323
|
+
const self: *@This() = @ptrCast(@alignCast(context));
|
|
324
|
+
switch (event_value) {
|
|
325
|
+
.command => |command| {
|
|
326
|
+
self.command_count += 1;
|
|
327
|
+
self.last_name = command.name;
|
|
328
|
+
self.last_source = command.source;
|
|
329
|
+
self.last_window_id = command.window_id;
|
|
330
|
+
},
|
|
331
|
+
else => {},
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const harness = try TestHarness().create(std.testing.allocator, .{});
|
|
337
|
+
defer harness.destroy(std.testing.allocator);
|
|
338
|
+
var app_state: TestApp = .{};
|
|
339
|
+
try harness.start(app_state.app());
|
|
340
|
+
|
|
341
|
+
try harness.runtime.dispatchPlatformEvent(app_state.app(), .{ .tray_command = .{
|
|
342
|
+
.name = "app.refresh",
|
|
343
|
+
.window_id = 3,
|
|
344
|
+
} });
|
|
345
|
+
|
|
346
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.command_count);
|
|
347
|
+
try std.testing.expectEqualStrings("app.refresh", app_state.last_name);
|
|
348
|
+
try std.testing.expectEqual(CommandSource.tray, app_state.last_source);
|
|
349
|
+
try std.testing.expectEqual(@as(platform.WindowId, 3), app_state.last_window_id);
|
|
350
|
+
}
|
|
351
|
+
|
|
310
352
|
test "runtime dispatches file drop events to app and window bridge" {
|
|
311
353
|
const TestApp = struct {
|
|
312
354
|
drop_count: u32 = 0,
|