@native-sdk/cli 0.9.0 → 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 +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -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 +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
package/src/runtime/ui_app.zig
CHANGED
|
@@ -12,12 +12,14 @@
|
|
|
12
12
|
//! view. Shell command events can map into messages through `on_command`.
|
|
13
13
|
//!
|
|
14
14
|
//! Secondary windows are model-declared: `Options.windows_fn` returns the
|
|
15
|
-
//! window descriptors that should exist right now (presence IS
|
|
16
|
-
//!
|
|
15
|
+
//! window descriptors that should exist right now (presence IS liveness;
|
|
16
|
+
//! a `.hide` close policy may temporarily hide one),
|
|
17
|
+
//! `Options.window_view` builds each declared window's
|
|
17
18
|
//! canvas tree, the runtime reconciles declared against live windows
|
|
18
19
|
//! after every rebuild, input from any window dispatches Msgs with its
|
|
19
|
-
//! window identity, and a user close dispatches the descriptor's
|
|
20
|
-
//! `on_close` Msg
|
|
20
|
+
//! window identity, and a `.quit` user close dispatches the descriptor's
|
|
21
|
+
//! `on_close` Msg while `.hide` retains it — the platform close-policy
|
|
22
|
+
//! contract applied to model-declared windows.
|
|
21
23
|
//!
|
|
22
24
|
//! Markup apps choose an engine per build: `Options.markup` runs the
|
|
23
25
|
//! runtime parser/interpreter (dev, hot reload), while
|
|
@@ -279,6 +281,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
279
281
|
items: []const platform.TrayMenuItem = &.{},
|
|
280
282
|
};
|
|
281
283
|
|
|
284
|
+
/// One entry in the model-declared status-item collection.
|
|
285
|
+
/// `id` is stable identity; dropping the entry removes that
|
|
286
|
+
/// native status item, while every other field patches in place.
|
|
287
|
+
pub const StatusItemDescriptor = struct {
|
|
288
|
+
id: platform.StatusItemId,
|
|
289
|
+
visible: bool = true,
|
|
290
|
+
state: StatusItemState = .{},
|
|
291
|
+
};
|
|
292
|
+
|
|
282
293
|
/// Scratch handed to `status_item_fn` so a derived title
|
|
283
294
|
/// (`std.fmt.bufPrint(&scratch.title_buffer, "{d} open", ...)`)
|
|
284
295
|
/// and a built-up item list need no model-side storage. Lives on
|
|
@@ -290,20 +301,39 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
290
301
|
items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
291
302
|
};
|
|
292
303
|
|
|
304
|
+
/// Scratch for `status_items_fn`. The flat row store gives each
|
|
305
|
+
/// of the eight status items its full 32-row budget without heap
|
|
306
|
+
/// allocation; TypeScript adapters partition it by descriptor.
|
|
307
|
+
pub const StatusItemsScratch = struct {
|
|
308
|
+
status_items: [platform.max_status_items]StatusItemDescriptor = undefined,
|
|
309
|
+
title_buffers: [platform.max_status_items][platform.max_tray_title_bytes]u8 = undefined,
|
|
310
|
+
arena_buffer: [platform.max_status_items * 2048]u8 = undefined,
|
|
311
|
+
items: [platform.max_status_items * platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
const AppliedStatusItem = struct {
|
|
315
|
+
id: platform.StatusItemId = 0,
|
|
316
|
+
active: bool = false,
|
|
317
|
+
shell_hash: u64 = 0,
|
|
318
|
+
presentation_hash: u64 = 0,
|
|
319
|
+
menu_hash: u64 = 0,
|
|
320
|
+
shell_unsupported: bool = false,
|
|
321
|
+
presentation_unsupported: bool = false,
|
|
322
|
+
};
|
|
323
|
+
|
|
293
324
|
/// Budget for model-declared secondary windows (see
|
|
294
325
|
/// `canvas_limits.max_ui_app_windows` for the sizing rationale).
|
|
295
326
|
pub const max_ui_windows: usize = canvas_limits.max_ui_app_windows;
|
|
296
327
|
|
|
297
328
|
/// A model-declared secondary window (`Options.windows_fn`):
|
|
298
329
|
/// settings, about, inspectors. Identity is `label`; PRESENCE in
|
|
299
|
-
/// the returned slice is
|
|
330
|
+
/// the returned slice is liveness — the runtime reconciles the
|
|
300
331
|
/// declared set against live windows after every rebuild,
|
|
301
332
|
/// creating the missing and closing the no-longer-declared.
|
|
302
|
-
/// There is deliberately no `visible` flag:
|
|
303
|
-
///
|
|
304
|
-
///
|
|
305
|
-
///
|
|
306
|
-
/// channel, exactly like a dismissible surface's open flag.
|
|
333
|
+
/// There is deliberately no `visible` flag: transient visibility
|
|
334
|
+
/// is host state, changed through `hideWindow`/`showWindow` or a
|
|
335
|
+
/// `.hide` close policy. Stop declaring the window to close it and
|
|
336
|
+
/// release its retained views.
|
|
307
337
|
pub const WindowDescriptor = struct {
|
|
308
338
|
/// Window label: the stable identity across rebuilds, and
|
|
309
339
|
/// the label automation snapshots print for the window.
|
|
@@ -351,8 +381,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
351
381
|
/// False leaves the window resizable but disables the green
|
|
352
382
|
/// fullscreen affordance and fullscreen command.
|
|
353
383
|
allows_fullscreen: bool = true,
|
|
384
|
+
/// What the USER'S close affordance does. `.quit` (the
|
|
385
|
+
/// default) really closes the window; `.hide` retains its
|
|
386
|
+
/// native identity and views for a later `showWindow`. Fixed
|
|
387
|
+
/// at create like the titlebar. Unsupported hosts refuse
|
|
388
|
+
/// `.hide` rather than strand an unreachable hidden window.
|
|
389
|
+
close_policy: app_manifest.WindowClosePolicy = .quit,
|
|
354
390
|
/// Msg dispatched when the USER closes the window (never for
|
|
355
|
-
/// a reconcile close the model itself
|
|
391
|
+
/// a `.hide` policy hide or a reconcile close the model itself
|
|
392
|
+
/// initiated). The
|
|
356
393
|
/// dismissal precedent: the window is already gone as an
|
|
357
394
|
/// optimistic echo; the model clears its open flag in
|
|
358
395
|
/// `update` — or keeps declaring the window and the next
|
|
@@ -731,17 +768,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
731
768
|
/// tray title seam keep the menu updates and log the title
|
|
732
769
|
/// gap once.
|
|
733
770
|
status_item_fn: ?*const fn (model: *const ModelT, scratch: *StatusItemScratch) StatusItemState = null,
|
|
771
|
+
/// Model-declared status-item collection. Stable non-zero
|
|
772
|
+
/// identifiers own native identity; presence creates,
|
|
773
|
+
/// absence removes, and changed shell/presentation/menu
|
|
774
|
+
/// fields patch the existing item independently. Mutually
|
|
775
|
+
/// exclusive with `status_item` and `status_item_fn`.
|
|
776
|
+
status_items_fn: ?*const fn (model: *const ModelT, scratch: *StatusItemsScratch) []const StatusItemDescriptor = null,
|
|
734
777
|
/// Model-declared secondary windows, reconciled after every
|
|
735
778
|
/// rebuild (and on the installing frame): windows the model
|
|
736
779
|
/// declares exist, windows it stops declaring close — the
|
|
737
780
|
/// `status_item_fn` shape applied to the window set, so a
|
|
738
781
|
/// settings window is `if (model.settings_open)` declaring a
|
|
739
782
|
/// descriptor, opened by a Msg and closed by one. Requires
|
|
740
|
-
/// `window_view`. A user close dispatches the
|
|
741
|
-
/// `on_close` Msg (the dismissal precedent: the
|
|
742
|
-
/// already closed it; the model's next declared set is
|
|
743
|
-
/// truth)
|
|
744
|
-
///
|
|
783
|
+
/// `window_view`. A `.quit` user close dispatches the
|
|
784
|
+
/// descriptor's `on_close` Msg (the dismissal precedent: the
|
|
785
|
+
/// engine already closed it; the model's next declared set is
|
|
786
|
+
/// truth); `.hide` retains the declared window and dispatches
|
|
787
|
+
/// no close Msg. Reconcile failures degrade to logged warnings
|
|
788
|
+
/// — a failed create never takes the render loop down.
|
|
745
789
|
windows_fn: ?*const fn (model: *const ModelT, scratch: *WindowsScratch) []const WindowDescriptor = null,
|
|
746
790
|
/// Per-window view for declared secondary windows, keyed by
|
|
747
791
|
/// the descriptor's window label — the `view` seam with the
|
|
@@ -786,6 +830,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
786
830
|
canvas_label_storage: [app_manifest.max_view_label_bytes]u8 = undefined,
|
|
787
831
|
canvas_label_len: usize = 0,
|
|
788
832
|
window_id: platform.WindowId = 0,
|
|
833
|
+
/// Owned copy of `on_close`: windows outlive the callback pass
|
|
834
|
+
/// that declared them, and TypeScript channel messages in
|
|
835
|
+
/// particular may point into a per-cycle decode arena. Keep the
|
|
836
|
+
/// payload alive until the user closes the window (or the model
|
|
837
|
+
/// replaces the declaration).
|
|
838
|
+
on_close_arena: std.heap.ArenaAllocator,
|
|
789
839
|
on_close: ?MsgT = null,
|
|
790
840
|
/// The descriptor's top-level alpha contract also controls
|
|
791
841
|
/// this slot's gpu alpha mode and frame clear. Without both,
|
|
@@ -822,10 +872,27 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
822
872
|
arenas: [2]std.heap.ArenaAllocator,
|
|
823
873
|
|
|
824
874
|
fn init(backing: std.mem.Allocator) WindowSlot {
|
|
825
|
-
return .{
|
|
826
|
-
std.heap.ArenaAllocator.init(backing),
|
|
827
|
-
|
|
828
|
-
|
|
875
|
+
return .{
|
|
876
|
+
.on_close_arena = std.heap.ArenaAllocator.init(backing),
|
|
877
|
+
.arenas = .{
|
|
878
|
+
std.heap.ArenaAllocator.init(backing),
|
|
879
|
+
std.heap.ArenaAllocator.init(backing),
|
|
880
|
+
},
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
fn setOnClose(self: *WindowSlot, msg: ?MsgT) error{ OutOfMemory, HoverCapturePayloadUnsupported }!void {
|
|
885
|
+
_ = self.on_close_arena.reset(.retain_capacity);
|
|
886
|
+
self.on_close = null;
|
|
887
|
+
if (msg) |value| {
|
|
888
|
+
self.on_close = try Self.deepCopyMsgValue(MsgT, value, self.on_close_arena.allocator(), 0);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
fn deinit(self: *WindowSlot) void {
|
|
893
|
+
self.on_close_arena.deinit();
|
|
894
|
+
self.arenas[0].deinit();
|
|
895
|
+
self.arenas[1].deinit();
|
|
829
896
|
}
|
|
830
897
|
|
|
831
898
|
fn label(self: *const WindowSlot) []const u8 {
|
|
@@ -961,19 +1028,15 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
961
1028
|
web_pane_state_count: usize = 0,
|
|
962
1029
|
/// Exactly-once guard for `Options.status_item`/`status_item_fn`.
|
|
963
1030
|
status_item_installed: bool = false,
|
|
964
|
-
///
|
|
965
|
-
///
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
tray_title_unsupported: bool = false,
|
|
970
|
-
/// Hashes of the last APPLIED model-derived tray state, so
|
|
971
|
-
/// rebuilds only touch the platform when the output changed.
|
|
972
|
-
tray_title_hash: u64 = 0,
|
|
973
|
-
tray_menu_hash: u64 = 0,
|
|
1031
|
+
/// Last successfully created status-item identities and their
|
|
1032
|
+
/// applied channel hashes. Each channel patches independently;
|
|
1033
|
+
/// menu changes never replace the native item.
|
|
1034
|
+
applied_status_items: [platform.max_status_items]AppliedStatusItem = [_]AppliedStatusItem{.{}} ** platform.max_status_items,
|
|
1035
|
+
applied_status_item_count: usize = 0,
|
|
974
1036
|
/// Scratch handed to `status_item_fn`; on the app struct so the
|
|
975
1037
|
/// returned slices outlive the apply.
|
|
976
1038
|
tray_scratch: StatusItemScratch = .{},
|
|
1039
|
+
status_items_scratch: StatusItemsScratch = .{},
|
|
977
1040
|
/// Press-and-hold gesture state (`ElementOptions.on_hold`): the
|
|
978
1041
|
/// widget id whose press armed the hold timer, and whether the
|
|
979
1042
|
/// timer fired for the current gesture (a fired hold suppresses
|
|
@@ -1358,8 +1421,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1358
1421
|
}
|
|
1359
1422
|
}
|
|
1360
1423
|
for (&self.window_slots) |*slot| {
|
|
1361
|
-
slot.
|
|
1362
|
-
slot.arenas[1].deinit();
|
|
1424
|
+
slot.deinit();
|
|
1363
1425
|
}
|
|
1364
1426
|
for (&self.hover_msg_leave_arenas) |*arena| arena.deinit();
|
|
1365
1427
|
self.drag_msg_template_arena.deinit();
|
|
@@ -1417,6 +1479,18 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1417
1479
|
.permitted = runtime.options.credentials_enabled and
|
|
1418
1480
|
security.hasPermission(runtime.options.security.permissions, security.permission_credentials),
|
|
1419
1481
|
});
|
|
1482
|
+
if (runtime.options.file_access) |binding| {
|
|
1483
|
+
self.effects.bindFileAccess(binding);
|
|
1484
|
+
} else if (!builtin.is_test and !self.effects.replayArmed()) {
|
|
1485
|
+
// Fail closed for custom/older runners that omit the new path
|
|
1486
|
+
// policy. Replay is exempt: the journal is the whole world and
|
|
1487
|
+
// fake file requests must park without consulting live paths.
|
|
1488
|
+
self.effects.bindFileAccess(.{
|
|
1489
|
+
.roots = &.{},
|
|
1490
|
+
.permitted = security.hasPermission(runtime.options.security.permissions, security.permission_filesystem),
|
|
1491
|
+
.enforce = true,
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1420
1494
|
self.effects.bindImages(runtime.canvasImageRegistryBinding());
|
|
1421
1495
|
self.effects.bindMediaSurfaces(runtime.mediaSurfaceBinding());
|
|
1422
1496
|
self.effects.bindWindowActions(.{
|
|
@@ -1492,7 +1566,16 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1492
1566
|
record.truncated,
|
|
1493
1567
|
record.dropped,
|
|
1494
1568
|
),
|
|
1495
|
-
.file => try self.effects.
|
|
1569
|
+
.file => try self.effects.feedFileResultDetailed(.{
|
|
1570
|
+
.key = record.key,
|
|
1571
|
+
.op = record.file_op,
|
|
1572
|
+
.event = record.file_event,
|
|
1573
|
+
.outcome = record.file_outcome,
|
|
1574
|
+
.bytes = record.payload,
|
|
1575
|
+
.total = record.file_total,
|
|
1576
|
+
.mtime_ms = record.file_mtime_ms,
|
|
1577
|
+
.exists = record.file_exists,
|
|
1578
|
+
}),
|
|
1496
1579
|
.clipboard => try self.effects.feedClipboardResult(record.key, record.clipboard_outcome, record.payload),
|
|
1497
1580
|
// `.host` records ride the route in `code` (0 ok / 1
|
|
1498
1581
|
// err); rejections never reach here — they carry
|
|
@@ -2667,7 +2750,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2667
2750
|
for (declared) |descriptor| {
|
|
2668
2751
|
if (self.windowSlotIndexByLabel(descriptor.label)) |slot_index| {
|
|
2669
2752
|
// Already live: the close Msg follows the model.
|
|
2670
|
-
self.window_slots[slot_index]
|
|
2753
|
+
self.setWindowSlotOnClose(&self.window_slots[slot_index], descriptor.on_close);
|
|
2671
2754
|
continue;
|
|
2672
2755
|
}
|
|
2673
2756
|
self.createWindowSlot(runtime, descriptor);
|
|
@@ -2741,6 +2824,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2741
2824
|
.allows_fullscreen = descriptor.allows_fullscreen,
|
|
2742
2825
|
.min_width = descriptor.min_width,
|
|
2743
2826
|
.min_height = descriptor.min_height,
|
|
2827
|
+
.close_policy = descriptor.close_policy,
|
|
2744
2828
|
// Deterministic reopen: the descriptor is the geometry
|
|
2745
2829
|
// channel, not a persisted frame store.
|
|
2746
2830
|
.restore_state = false,
|
|
@@ -2756,7 +2840,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2756
2840
|
slot.canvas_label_len = descriptor.canvas_label.len;
|
|
2757
2841
|
@memcpy(slot.canvas_label_storage[0..descriptor.canvas_label.len], descriptor.canvas_label);
|
|
2758
2842
|
slot.window_id = info.id;
|
|
2759
|
-
slot
|
|
2843
|
+
self.setWindowSlotOnClose(slot, descriptor.on_close);
|
|
2760
2844
|
slot.transparent = descriptor.transparent;
|
|
2761
2845
|
slot.installed = false;
|
|
2762
2846
|
slot.canvas_size = .{ .width = descriptor.width, .height = descriptor.height };
|
|
@@ -2769,6 +2853,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2769
2853
|
self.window_slot_count += 1;
|
|
2770
2854
|
}
|
|
2771
2855
|
|
|
2856
|
+
fn setWindowSlotOnClose(self: *Self, slot: *WindowSlot, msg: ?MsgT) void {
|
|
2857
|
+
_ = self;
|
|
2858
|
+
slot.setOnClose(msg) catch |err| {
|
|
2859
|
+
slot.on_close = null;
|
|
2860
|
+
_ = slot.on_close_arena.reset(.free_all);
|
|
2861
|
+
switch (err) {
|
|
2862
|
+
error.OutOfMemory => ui_app_log.warn(
|
|
2863
|
+
"declared window '{s}' could not retain its on_close message: out of memory; user close will not dispatch it",
|
|
2864
|
+
.{slot.label()},
|
|
2865
|
+
),
|
|
2866
|
+
error.HoverCapturePayloadUnsupported => ui_app_log.warn(
|
|
2867
|
+
"declared window '{s}' has an on_close payload that cannot be owned; bind scalar, record, union, array, optional, or slice data",
|
|
2868
|
+
.{slot.label()},
|
|
2869
|
+
),
|
|
2870
|
+
}
|
|
2871
|
+
};
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2772
2874
|
/// The gpu_surface shell view for a declared window: the
|
|
2773
2875
|
/// descriptor's canvas label wearing the MAIN canvas's declared
|
|
2774
2876
|
/// gpu options (backend, pixel format, present mode...), so a
|
|
@@ -2815,8 +2917,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2815
2917
|
self.window_slots[index] = self.window_slots[last];
|
|
2816
2918
|
self.window_slots[last] = WindowSlot.init(self.backing);
|
|
2817
2919
|
self.window_slot_count = last;
|
|
2818
|
-
removed.
|
|
2819
|
-
removed.arenas[1].deinit();
|
|
2920
|
+
removed.deinit();
|
|
2820
2921
|
runtime.closeWindow(window_id) catch |err| {
|
|
2821
2922
|
ui_app_log.warn("declared window close failed: {s}", .{@errorName(err)});
|
|
2822
2923
|
};
|
|
@@ -2824,17 +2925,19 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2824
2925
|
|
|
2825
2926
|
/// Drop a slot whose runtime window is ALREADY gone (the user
|
|
2826
2927
|
/// closed it): bookkeeping only, no platform call.
|
|
2827
|
-
fn forgetWindowSlot(self: *Self, index: usize)
|
|
2928
|
+
fn forgetWindowSlot(self: *Self, index: usize) WindowSlot {
|
|
2828
2929
|
self.releaseContextMenuSnapshotForWindow(self.window_slots[index].window_id);
|
|
2829
|
-
const on_close = self.window_slots[index].on_close;
|
|
2830
2930
|
const last = self.window_slot_count - 1;
|
|
2831
2931
|
var removed = self.window_slots[index];
|
|
2832
2932
|
self.window_slots[index] = self.window_slots[last];
|
|
2833
2933
|
self.window_slots[last] = WindowSlot.init(self.backing);
|
|
2834
2934
|
self.window_slot_count = last;
|
|
2935
|
+
// The retained tree is dead with the native window. Keep only
|
|
2936
|
+
// the on-close arena alive through the synchronous dispatch
|
|
2937
|
+
// below, then release it there as well.
|
|
2835
2938
|
removed.arenas[0].deinit();
|
|
2836
2939
|
removed.arenas[1].deinit();
|
|
2837
|
-
return
|
|
2940
|
+
return removed;
|
|
2838
2941
|
}
|
|
2839
2942
|
|
|
2840
2943
|
/// Rebuild every installed secondary window's tree from the
|
|
@@ -3671,86 +3774,177 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
3671
3774
|
/// menu): ~350 ms press-and-hold.
|
|
3672
3775
|
pub const press_hold_duration_ns: u64 = 350 * std.time.ns_per_ms;
|
|
3673
3776
|
|
|
3674
|
-
/// Install the
|
|
3675
|
-
///
|
|
3676
|
-
///
|
|
3677
|
-
/// Unsupported platforms degrade to a logged warning. With a
|
|
3678
|
-
/// `status_item_fn`, the model's derived presentation/items win from
|
|
3679
|
-
/// the very first frame (the static options keep icon+tooltip).
|
|
3777
|
+
/// Install the declarative status-item surface on the installing
|
|
3778
|
+
/// frame. Collection entries reconcile by stable id; the legacy
|
|
3779
|
+
/// singular channel occupies the reserved primary id.
|
|
3680
3780
|
fn installStatusItem(self: *Self, runtime: *Runtime) void {
|
|
3681
3781
|
if (self.status_item_installed) return;
|
|
3682
|
-
if (self.options.status_item == null and self.options.status_item_fn == null) return;
|
|
3782
|
+
if (self.options.status_item == null and self.options.status_item_fn == null and self.options.status_items_fn == null) return;
|
|
3783
|
+
if (self.options.status_items_fn != null and (self.options.status_item != null or self.options.status_item_fn != null)) {
|
|
3784
|
+
@panic("UiApp status_items_fn is mutually exclusive with status_item/status_item_fn");
|
|
3785
|
+
}
|
|
3683
3786
|
self.status_item_installed = true;
|
|
3787
|
+
self.reconcileStatusItems(runtime, self.desiredStatusItems());
|
|
3788
|
+
}
|
|
3789
|
+
|
|
3790
|
+
/// Re-derive the status-item collection after every committed
|
|
3791
|
+
/// rebuild and patch shell, presentation, and menu independently.
|
|
3792
|
+
fn applyStatusItem(self: *Self, runtime: *Runtime) void {
|
|
3793
|
+
if (!self.status_item_installed) return;
|
|
3794
|
+
if (self.options.status_item_fn == null and self.options.status_items_fn == null) return;
|
|
3795
|
+
self.reconcileStatusItems(runtime, self.desiredStatusItems());
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
fn desiredStatusItems(self: *Self) []const StatusItemDescriptor {
|
|
3799
|
+
if (self.options.status_items_fn) |items_fn| {
|
|
3800
|
+
return items_fn(&self.model, &self.status_items_scratch);
|
|
3801
|
+
}
|
|
3684
3802
|
const static = self.options.status_item orelse StatusItemOptions{};
|
|
3685
|
-
var
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3803
|
+
var state: StatusItemState = .{
|
|
3804
|
+
.title = static.title,
|
|
3805
|
+
.presentation = .{ .title = static.title },
|
|
3806
|
+
.icon_path = static.icon_path,
|
|
3807
|
+
.tooltip = static.tooltip,
|
|
3808
|
+
.activation_command = static.activation_command,
|
|
3809
|
+
.alternate_activation_command = static.alternate_activation_command,
|
|
3810
|
+
.open_command = static.open_command,
|
|
3811
|
+
.items = static.items,
|
|
3812
|
+
};
|
|
3692
3813
|
if (self.options.status_item_fn) |state_fn| {
|
|
3693
|
-
|
|
3694
|
-
presentation = state.
|
|
3695
|
-
if (
|
|
3696
|
-
if (state.
|
|
3697
|
-
if (state.
|
|
3698
|
-
if (state.
|
|
3699
|
-
if (state.
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
.title = presentation.title,
|
|
3705
|
-
.icon_path = icon_path,
|
|
3706
|
-
.tooltip = tooltip,
|
|
3707
|
-
.items = items,
|
|
3708
|
-
.presentation = presentation,
|
|
3709
|
-
.activation_command = activation_command,
|
|
3710
|
-
.alternate_activation_command = alternate_activation_command,
|
|
3711
|
-
.open_command = open_command,
|
|
3712
|
-
}) catch |err| {
|
|
3713
|
-
ui_app_log.warn("status item install failed: {s}", .{@errorName(err)});
|
|
3714
|
-
return;
|
|
3814
|
+
state = state_fn(&self.model, &self.tray_scratch);
|
|
3815
|
+
if (state.presentation.title.len == 0) state.presentation.title = state.title;
|
|
3816
|
+
if (state.icon_path.len == 0) state.icon_path = static.icon_path;
|
|
3817
|
+
if (state.tooltip.len == 0) state.tooltip = static.tooltip;
|
|
3818
|
+
if (state.activation_command.len == 0) state.activation_command = static.activation_command;
|
|
3819
|
+
if (state.alternate_activation_command.len == 0) state.alternate_activation_command = static.alternate_activation_command;
|
|
3820
|
+
if (state.open_command.len == 0) state.open_command = static.open_command;
|
|
3821
|
+
}
|
|
3822
|
+
self.status_items_scratch.status_items[0] = .{
|
|
3823
|
+
.id = platform.primary_status_item_id,
|
|
3824
|
+
.state = state,
|
|
3715
3825
|
};
|
|
3716
|
-
self.
|
|
3717
|
-
self.tray_title_hash = hashTrayPresentation(presentation);
|
|
3718
|
-
self.tray_menu_hash = hashTrayMenu(items);
|
|
3826
|
+
return self.status_items_scratch.status_items[0..1];
|
|
3719
3827
|
}
|
|
3720
3828
|
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
self.
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3829
|
+
fn reconcileStatusItems(self: *Self, runtime: *Runtime, declared: []const StatusItemDescriptor) void {
|
|
3830
|
+
if (declared.len > platform.max_status_items) {
|
|
3831
|
+
ui_app_log.warn("status item collection has {d} entries; at most {d} are supported", .{ declared.len, platform.max_status_items });
|
|
3832
|
+
}
|
|
3833
|
+
const desired = declared[0..@min(declared.len, platform.max_status_items)];
|
|
3834
|
+
|
|
3835
|
+
for (&self.applied_status_items) |*applied| {
|
|
3836
|
+
if (!applied.active or statusItemDeclared(desired, applied.id)) continue;
|
|
3837
|
+
runtime.removeStatusItem(applied.id) catch |err| {
|
|
3838
|
+
ui_app_log.warn("status item #{d} remove failed: {s}", .{ applied.id, @errorName(err) });
|
|
3839
|
+
continue;
|
|
3840
|
+
};
|
|
3841
|
+
applied.* = .{};
|
|
3842
|
+
self.applied_status_item_count -= 1;
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
for (desired, 0..) |raw_descriptor, index| {
|
|
3846
|
+
if (raw_descriptor.id == 0 or statusItemIdAppearedEarlier(desired, index, raw_descriptor.id)) {
|
|
3847
|
+
ui_app_log.warn("status item declaration ignored: identifiers must be unique and non-zero (got {d})", .{raw_descriptor.id});
|
|
3848
|
+
continue;
|
|
3849
|
+
}
|
|
3850
|
+
var descriptor = raw_descriptor;
|
|
3851
|
+
if (descriptor.state.presentation.title.len == 0) descriptor.state.presentation.title = descriptor.state.title;
|
|
3852
|
+
const shell = platform.TrayShell{
|
|
3853
|
+
.icon_path = descriptor.state.icon_path,
|
|
3854
|
+
.tooltip = descriptor.state.tooltip,
|
|
3855
|
+
.visible = descriptor.visible,
|
|
3856
|
+
.activation_command = descriptor.state.activation_command,
|
|
3857
|
+
.alternate_activation_command = descriptor.state.alternate_activation_command,
|
|
3858
|
+
.open_command = descriptor.state.open_command,
|
|
3859
|
+
};
|
|
3860
|
+
const shell_hash = hashTrayShell(shell);
|
|
3861
|
+
const presentation_hash = hashTrayPresentation(descriptor.state.presentation);
|
|
3862
|
+
const menu_hash = hashTrayMenu(descriptor.state.items);
|
|
3863
|
+
|
|
3864
|
+
const applied = self.findAppliedStatusItem(descriptor.id) orelse self.emptyAppliedStatusItem() orelse {
|
|
3865
|
+
ui_app_log.warn("status item #{d} ignored: status-item capacity is full", .{descriptor.id});
|
|
3866
|
+
continue;
|
|
3867
|
+
};
|
|
3868
|
+
if (!applied.active) {
|
|
3869
|
+
runtime.createStatusItem(descriptor.id, .{
|
|
3870
|
+
.title = descriptor.state.presentation.title,
|
|
3871
|
+
.icon_path = shell.icon_path,
|
|
3872
|
+
.tooltip = shell.tooltip,
|
|
3873
|
+
.visible = shell.visible,
|
|
3874
|
+
.items = descriptor.state.items,
|
|
3875
|
+
.presentation = descriptor.state.presentation,
|
|
3876
|
+
.activation_command = shell.activation_command,
|
|
3877
|
+
.alternate_activation_command = shell.alternate_activation_command,
|
|
3878
|
+
.open_command = shell.open_command,
|
|
3879
|
+
}) catch |err| {
|
|
3880
|
+
ui_app_log.warn("status item #{d} install failed: {s}", .{ descriptor.id, @errorName(err) });
|
|
3881
|
+
continue;
|
|
3882
|
+
};
|
|
3883
|
+
applied.* = .{
|
|
3884
|
+
.id = descriptor.id,
|
|
3885
|
+
.active = true,
|
|
3886
|
+
.shell_hash = shell_hash,
|
|
3887
|
+
.presentation_hash = presentation_hash,
|
|
3888
|
+
.menu_hash = menu_hash,
|
|
3889
|
+
};
|
|
3890
|
+
self.applied_status_item_count += 1;
|
|
3891
|
+
continue;
|
|
3892
|
+
}
|
|
3893
|
+
|
|
3894
|
+
if (shell_hash != applied.shell_hash) {
|
|
3895
|
+
applied.shell_hash = shell_hash;
|
|
3896
|
+
if (!applied.shell_unsupported) {
|
|
3897
|
+
runtime.updateStatusItemShell(descriptor.id, shell) catch |err| {
|
|
3898
|
+
if (err == error.UnsupportedService) applied.shell_unsupported = true;
|
|
3899
|
+
ui_app_log.warn("status item #{d} shell update failed: {s}", .{ descriptor.id, @errorName(err) });
|
|
3900
|
+
};
|
|
3901
|
+
}
|
|
3902
|
+
}
|
|
3903
|
+
if (presentation_hash != applied.presentation_hash) {
|
|
3904
|
+
applied.presentation_hash = presentation_hash;
|
|
3905
|
+
if (!applied.presentation_unsupported) {
|
|
3906
|
+
runtime.updateStatusItemPresentation(descriptor.id, descriptor.state.presentation) catch |err| {
|
|
3907
|
+
if (err == error.UnsupportedService) applied.presentation_unsupported = true;
|
|
3908
|
+
ui_app_log.warn("status item #{d} presentation update failed: {s}", .{ descriptor.id, @errorName(err) });
|
|
3909
|
+
};
|
|
3910
|
+
}
|
|
3911
|
+
}
|
|
3912
|
+
if (menu_hash != applied.menu_hash) {
|
|
3913
|
+
applied.menu_hash = menu_hash;
|
|
3914
|
+
runtime.updateStatusItemMenu(descriptor.id, descriptor.state.items) catch |err| {
|
|
3915
|
+
ui_app_log.warn("status item #{d} menu update failed: {s}", .{ descriptor.id, @errorName(err) });
|
|
3743
3916
|
};
|
|
3744
3917
|
}
|
|
3745
3918
|
}
|
|
3919
|
+
}
|
|
3746
3920
|
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3921
|
+
fn findAppliedStatusItem(self: *Self, id: platform.StatusItemId) ?*AppliedStatusItem {
|
|
3922
|
+
for (&self.applied_status_items) |*applied| {
|
|
3923
|
+
if (applied.active and applied.id == id) return applied;
|
|
3924
|
+
}
|
|
3925
|
+
return null;
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
fn emptyAppliedStatusItem(self: *Self) ?*AppliedStatusItem {
|
|
3929
|
+
if (self.applied_status_item_count >= self.applied_status_items.len) return null;
|
|
3930
|
+
for (&self.applied_status_items) |*applied| {
|
|
3931
|
+
if (!applied.active) return applied;
|
|
3932
|
+
}
|
|
3933
|
+
return null;
|
|
3934
|
+
}
|
|
3935
|
+
|
|
3936
|
+
fn statusItemDeclared(declared: []const StatusItemDescriptor, id: platform.StatusItemId) bool {
|
|
3937
|
+
for (declared) |descriptor| {
|
|
3938
|
+
if (descriptor.id == id) return true;
|
|
3753
3939
|
}
|
|
3940
|
+
return false;
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
fn statusItemIdAppearedEarlier(declared: []const StatusItemDescriptor, index: usize, id: platform.StatusItemId) bool {
|
|
3944
|
+
for (declared[0..index]) |descriptor| {
|
|
3945
|
+
if (descriptor.id == id) return true;
|
|
3946
|
+
}
|
|
3947
|
+
return false;
|
|
3754
3948
|
}
|
|
3755
3949
|
|
|
3756
3950
|
/// The video channel snapshot in the builder's chrome shape
|
|
@@ -4150,8 +4344,9 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4150
4344
|
// in its place), a non-owner just drops out of the table.
|
|
4151
4345
|
self.captureSlotVideoDeclaration(closed.window_id, null);
|
|
4152
4346
|
self.applyVideoDeclaration(runtime);
|
|
4153
|
-
|
|
4154
|
-
|
|
4347
|
+
var removed = self.forgetWindowSlot(index);
|
|
4348
|
+
defer removed.on_close_arena.deinit();
|
|
4349
|
+
if (removed.on_close) |msg| {
|
|
4155
4350
|
try self.dispatch(runtime, self.canvas_window_id, msg);
|
|
4156
4351
|
}
|
|
4157
4352
|
}
|
|
@@ -4546,6 +4741,23 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4546
4741
|
/// Change-detection hashes for the model-derived tray state:
|
|
4547
4742
|
/// field lengths are folded in so adjacent slices can
|
|
4548
4743
|
/// never alias across boundaries.
|
|
4744
|
+
fn hashTrayShell(shell: platform.TrayShell) u64 {
|
|
4745
|
+
var hasher = std.hash.Wyhash.init(0x7261795f7368656c); // "ray_shel"
|
|
4746
|
+
const fields = [_][]const u8{
|
|
4747
|
+
shell.icon_path,
|
|
4748
|
+
shell.tooltip,
|
|
4749
|
+
shell.activation_command,
|
|
4750
|
+
shell.alternate_activation_command,
|
|
4751
|
+
shell.open_command,
|
|
4752
|
+
};
|
|
4753
|
+
for (fields) |field| {
|
|
4754
|
+
hasher.update(std.mem.asBytes(&field.len));
|
|
4755
|
+
hasher.update(field);
|
|
4756
|
+
}
|
|
4757
|
+
hasher.update(&.{@intFromBool(shell.visible)});
|
|
4758
|
+
return hasher.final();
|
|
4759
|
+
}
|
|
4760
|
+
|
|
4549
4761
|
fn hashTrayPresentation(presentation: platform.TrayPresentation) u64 {
|
|
4550
4762
|
var hasher = std.hash.Wyhash.init(0x7261795f70726573); // "ray_pres"
|
|
4551
4763
|
hasher.update(presentation.title);
|