@native-sdk/cli 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/build/app.zig +68 -57
- package/build.zig +12 -1
- package/package.json +10 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +435 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +41 -2
- package/src/platform/macos/appkit_host.m +198 -9
- package/src/platform/macos/cef_host.mm +191 -9
- package/src/platform/macos/root.zig +110 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +58 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/canvas/reference.zig +37 -15
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +7 -2
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +4 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/flow.zig +1 -1
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +120 -33
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +165 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
|
@@ -229,6 +229,25 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
|
|
|
229
229
|
const status_item = findStatusItemConst(self, status_item_id) orelse return false;
|
|
230
230
|
for (status_item.items[0..status_item.item_count]) |item| {
|
|
231
231
|
if (item.id == item_id) return true;
|
|
232
|
+
if (item.segmented) |segmented| {
|
|
233
|
+
for (segmented.options) |option| if (option.id == item_id) return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// Whether automation may invoke this row exactly as a user can.
|
|
240
|
+
/// Disabled native menu items and segmented choices cannot emit a
|
|
241
|
+
/// platform action, so the automation seam must reject them too.
|
|
242
|
+
pub fn statusItemMenuItemActionable(self: *const Runtime, status_item_id: platform.StatusItemId, item_id: platform.TrayItemId) bool {
|
|
243
|
+
const status_item = findStatusItemConst(self, status_item_id) orelse return false;
|
|
244
|
+
for (status_item.items[0..status_item.item_count]) |item| {
|
|
245
|
+
if (item.id == item_id) return !item.separator and item.enabled and (item.role == .command or item.role == .agent);
|
|
246
|
+
if (item.segmented) |segmented| {
|
|
247
|
+
for (segmented.options) |option| {
|
|
248
|
+
if (option.id == item_id) return option.enabled;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
232
251
|
}
|
|
233
252
|
return false;
|
|
234
253
|
}
|
|
@@ -241,6 +260,11 @@ pub fn RuntimeSystemServices(comptime Runtime: type) type {
|
|
|
241
260
|
const status_item = findStatusItemConst(self, status_item_id) orelse return "tray.action";
|
|
242
261
|
for (status_item.items[0..status_item.item_count]) |item| {
|
|
243
262
|
if (item.id == item_id and item.command.len > 0) return item.command;
|
|
263
|
+
if (item.segmented) |segmented| {
|
|
264
|
+
for (segmented.options) |option| {
|
|
265
|
+
if (option.id == item_id) return option.command;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
244
268
|
}
|
|
245
269
|
return "tray.action";
|
|
246
270
|
}
|
|
@@ -480,6 +504,44 @@ fn storeTrayItems(status_item: anytype, items: []const platform.TrayMenuItem) !v
|
|
|
480
504
|
status_item.items[index].role = item.role;
|
|
481
505
|
status_item.items[index].key = try copyInto(&status_item.items[index].key_storage, item.key);
|
|
482
506
|
status_item.items[index].modifiers = item.modifiers;
|
|
507
|
+
status_item.items[index].segmented = null;
|
|
508
|
+
status_item.items[index].segment_option_count = 0;
|
|
509
|
+
if (item.segmented) |segmented| {
|
|
510
|
+
for (segmented.options, 0..) |option, option_index| {
|
|
511
|
+
const stored = &status_item.items[index].segment_options[option_index];
|
|
512
|
+
stored.id = option.id;
|
|
513
|
+
stored.label = try copyInto(&status_item.items[index].segment_option_label_storage[option_index], option.label);
|
|
514
|
+
stored.command = try copyInto(&status_item.items[index].segment_option_command_storage[option_index], option.command);
|
|
515
|
+
stored.selected = option.selected;
|
|
516
|
+
stored.enabled = option.enabled;
|
|
517
|
+
}
|
|
518
|
+
status_item.items[index].segment_option_count = segmented.options.len;
|
|
519
|
+
const stored = &status_item.items[index];
|
|
520
|
+
stored.segmented = .{ .options = stored.segment_options[0..stored.segment_option_count] };
|
|
521
|
+
}
|
|
522
|
+
status_item.items[index].metric = null;
|
|
523
|
+
if (item.metric) |metric| {
|
|
524
|
+
status_item.items[index].metric = .{
|
|
525
|
+
.primary_text = try copyInto(&status_item.items[index].metric_primary_storage, metric.primary_text),
|
|
526
|
+
.secondary_text = try copyInto(&status_item.items[index].metric_secondary_storage, metric.secondary_text),
|
|
527
|
+
.accessibility_label = try copyInto(&status_item.items[index].metric_accessibility_storage, metric.accessibility_label),
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
status_item.items[index].chart = null;
|
|
531
|
+
if (item.chart) |chart| {
|
|
532
|
+
@memcpy(status_item.items[index].chart_values[0..chart.values.len], chart.values);
|
|
533
|
+
const leading_caption = try copyInto(&status_item.items[index].chart_leading_caption_storage, chart.leading_caption);
|
|
534
|
+
const trailing_summary = try copyInto(&status_item.items[index].chart_trailing_summary_storage, chart.trailing_summary);
|
|
535
|
+
const accessibility_label = try copyInto(&status_item.items[index].chart_accessibility_label_storage, chart.accessibility_label);
|
|
536
|
+
status_item.items[index].chart = .{
|
|
537
|
+
.values = status_item.items[index].chart_values[0..chart.values.len],
|
|
538
|
+
.min_value = chart.min_value,
|
|
539
|
+
.max_value = chart.max_value,
|
|
540
|
+
.leading_caption = leading_caption,
|
|
541
|
+
.trailing_summary = trailing_summary,
|
|
542
|
+
.accessibility_label = accessibility_label,
|
|
543
|
+
};
|
|
544
|
+
}
|
|
483
545
|
}
|
|
484
546
|
status_item.item_count = items.len;
|
|
485
547
|
}
|
|
@@ -638,23 +638,13 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
638
638
|
}
|
|
639
639
|
for (state.items, 0..) |raw_item, index| {
|
|
640
640
|
const item = if (comptime @typeInfo(@TypeOf(raw_item)) == .pointer) raw_item.* else raw_item;
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
.
|
|
646
|
-
.
|
|
647
|
-
|
|
648
|
-
.role = statusItemRole(item.role),
|
|
649
|
-
.key = item.key,
|
|
650
|
-
.modifiers = .{
|
|
651
|
-
.primary = item.modifiers.primary,
|
|
652
|
-
.command = item.modifiers.command,
|
|
653
|
-
.control = item.modifiers.control,
|
|
654
|
-
.option = item.modifiers.option,
|
|
655
|
-
.shift = item.modifiers.shift,
|
|
656
|
-
},
|
|
657
|
-
};
|
|
641
|
+
const segment_start = index * platform.max_tray_segment_options;
|
|
642
|
+
const chart_start = index * platform.max_tray_chart_values;
|
|
643
|
+
scratch.items[index] = statusItemMenuItem(
|
|
644
|
+
item,
|
|
645
|
+
scratch.segment_options[segment_start .. segment_start + platform.max_tray_segment_options],
|
|
646
|
+
scratch.chart_values[chart_start .. chart_start + platform.max_tray_chart_values],
|
|
647
|
+
);
|
|
658
648
|
}
|
|
659
649
|
return statusItemState(state, scratch.items[0..state.items.len]);
|
|
660
650
|
}
|
|
@@ -684,7 +674,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
684
674
|
}
|
|
685
675
|
for (state.items, 0..) |raw_item, item_index| {
|
|
686
676
|
const item = if (comptime @typeInfo(@TypeOf(raw_item)) == .pointer) raw_item.* else raw_item;
|
|
687
|
-
|
|
677
|
+
const flat_row_index = row_start + item_index;
|
|
678
|
+
const segment_start = flat_row_index * platform.max_tray_segment_options;
|
|
679
|
+
const chart_start = flat_row_index * platform.max_tray_chart_values;
|
|
680
|
+
row_storage[item_index] = statusItemMenuItem(
|
|
681
|
+
item,
|
|
682
|
+
scratch.segment_options[segment_start .. segment_start + platform.max_tray_segment_options],
|
|
683
|
+
scratch.chart_values[chart_start .. chart_start + platform.max_tray_chart_values],
|
|
684
|
+
);
|
|
688
685
|
}
|
|
689
686
|
scratch.status_items[status_index] = .{
|
|
690
687
|
.id = statusItemId(state.id),
|
|
@@ -790,8 +787,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
790
787
|
};
|
|
791
788
|
}
|
|
792
789
|
|
|
793
|
-
fn statusItemMenuItem(item: anytype) platform.TrayMenuItem {
|
|
794
|
-
|
|
790
|
+
fn statusItemMenuItem(item: anytype, segment_storage: []platform.TraySegmentOption, chart_storage: []f32) platform.TrayMenuItem {
|
|
791
|
+
var result = platform.TrayMenuItem{
|
|
795
792
|
.id = statusItemId(item.id),
|
|
796
793
|
.label = item.label,
|
|
797
794
|
.command = item.command,
|
|
@@ -808,6 +805,49 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
808
805
|
.shift = item.modifiers.shift,
|
|
809
806
|
},
|
|
810
807
|
};
|
|
808
|
+
if (@hasField(@TypeOf(item), "segmented")) if (item.segmented) |raw_segmented| {
|
|
809
|
+
const segmented = if (comptime @typeInfo(@TypeOf(raw_segmented)) == .pointer) raw_segmented.* else raw_segmented;
|
|
810
|
+
if (segmented.options.len <= segment_storage.len) {
|
|
811
|
+
for (segmented.options, 0..) |raw_option, index| {
|
|
812
|
+
const option = if (comptime @typeInfo(@TypeOf(raw_option)) == .pointer) raw_option.* else raw_option;
|
|
813
|
+
segment_storage[index] = .{
|
|
814
|
+
.id = statusItemId(option.id),
|
|
815
|
+
.label = option.label,
|
|
816
|
+
.command = option.command,
|
|
817
|
+
.selected = option.selected,
|
|
818
|
+
.enabled = option.enabled,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
result.segmented = .{ .options = segment_storage[0..segmented.options.len] };
|
|
822
|
+
} else {
|
|
823
|
+
result.segmented = .{};
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
if (@hasField(@TypeOf(item), "metric")) if (item.metric) |raw_metric| {
|
|
827
|
+
const metric = if (comptime @typeInfo(@TypeOf(raw_metric)) == .pointer) raw_metric.* else raw_metric;
|
|
828
|
+
result.metric = .{
|
|
829
|
+
.primary_text = metric.primaryText,
|
|
830
|
+
.secondary_text = metric.secondaryText,
|
|
831
|
+
.accessibility_label = metric.accessibilityLabel,
|
|
832
|
+
};
|
|
833
|
+
};
|
|
834
|
+
if (@hasField(@TypeOf(item), "chart")) if (item.chart) |raw_chart| {
|
|
835
|
+
const chart = if (comptime @typeInfo(@TypeOf(raw_chart)) == .pointer) raw_chart.* else raw_chart;
|
|
836
|
+
if (chart.values.len <= chart_storage.len) {
|
|
837
|
+
for (chart.values, 0..) |value, index| chart_storage[index] = statusItemFloat(value);
|
|
838
|
+
result.chart = .{
|
|
839
|
+
.values = chart_storage[0..chart.values.len],
|
|
840
|
+
.min_value = statusItemFloat(chart.minValue),
|
|
841
|
+
.max_value = statusItemFloat(chart.maxValue),
|
|
842
|
+
.leading_caption = chart.leadingCaption,
|
|
843
|
+
.trailing_summary = chart.trailingSummary,
|
|
844
|
+
.accessibility_label = chart.accessibilityLabel,
|
|
845
|
+
};
|
|
846
|
+
} else {
|
|
847
|
+
result.chart = .{};
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
return result;
|
|
811
851
|
}
|
|
812
852
|
|
|
813
853
|
fn statusItemState(state: anytype, items: []const platform.TrayMenuItem) App.StatusItemState {
|
|
@@ -819,6 +859,8 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
819
859
|
.tone = statusItemTone(presentation.tone),
|
|
820
860
|
.icon_opacity = statusItemFloat(presentation.iconOpacity),
|
|
821
861
|
.monospaced = presentation.monospaced,
|
|
862
|
+
.font_size = if (presentation.fontSize) |value| statusItemFloat(value) else 0,
|
|
863
|
+
.font_weight = if (presentation.fontWeight) |value| statusItemFontWeight(value) else .regular,
|
|
822
864
|
},
|
|
823
865
|
.icon_path = state.iconPath,
|
|
824
866
|
.tooltip = state.tooltip,
|
|
@@ -859,6 +901,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
859
901
|
unreachable;
|
|
860
902
|
}
|
|
861
903
|
|
|
904
|
+
fn statusItemFontWeight(value: anytype) platform.TrayFontWeight {
|
|
905
|
+
const name = @tagName(value);
|
|
906
|
+
inline for (std.meta.fields(platform.TrayFontWeight)) |field| {
|
|
907
|
+
if (std.mem.eql(u8, name, field.name)) return @enumFromInt(field.value);
|
|
908
|
+
}
|
|
909
|
+
unreachable;
|
|
910
|
+
}
|
|
911
|
+
|
|
862
912
|
fn statusItemRole(value: anytype) platform.TrayItemRole {
|
|
863
913
|
const name = @tagName(value);
|
|
864
914
|
inline for (std.meta.fields(platform.TrayItemRole)) |field| {
|
|
@@ -902,14 +952,17 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
902
952
|
}
|
|
903
953
|
const Presentation = statusItemRecordType(@FieldType(State, "presentation"), teaching);
|
|
904
954
|
const presentation_info = @typeInfo(Presentation).@"struct";
|
|
905
|
-
if (presentation_info.fields.len !=
|
|
906
|
-
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced")
|
|
955
|
+
if (presentation_info.fields.len != 7 or !@hasField(Presentation, "title") or !@hasField(Presentation, "width") or
|
|
956
|
+
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced") or
|
|
957
|
+
!@hasField(Presentation, "fontSize") or !@hasField(Presentation, "fontWeight"))
|
|
907
958
|
{
|
|
908
959
|
@compileError(teaching);
|
|
909
960
|
}
|
|
910
961
|
if (@FieldType(Presentation, "title") != []const u8 or !statusItemNumericType(@FieldType(Presentation, "width")) or
|
|
911
962
|
!statusItemEnumType(@FieldType(Presentation, "tone"), &.{ "normal", "warning", "critical" }) or
|
|
912
|
-
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool
|
|
963
|
+
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool or
|
|
964
|
+
!optionalNumericType(@FieldType(Presentation, "fontSize")) or
|
|
965
|
+
!optionalEnumType(@FieldType(Presentation, "fontWeight"), &.{ "regular", "medium", "semibold", "bold" }))
|
|
913
966
|
{
|
|
914
967
|
@compileError(teaching);
|
|
915
968
|
}
|
|
@@ -917,9 +970,10 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
917
970
|
if (items_info != .pointer or items_info.pointer.size != .slice or !items_info.pointer.is_const) @compileError(teaching);
|
|
918
971
|
const Item = statusItemRecordType(items_info.pointer.child, teaching);
|
|
919
972
|
const item_info = @typeInfo(Item).@"struct";
|
|
920
|
-
if (item_info.fields.len !=
|
|
973
|
+
if (item_info.fields.len != 12 or !@hasField(Item, "id") or !@hasField(Item, "label") or
|
|
921
974
|
!@hasField(Item, "command") or !@hasField(Item, "separator") or !@hasField(Item, "enabled") or
|
|
922
|
-
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or !@hasField(Item, "modifiers")
|
|
975
|
+
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or !@hasField(Item, "modifiers") or
|
|
976
|
+
!@hasField(Item, "segmented") or !@hasField(Item, "metric") or !@hasField(Item, "chart"))
|
|
923
977
|
{
|
|
924
978
|
@compileError(teaching);
|
|
925
979
|
}
|
|
@@ -927,7 +981,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
927
981
|
if (@FieldType(Item, "label") != []const u8 or @FieldType(Item, "command") != []const u8 or
|
|
928
982
|
@FieldType(Item, "separator") != bool or @FieldType(Item, "enabled") != bool or
|
|
929
983
|
@FieldType(Item, "detail") != []const u8 or
|
|
930
|
-
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context" }) or
|
|
984
|
+
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context", "segmented", "chart" }) or
|
|
931
985
|
@FieldType(Item, "key") != []const u8)
|
|
932
986
|
{
|
|
933
987
|
@compileError(teaching);
|
|
@@ -941,6 +995,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
941
995
|
{
|
|
942
996
|
@compileError(teaching);
|
|
943
997
|
}
|
|
998
|
+
validateStatusItemRichTypes(Item, teaching);
|
|
944
999
|
}
|
|
945
1000
|
|
|
946
1001
|
fn validateStatusItemsHelper() void {
|
|
@@ -976,11 +1031,14 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
976
1031
|
}
|
|
977
1032
|
const Presentation = statusItemRecordType(@FieldType(State, "presentation"), teaching);
|
|
978
1033
|
const presentation_info = @typeInfo(Presentation).@"struct";
|
|
979
|
-
if (presentation_info.fields.len !=
|
|
1034
|
+
if (presentation_info.fields.len != 7 or !@hasField(Presentation, "title") or !@hasField(Presentation, "width") or
|
|
980
1035
|
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced") or
|
|
1036
|
+
!@hasField(Presentation, "fontSize") or !@hasField(Presentation, "fontWeight") or
|
|
981
1037
|
@FieldType(Presentation, "title") != []const u8 or !statusItemNumericType(@FieldType(Presentation, "width")) or
|
|
982
1038
|
!statusItemEnumType(@FieldType(Presentation, "tone"), &.{ "normal", "warning", "critical" }) or
|
|
983
|
-
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool
|
|
1039
|
+
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool or
|
|
1040
|
+
!optionalNumericType(@FieldType(Presentation, "fontSize")) or
|
|
1041
|
+
!optionalEnumType(@FieldType(Presentation, "fontWeight"), &.{ "regular", "medium", "semibold", "bold" }))
|
|
984
1042
|
{
|
|
985
1043
|
@compileError(teaching);
|
|
986
1044
|
}
|
|
@@ -988,18 +1046,20 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
988
1046
|
if (items_info != .pointer or items_info.pointer.size != .slice or !items_info.pointer.is_const) @compileError(teaching);
|
|
989
1047
|
const Item = statusItemRecordType(items_info.pointer.child, teaching);
|
|
990
1048
|
const item_info = @typeInfo(Item).@"struct";
|
|
991
|
-
if (item_info.fields.len !=
|
|
1049
|
+
if (item_info.fields.len != 12 or !@hasField(Item, "id") or !@hasField(Item, "label") or
|
|
992
1050
|
!@hasField(Item, "command") or !@hasField(Item, "separator") or !@hasField(Item, "enabled") or
|
|
993
1051
|
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or
|
|
994
|
-
!@hasField(Item, "modifiers") or
|
|
1052
|
+
!@hasField(Item, "modifiers") or !@hasField(Item, "segmented") or !@hasField(Item, "metric") or !@hasField(Item, "chart") or
|
|
1053
|
+
!statusItemNumericType(@FieldType(Item, "id")) or
|
|
995
1054
|
@FieldType(Item, "label") != []const u8 or @FieldType(Item, "command") != []const u8 or
|
|
996
1055
|
@FieldType(Item, "separator") != bool or @FieldType(Item, "enabled") != bool or
|
|
997
1056
|
@FieldType(Item, "detail") != []const u8 or
|
|
998
|
-
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context" }) or
|
|
1057
|
+
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context", "segmented", "chart" }) or
|
|
999
1058
|
@FieldType(Item, "key") != []const u8)
|
|
1000
1059
|
{
|
|
1001
1060
|
@compileError(teaching);
|
|
1002
1061
|
}
|
|
1062
|
+
validateStatusItemRichTypes(Item, teaching);
|
|
1003
1063
|
const Modifiers = statusItemRecordType(@FieldType(Item, "modifiers"), teaching);
|
|
1004
1064
|
const modifiers_info = @typeInfo(Modifiers).@"struct";
|
|
1005
1065
|
if (modifiers_info.fields.len != 5 or !@hasField(Modifiers, "primary") or !@hasField(Modifiers, "command") or
|
|
@@ -1059,6 +1119,43 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1059
1119
|
return info == .optional and statusItemEnumType(info.optional.child, expected);
|
|
1060
1120
|
}
|
|
1061
1121
|
|
|
1122
|
+
fn validateStatusItemRichTypes(comptime Item: type, comptime teaching: []const u8) void {
|
|
1123
|
+
const segmented_info = @typeInfo(@FieldType(Item, "segmented"));
|
|
1124
|
+
const metric_info = @typeInfo(@FieldType(Item, "metric"));
|
|
1125
|
+
const chart_info = @typeInfo(@FieldType(Item, "chart"));
|
|
1126
|
+
if (segmented_info != .optional or metric_info != .optional or chart_info != .optional) @compileError(teaching);
|
|
1127
|
+
|
|
1128
|
+
const Segmented = statusItemRecordType(segmented_info.optional.child, teaching);
|
|
1129
|
+
const segmented_fields = @typeInfo(Segmented).@"struct".fields;
|
|
1130
|
+
if (segmented_fields.len != 1 or !@hasField(Segmented, "options")) @compileError(teaching);
|
|
1131
|
+
const options_info = @typeInfo(@FieldType(Segmented, "options"));
|
|
1132
|
+
if (options_info != .pointer or options_info.pointer.size != .slice or !options_info.pointer.is_const) @compileError(teaching);
|
|
1133
|
+
const Option = statusItemRecordType(options_info.pointer.child, teaching);
|
|
1134
|
+
const option_info = @typeInfo(Option).@"struct";
|
|
1135
|
+
if (option_info.fields.len != 5 or !@hasField(Option, "id") or !@hasField(Option, "label") or
|
|
1136
|
+
!@hasField(Option, "command") or !@hasField(Option, "selected") or !@hasField(Option, "enabled") or
|
|
1137
|
+
!statusItemNumericType(@FieldType(Option, "id")) or @FieldType(Option, "label") != []const u8 or
|
|
1138
|
+
@FieldType(Option, "command") != []const u8 or @FieldType(Option, "selected") != bool or
|
|
1139
|
+
@FieldType(Option, "enabled") != bool) @compileError(teaching);
|
|
1140
|
+
|
|
1141
|
+
const Metric = statusItemRecordType(metric_info.optional.child, teaching);
|
|
1142
|
+
const metric_fields = @typeInfo(Metric).@"struct".fields;
|
|
1143
|
+
if (metric_fields.len != 3 or !@hasField(Metric, "primaryText") or !@hasField(Metric, "secondaryText") or
|
|
1144
|
+
!@hasField(Metric, "accessibilityLabel") or @FieldType(Metric, "primaryText") != []const u8 or
|
|
1145
|
+
@FieldType(Metric, "secondaryText") != []const u8 or @FieldType(Metric, "accessibilityLabel") != []const u8) @compileError(teaching);
|
|
1146
|
+
|
|
1147
|
+
const Chart = statusItemRecordType(chart_info.optional.child, teaching);
|
|
1148
|
+
const chart_fields = @typeInfo(Chart).@"struct".fields;
|
|
1149
|
+
if (chart_fields.len != 6 or !@hasField(Chart, "values") or !@hasField(Chart, "minValue") or
|
|
1150
|
+
!@hasField(Chart, "maxValue") or !@hasField(Chart, "leadingCaption") or
|
|
1151
|
+
!@hasField(Chart, "trailingSummary") or !@hasField(Chart, "accessibilityLabel")) @compileError(teaching);
|
|
1152
|
+
const values_info = @typeInfo(@FieldType(Chart, "values"));
|
|
1153
|
+
if (values_info != .pointer or values_info.pointer.size != .slice or !values_info.pointer.is_const or
|
|
1154
|
+
!statusItemNumericType(values_info.pointer.child) or !statusItemNumericType(@FieldType(Chart, "minValue")) or
|
|
1155
|
+
!statusItemNumericType(@FieldType(Chart, "maxValue")) or @FieldType(Chart, "leadingCaption") != []const u8 or
|
|
1156
|
+
@FieldType(Chart, "trailingSummary") != []const u8 or @FieldType(Chart, "accessibilityLabel") != []const u8) @compileError(teaching);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1062
1159
|
fn statusItemNumericType(comptime T: type) bool {
|
|
1063
1160
|
return @typeInfo(T) == .int or @typeInfo(T) == .float;
|
|
1064
1161
|
}
|
|
@@ -1561,7 +1658,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1561
1658
|
|
|
1562
1659
|
const StatusItemsAdapterTestCore = struct {
|
|
1563
1660
|
const Tone = enum { normal, warning, critical };
|
|
1564
|
-
const Role = enum { command, info, header, hero, agent, context };
|
|
1661
|
+
const Role = enum { command, info, header, hero, agent, context, segmented, chart };
|
|
1565
1662
|
const Modifiers = struct {
|
|
1566
1663
|
primary: bool,
|
|
1567
1664
|
command: bool,
|
|
@@ -1575,6 +1672,29 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1575
1672
|
tone: Tone,
|
|
1576
1673
|
iconOpacity: f64,
|
|
1577
1674
|
monospaced: bool,
|
|
1675
|
+
fontSize: ?f64,
|
|
1676
|
+
fontWeight: ?enum { regular, medium, semibold, bold },
|
|
1677
|
+
};
|
|
1678
|
+
const SegmentOption = struct {
|
|
1679
|
+
id: f64,
|
|
1680
|
+
label: []const u8,
|
|
1681
|
+
command: []const u8,
|
|
1682
|
+
selected: bool,
|
|
1683
|
+
enabled: bool,
|
|
1684
|
+
};
|
|
1685
|
+
const Segmented = struct { options: []const SegmentOption };
|
|
1686
|
+
const Metric = struct {
|
|
1687
|
+
primaryText: []const u8,
|
|
1688
|
+
secondaryText: []const u8,
|
|
1689
|
+
accessibilityLabel: []const u8,
|
|
1690
|
+
};
|
|
1691
|
+
const Chart = struct {
|
|
1692
|
+
values: []const f64,
|
|
1693
|
+
minValue: f64,
|
|
1694
|
+
maxValue: f64,
|
|
1695
|
+
leadingCaption: []const u8,
|
|
1696
|
+
trailingSummary: []const u8,
|
|
1697
|
+
accessibilityLabel: []const u8,
|
|
1578
1698
|
};
|
|
1579
1699
|
const Item = struct {
|
|
1580
1700
|
id: f64,
|
|
@@ -1586,6 +1706,9 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1586
1706
|
role: Role,
|
|
1587
1707
|
key: []const u8,
|
|
1588
1708
|
modifiers: Modifiers,
|
|
1709
|
+
segmented: ?Segmented,
|
|
1710
|
+
metric: ?Metric,
|
|
1711
|
+
chart: ?Chart,
|
|
1589
1712
|
};
|
|
1590
1713
|
const Descriptor = struct {
|
|
1591
1714
|
id: f64,
|
|
@@ -1609,6 +1732,9 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1609
1732
|
.role = .command,
|
|
1610
1733
|
.key = "r",
|
|
1611
1734
|
.modifiers = .{ .primary = true, .command = false, .control = false, .option = false, .shift = false },
|
|
1735
|
+
.segmented = null,
|
|
1736
|
+
.metric = null,
|
|
1737
|
+
.chart = null,
|
|
1612
1738
|
}};
|
|
1613
1739
|
const descriptors = [_]Descriptor{.{
|
|
1614
1740
|
.id = 7,
|
|
@@ -1618,7 +1744,7 @@ const StatusItemsAdapterTestCore = struct {
|
|
|
1618
1744
|
.activationCommand = "spend.open",
|
|
1619
1745
|
.alternateActivationCommand = "",
|
|
1620
1746
|
.openCommand = "spend.refresh",
|
|
1621
|
-
.presentation = .{ .title = "$7", .width = 52, .tone = .warning, .iconOpacity = 0.75, .monospaced = true },
|
|
1747
|
+
.presentation = .{ .title = "$7", .width = 52, .tone = .warning, .iconOpacity = 0.75, .monospaced = true, .fontSize = null, .fontWeight = null },
|
|
1622
1748
|
.items = &rows,
|
|
1623
1749
|
}};
|
|
1624
1750
|
|
|
@@ -1640,6 +1766,8 @@ test "TypeScript statusItems adapter validates and projects canonical descriptor
|
|
|
1640
1766
|
try std.testing.expectEqual(@as(platform.StatusItemId, 7), descriptors[0].id);
|
|
1641
1767
|
try std.testing.expect(!descriptors[0].visible);
|
|
1642
1768
|
try std.testing.expectEqualStrings("$7", descriptors[0].state.presentation.title);
|
|
1769
|
+
try std.testing.expectEqual(@as(f32, 0), descriptors[0].state.presentation.font_size);
|
|
1770
|
+
try std.testing.expectEqual(platform.TrayFontWeight.regular, descriptors[0].state.presentation.font_weight);
|
|
1643
1771
|
try std.testing.expectEqualStrings("spend.png", descriptors[0].state.icon_path);
|
|
1644
1772
|
try std.testing.expectEqual(@as(usize, 1), descriptors[0].state.items.len);
|
|
1645
1773
|
try std.testing.expectEqual(@as(platform.TrayItemId, 3), descriptors[0].state.items[0].id);
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -316,6 +316,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
316
316
|
title_buffer: [platform.max_tray_title_bytes]u8 = undefined,
|
|
317
317
|
arena_buffer: [2048]u8 = undefined,
|
|
318
318
|
items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
319
|
+
segment_options: [platform.max_tray_items * platform.max_tray_segment_options]platform.TraySegmentOption = undefined,
|
|
320
|
+
chart_values: [platform.max_tray_items * platform.max_tray_chart_values]f32 = undefined,
|
|
319
321
|
};
|
|
320
322
|
|
|
321
323
|
/// Scratch for `status_items_fn`. The flat row store gives each
|
|
@@ -326,6 +328,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
326
328
|
title_buffers: [platform.max_status_items][platform.max_tray_title_bytes]u8 = undefined,
|
|
327
329
|
arena_buffer: [platform.max_status_items * 2048]u8 = undefined,
|
|
328
330
|
items: [platform.max_status_items * platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
331
|
+
segment_options: [platform.max_status_items * platform.max_tray_items * platform.max_tray_segment_options]platform.TraySegmentOption = undefined,
|
|
332
|
+
chart_values: [platform.max_status_items * platform.max_tray_items * platform.max_tray_chart_values]f32 = undefined,
|
|
329
333
|
};
|
|
330
334
|
|
|
331
335
|
const AppliedStatusItem = struct {
|
|
@@ -4843,7 +4847,8 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4843
4847
|
hasher.update(presentation.title);
|
|
4844
4848
|
hasher.update(std.mem.asBytes(&presentation.width));
|
|
4845
4849
|
hasher.update(std.mem.asBytes(&presentation.icon_opacity));
|
|
4846
|
-
hasher.update(
|
|
4850
|
+
hasher.update(std.mem.asBytes(&presentation.font_size));
|
|
4851
|
+
hasher.update(&.{ @intFromEnum(presentation.tone), @intFromBool(presentation.monospaced), @intFromEnum(presentation.font_weight) });
|
|
4847
4852
|
return hasher.final();
|
|
4848
4853
|
}
|
|
4849
4854
|
|
|
@@ -4860,6 +4865,33 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4860
4865
|
hasher.update(item.detail);
|
|
4861
4866
|
hasher.update(std.mem.asBytes(&item.key.len));
|
|
4862
4867
|
hasher.update(item.key);
|
|
4868
|
+
if (item.segmented) |segmented| {
|
|
4869
|
+
hasher.update(std.mem.asBytes(&segmented.options.len));
|
|
4870
|
+
for (segmented.options) |option| {
|
|
4871
|
+
hasher.update(std.mem.asBytes(&option.id));
|
|
4872
|
+
hasher.update(std.mem.asBytes(&option.label.len));
|
|
4873
|
+
hasher.update(option.label);
|
|
4874
|
+
hasher.update(std.mem.asBytes(&option.command.len));
|
|
4875
|
+
hasher.update(option.command);
|
|
4876
|
+
hasher.update(&.{ @intFromBool(option.selected), @intFromBool(option.enabled) });
|
|
4877
|
+
}
|
|
4878
|
+
}
|
|
4879
|
+
if (item.metric) |metric| {
|
|
4880
|
+
for ([_][]const u8{ metric.primary_text, metric.secondary_text, metric.accessibility_label }) |field| {
|
|
4881
|
+
hasher.update(std.mem.asBytes(&field.len));
|
|
4882
|
+
hasher.update(field);
|
|
4883
|
+
}
|
|
4884
|
+
}
|
|
4885
|
+
if (item.chart) |chart| {
|
|
4886
|
+
hasher.update(std.mem.asBytes(&chart.values.len));
|
|
4887
|
+
hasher.update(std.mem.sliceAsBytes(chart.values));
|
|
4888
|
+
hasher.update(std.mem.asBytes(&chart.min_value));
|
|
4889
|
+
hasher.update(std.mem.asBytes(&chart.max_value));
|
|
4890
|
+
for ([_][]const u8{ chart.leading_caption, chart.trailing_summary, chart.accessibility_label }) |field| {
|
|
4891
|
+
hasher.update(std.mem.asBytes(&field.len));
|
|
4892
|
+
hasher.update(field);
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4863
4895
|
hasher.update(&.{
|
|
4864
4896
|
@intFromBool(item.separator),
|
|
4865
4897
|
@intFromBool(item.enabled),
|
|
@@ -4540,11 +4540,74 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
|
|
|
4540
4540
|
|
|
4541
4541
|
// Unknown or malformed item ids are loud driver misuse, never a
|
|
4542
4542
|
// silent no-op or a fallback command dispatch.
|
|
4543
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 11"));
|
|
4543
4544
|
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 99"));
|
|
4544
4545
|
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action open"));
|
|
4545
4546
|
try std.testing.expectEqual(@as(u32, 1), app_state.model.selected_issue);
|
|
4546
4547
|
}
|
|
4547
4548
|
|
|
4549
|
+
const SegmentedAutomationModel = struct { selected: bool = true };
|
|
4550
|
+
const SegmentedAutomationMsg = union(enum) { enable, disable };
|
|
4551
|
+
const SegmentedAutomationApp = ui_app_model.UiApp(SegmentedAutomationModel, SegmentedAutomationMsg);
|
|
4552
|
+
|
|
4553
|
+
fn segmentedAutomationUpdate(model: *SegmentedAutomationModel, msg: SegmentedAutomationMsg) void {
|
|
4554
|
+
switch (msg) {
|
|
4555
|
+
.enable => model.selected = true,
|
|
4556
|
+
.disable => model.selected = false,
|
|
4557
|
+
}
|
|
4558
|
+
}
|
|
4559
|
+
|
|
4560
|
+
fn segmentedAutomationView(ui: *SegmentedAutomationApp.Ui, _: *const SegmentedAutomationModel) SegmentedAutomationApp.Ui.Node {
|
|
4561
|
+
return ui.text(.{}, "Segments");
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
fn segmentedAutomationCommand(name: []const u8) ?SegmentedAutomationMsg {
|
|
4565
|
+
if (std.mem.eql(u8, name, "segment.enable")) return .enable;
|
|
4566
|
+
if (std.mem.eql(u8, name, "segment.disable")) return .disable;
|
|
4567
|
+
return null;
|
|
4568
|
+
}
|
|
4569
|
+
|
|
4570
|
+
fn segmentedAutomationStatusItem(model: *const SegmentedAutomationModel, scratch: *SegmentedAutomationApp.StatusItemScratch) SegmentedAutomationApp.StatusItemState {
|
|
4571
|
+
scratch.segment_options[0] = .{ .id = 20, .label = "On", .command = "segment.enable", .selected = model.selected, .enabled = false };
|
|
4572
|
+
scratch.segment_options[1] = .{ .id = 21, .label = "Off", .command = "segment.disable", .selected = !model.selected };
|
|
4573
|
+
scratch.items[0] = .{ .role = .segmented, .segmented = .{ .options = scratch.segment_options[0..2] } };
|
|
4574
|
+
return .{ .items = scratch.items[0..1] };
|
|
4575
|
+
}
|
|
4576
|
+
|
|
4577
|
+
test "automation tray-action rejects disabled segmented options" {
|
|
4578
|
+
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
4579
|
+
defer harness.destroy(std.testing.allocator);
|
|
4580
|
+
harness.null_platform.gpu_surfaces = true;
|
|
4581
|
+
|
|
4582
|
+
const app_state = try std.testing.allocator.create(SegmentedAutomationApp);
|
|
4583
|
+
defer std.testing.allocator.destroy(app_state);
|
|
4584
|
+
app_state.* = SegmentedAutomationApp.init(std.heap.page_allocator, .{}, .{
|
|
4585
|
+
.name = "ui-app-tray-segmented-automation",
|
|
4586
|
+
.scene = counter_scene,
|
|
4587
|
+
.canvas_label = canvas_label,
|
|
4588
|
+
.update = segmentedAutomationUpdate,
|
|
4589
|
+
.view = segmentedAutomationView,
|
|
4590
|
+
.on_command = segmentedAutomationCommand,
|
|
4591
|
+
.status_item_fn = segmentedAutomationStatusItem,
|
|
4592
|
+
});
|
|
4593
|
+
defer app_state.deinit();
|
|
4594
|
+
const app = app_state.app();
|
|
4595
|
+
try harness.start(app);
|
|
4596
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
4597
|
+
.label = canvas_label,
|
|
4598
|
+
.size = geometry.SizeF.init(400, 300),
|
|
4599
|
+
.scale_factor = 1,
|
|
4600
|
+
.frame_index = 1,
|
|
4601
|
+
.timestamp_ns = 1_000_000,
|
|
4602
|
+
.nonblank = true,
|
|
4603
|
+
} });
|
|
4604
|
+
|
|
4605
|
+
try std.testing.expectError(error.InvalidCommand, harness.runtime.dispatchAutomationCommand(app, "tray-action 20"));
|
|
4606
|
+
try std.testing.expect(app_state.model.selected);
|
|
4607
|
+
try harness.runtime.dispatchAutomationCommand(app, "tray-action 21");
|
|
4608
|
+
try std.testing.expect(!app_state.model.selected);
|
|
4609
|
+
}
|
|
4610
|
+
|
|
4548
4611
|
const TaskModel = struct {
|
|
4549
4612
|
completed: u32 = 0,
|
|
4550
4613
|
deleted: u32 = 0,
|