@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
|
@@ -40,15 +40,19 @@
|
|
|
40
40
|
//!
|
|
41
41
|
//! Everything else on `UiApp.Options` is the wiring's, unchanged: view
|
|
42
42
|
//! or markup, scene, `on_command` maps command ids through the core's
|
|
43
|
-
//! `commandMsg`, `tokens_fn`/`windows_fn
|
|
43
|
+
//! `commandMsg`, `tokens_fn`/`windows_fn`/status-item callbacks derive from
|
|
44
44
|
//! the committed model. One model-helper convention joins that wiring:
|
|
45
45
|
//! an exported `themePack(model): "house" | "geist"` helper selects the
|
|
46
46
|
//! stock pack live through `theme_fn`, without taking ownership of the
|
|
47
47
|
//! system appearance axes. An exported
|
|
48
|
-
//! `statusItem(model): StatusItemState` helper similarly owns
|
|
49
|
-
//! menu-bar item through `status_item_fn
|
|
50
|
-
//!
|
|
51
|
-
//!
|
|
48
|
+
//! `statusItem(model): StatusItemState` helper similarly owns one complete
|
|
49
|
+
//! menu-bar item through `status_item_fn`; `statusItems(model)` owns a keyed
|
|
50
|
+
//! collection through `status_items_fn`. Both keep shell, presentation, and
|
|
51
|
+
//! menu live. `windows(model): readonly WindowDescriptor[]` owns the
|
|
52
|
+
//! model-declared secondary-window set through `windows_fn`; the launcher or
|
|
53
|
+
//! hand wiring supplies the statically compiled `window_view` registry. In
|
|
54
|
+
//! hand wiring, empty singular shell fields inherit the static `status_item`
|
|
55
|
+
//! options. The two
|
|
52
56
|
//! seams the core owns — `update_fx` and
|
|
53
57
|
//! `init_fx` — are stamped by this adapter and must be left null.
|
|
54
58
|
//!
|
|
@@ -74,6 +78,8 @@ const persist_store = @import("persist_store.zig");
|
|
|
74
78
|
const ui_app = @import("ui_app.zig");
|
|
75
79
|
const ts_core_host = @import("ts_core_host.zig");
|
|
76
80
|
|
|
81
|
+
const ts_ui_app_log = std.log.scoped(.zero_ts_ui_app);
|
|
82
|
+
|
|
77
83
|
pub fn TsUiApp(comptime core: type) type {
|
|
78
84
|
return struct {
|
|
79
85
|
/// The effect bridge — shared with any direct `TsCoreHost(core)`
|
|
@@ -287,6 +293,20 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
287
293
|
return App.init(backing, Host.model().*, stamped);
|
|
288
294
|
}
|
|
289
295
|
|
|
296
|
+
/// Mobile counterpart of `init`/`create`: the embed host
|
|
297
|
+
/// (`native_sdk.embed.UiAppHost`) owns App construction, so this
|
|
298
|
+
/// resolves the adapter's stamped options and applies the core
|
|
299
|
+
/// options — the boot model commits here, and the generated mobile
|
|
300
|
+
/// wiring's `initModel` reads `Host.model()` afterwards. The embed
|
|
301
|
+
/// host then drives the same stamped `init_fx`/`update_fx` seams
|
|
302
|
+
/// the desktop wiring gets.
|
|
303
|
+
pub fn mobileOptions(core_options: CoreOptions, options: Options) Options {
|
|
304
|
+
const stamped = stampOptions(options);
|
|
305
|
+
Host.boot();
|
|
306
|
+
applyCoreOptions(core_options);
|
|
307
|
+
return stamped;
|
|
308
|
+
}
|
|
309
|
+
|
|
290
310
|
/// Heap counterpart of `init`, mirroring `UiApp.create`: the app
|
|
291
311
|
/// struct (and any real model) is multi-MB, so construct it in
|
|
292
312
|
/// place on the heap — the shape generated wiring and `main`
|
|
@@ -312,6 +332,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
312
332
|
var persist_options_store: ?PersistOptions = null;
|
|
313
333
|
var host_call_mux_store: ?HostCallMux = null;
|
|
314
334
|
var lifecycle_store: ?*const fn (event: runtime_core.LifecycleEvent) ?Msg = null;
|
|
335
|
+
var command_store: ?*const fn (name: []const u8) ?Msg = null;
|
|
315
336
|
var lifecycle_flush_after_update = false;
|
|
316
337
|
|
|
317
338
|
fn applyCoreOptions(core_options: CoreOptions) void {
|
|
@@ -345,6 +366,7 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
345
366
|
@panic("TsUiApp does not support Options.sync: a committed model cannot be mutated in place - echo widget state through on-change/on-scroll Msgs instead");
|
|
346
367
|
}
|
|
347
368
|
var stamped = options;
|
|
369
|
+
command_store = stamped.on_command;
|
|
348
370
|
lifecycle_store = stamped.on_lifecycle;
|
|
349
371
|
lifecycle_flush_after_update = false;
|
|
350
372
|
stamped.on_lifecycle = lifecycleAdapter;
|
|
@@ -365,9 +387,9 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
365
387
|
}
|
|
366
388
|
// A statusItem helper is the TS app's model-derived shell
|
|
367
389
|
// declaration. UiApp installs it on the first frame and
|
|
368
|
-
// independently patches presentation/menu after each
|
|
369
|
-
// committed rebuild; empty
|
|
370
|
-
//
|
|
390
|
+
// independently patches shell/presentation/menu after each
|
|
391
|
+
// committed rebuild; empty fields inherit custom static
|
|
392
|
+
// status_item options in hand wiring.
|
|
371
393
|
if (comptime @hasDecl(Model, "statusItem")) {
|
|
372
394
|
if (options.status_item_fn != null) {
|
|
373
395
|
@panic("TsUiApp wires status_item_fn from the core's statusItem helper - remove the wiring's status_item_fn");
|
|
@@ -375,6 +397,26 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
375
397
|
comptime validateStatusItemHelper();
|
|
376
398
|
stamped.status_item_fn = statusItemAdapter;
|
|
377
399
|
}
|
|
400
|
+
if (comptime @hasDecl(Model, "statusItems")) {
|
|
401
|
+
if (comptime @hasDecl(Model, "statusItem")) {
|
|
402
|
+
@compileError("TsUiApp: export either statusItem or statusItems, not both");
|
|
403
|
+
}
|
|
404
|
+
if (options.status_items_fn != null or options.status_item != null or options.status_item_fn != null) {
|
|
405
|
+
@panic("TsUiApp wires status_items_fn from the core's statusItems helper - remove singular/custom status-item wiring");
|
|
406
|
+
}
|
|
407
|
+
comptime validateStatusItemsHelper();
|
|
408
|
+
stamped.status_items_fn = statusItemsAdapter;
|
|
409
|
+
}
|
|
410
|
+
if (comptime @hasDecl(Model, "windows")) {
|
|
411
|
+
if (options.windows_fn != null) {
|
|
412
|
+
@panic("TsUiApp wires windows_fn from the core's windows helper - remove the wiring's windows_fn");
|
|
413
|
+
}
|
|
414
|
+
if (options.window_view == null) {
|
|
415
|
+
@panic("TsUiApp windows(model) requires a window_view registry - default apps provide src/windows/<label>.native; hand wiring must set Options.window_view");
|
|
416
|
+
}
|
|
417
|
+
comptime validateWindowsHelper();
|
|
418
|
+
stamped.windows_fn = windowsAdapter;
|
|
419
|
+
}
|
|
378
420
|
// The core's host-event channels, comptime-detected from its
|
|
379
421
|
// exports (export exists -> wired; every shape mismatch is a
|
|
380
422
|
// teaching compile error in the adapter below). A wiring that
|
|
@@ -504,6 +546,148 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
504
546
|
return statusItemState(state, scratch.items[0..state.items.len]);
|
|
505
547
|
}
|
|
506
548
|
|
|
549
|
+
fn statusItemsAdapter(model: *const Model, scratch: *App.StatusItemsScratch) []const App.StatusItemDescriptor {
|
|
550
|
+
const params = @typeInfo(@TypeOf(Model.statusItems)).@"fn".params;
|
|
551
|
+
const raw_states = if (comptime params.len == 1)
|
|
552
|
+
model.statusItems()
|
|
553
|
+
else
|
|
554
|
+
model.statusItems(core.rt.frameAllocator());
|
|
555
|
+
if (raw_states.len > scratch.status_items.len) {
|
|
556
|
+
scratch.status_items[0] = .{ .id = 0 };
|
|
557
|
+
return scratch.status_items[0..1];
|
|
558
|
+
}
|
|
559
|
+
for (raw_states, 0..) |raw_state, status_index| {
|
|
560
|
+
const state = if (comptime @typeInfo(@TypeOf(raw_state)) == .pointer) raw_state.* else raw_state;
|
|
561
|
+
const row_start = status_index * platform.max_tray_items;
|
|
562
|
+
const row_storage = scratch.items[row_start .. row_start + platform.max_tray_items];
|
|
563
|
+
if (state.items.len > row_storage.len) {
|
|
564
|
+
row_storage[0] = .{ .id = 0, .label = "status item has more than 32 rows", .command = "status-item-overflow" };
|
|
565
|
+
scratch.status_items[status_index] = .{
|
|
566
|
+
.id = statusItemId(state.id),
|
|
567
|
+
.visible = state.visible,
|
|
568
|
+
.state = statusItemState(state, row_storage[0..1]),
|
|
569
|
+
};
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
for (state.items, 0..) |raw_item, item_index| {
|
|
573
|
+
const item = if (comptime @typeInfo(@TypeOf(raw_item)) == .pointer) raw_item.* else raw_item;
|
|
574
|
+
row_storage[item_index] = statusItemMenuItem(item);
|
|
575
|
+
}
|
|
576
|
+
scratch.status_items[status_index] = .{
|
|
577
|
+
.id = statusItemId(state.id),
|
|
578
|
+
.visible = state.visible,
|
|
579
|
+
.state = statusItemState(state, row_storage[0..state.items.len]),
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
return scratch.status_items[0..raw_states.len];
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
fn windowsAdapter(model: *const Model, scratch: *App.WindowsScratch) []const App.WindowDescriptor {
|
|
586
|
+
const params = @typeInfo(@TypeOf(Model.windows)).@"fn".params;
|
|
587
|
+
const raw_windows = if (comptime params.len == 1)
|
|
588
|
+
model.windows()
|
|
589
|
+
else
|
|
590
|
+
model.windows(core.rt.frameAllocator());
|
|
591
|
+
if (raw_windows.len > scratch.windows.len) {
|
|
592
|
+
ts_ui_app_log.warn(
|
|
593
|
+
"windows(model) declared {d} windows; the budget is {d} (canvas_limits.max_ui_app_windows) - the excess is ignored",
|
|
594
|
+
.{ raw_windows.len, scratch.windows.len },
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
const kept = raw_windows[0..@min(raw_windows.len, scratch.windows.len)];
|
|
598
|
+
for (kept, 0..) |raw_window, index| {
|
|
599
|
+
const window = if (comptime @typeInfo(@TypeOf(raw_window)) == .pointer) raw_window.* else raw_window;
|
|
600
|
+
const close_policy = windowClosePolicy(window.closePolicy);
|
|
601
|
+
scratch.windows[index] = .{
|
|
602
|
+
.label = window.label,
|
|
603
|
+
.canvas_label = window.canvasLabel,
|
|
604
|
+
.title = window.title,
|
|
605
|
+
.width = statusItemFloat(window.width),
|
|
606
|
+
.height = statusItemFloat(window.height),
|
|
607
|
+
.x = optionalWindowFloat(window.x),
|
|
608
|
+
.y = optionalWindowFloat(window.y),
|
|
609
|
+
.resizable = window.resizable,
|
|
610
|
+
.min_width = statusItemFloat(window.minWidth),
|
|
611
|
+
.min_height = statusItemFloat(window.minHeight),
|
|
612
|
+
.titlebar = windowTitlebar(window.titlebar),
|
|
613
|
+
.transparent = window.transparent,
|
|
614
|
+
.always_on_top = window.alwaysOnTop,
|
|
615
|
+
.click_through = window.clickThrough,
|
|
616
|
+
.activate_on_show = window.activateOnShow,
|
|
617
|
+
.allows_fullscreen = window.allowsFullscreen,
|
|
618
|
+
.close_policy = close_policy,
|
|
619
|
+
// A hide never closes and therefore never routes its
|
|
620
|
+
// command. A real close must map a non-empty command
|
|
621
|
+
// now, before the window is created, so the adapter
|
|
622
|
+
// cannot install a dead callback that lets the model
|
|
623
|
+
// resurrect the just-closed window later.
|
|
624
|
+
.on_close = if (close_policy == .quit) requireWindowCloseMsg(window.onCloseCommand) else null,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
return scratch.windows[0..kept.len];
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
fn optionalWindowFloat(value: anytype) ?f32 {
|
|
631
|
+
return if (value) |present| statusItemFloat(present) else null;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
fn windowTitlebar(value: anytype) @import("app_manifest").WindowTitlebarStyle {
|
|
635
|
+
const Target = @import("app_manifest").WindowTitlebarStyle;
|
|
636
|
+
inline for (std.meta.fields(Target)) |field| {
|
|
637
|
+
if (std.mem.eql(u8, @tagName(value), field.name)) return @enumFromInt(field.value);
|
|
638
|
+
}
|
|
639
|
+
unreachable;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
fn windowClosePolicy(value: anytype) @import("app_manifest").WindowClosePolicy {
|
|
643
|
+
const Target = @import("app_manifest").WindowClosePolicy;
|
|
644
|
+
inline for (std.meta.fields(Target)) |field| {
|
|
645
|
+
if (std.mem.eql(u8, @tagName(value), field.name)) return @enumFromInt(field.value);
|
|
646
|
+
}
|
|
647
|
+
unreachable;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const WindowCloseCommandError = error{
|
|
651
|
+
MissingCommandMapper,
|
|
652
|
+
UnmappedCommand,
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
fn windowCloseMsg(command: []const u8) WindowCloseCommandError!?Msg {
|
|
656
|
+
if (command.len == 0) return null;
|
|
657
|
+
const map = command_store orelse return error.MissingCommandMapper;
|
|
658
|
+
return map(command) orelse error.UnmappedCommand;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
fn requireWindowCloseMsg(command: []const u8) ?Msg {
|
|
662
|
+
return windowCloseMsg(command) catch |err| {
|
|
663
|
+
ts_ui_app_log.err(
|
|
664
|
+
"window onCloseCommand '{s}' cannot be installed: {s}; map every quit-close command through Options.on_command (the default launcher wires exported commandMsg)",
|
|
665
|
+
.{ command, @errorName(err) },
|
|
666
|
+
);
|
|
667
|
+
@panic("TsUiApp: a non-empty quit-close onCloseCommand must map through Options.on_command");
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
fn statusItemMenuItem(item: anytype) platform.TrayMenuItem {
|
|
672
|
+
return .{
|
|
673
|
+
.id = statusItemId(item.id),
|
|
674
|
+
.label = item.label,
|
|
675
|
+
.command = item.command,
|
|
676
|
+
.separator = item.separator,
|
|
677
|
+
.enabled = item.enabled,
|
|
678
|
+
.detail = item.detail,
|
|
679
|
+
.role = statusItemRole(item.role),
|
|
680
|
+
.key = item.key,
|
|
681
|
+
.modifiers = .{
|
|
682
|
+
.primary = item.modifiers.primary,
|
|
683
|
+
.command = item.modifiers.command,
|
|
684
|
+
.control = item.modifiers.control,
|
|
685
|
+
.option = item.modifiers.option,
|
|
686
|
+
.shift = item.modifiers.shift,
|
|
687
|
+
},
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
|
|
507
691
|
fn statusItemState(state: anytype, items: []const platform.TrayMenuItem) App.StatusItemState {
|
|
508
692
|
const presentation = if (comptime @typeInfo(@TypeOf(state.presentation)) == .pointer) state.presentation.* else state.presentation;
|
|
509
693
|
return .{
|
|
@@ -637,6 +821,115 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
637
821
|
}
|
|
638
822
|
}
|
|
639
823
|
|
|
824
|
+
fn validateStatusItemsHelper() void {
|
|
825
|
+
const teaching = "TsUiApp: statusItems must be exported from core.ts as statusItems(model: Model): readonly StatusItemDescriptor[]; import StatusItemDescriptor from @native-sdk/core/events";
|
|
826
|
+
const helper_info = @typeInfo(@TypeOf(Model.statusItems));
|
|
827
|
+
if (helper_info != .@"fn") @compileError(teaching);
|
|
828
|
+
const function = helper_info.@"fn";
|
|
829
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type == null or function.params[0].type.? != *const Model) {
|
|
830
|
+
@compileError(teaching);
|
|
831
|
+
}
|
|
832
|
+
if (function.params.len == 2) {
|
|
833
|
+
if (function.params[1].type == null or function.params[1].type.? != std.mem.Allocator or
|
|
834
|
+
!@hasDecl(core, "rt") or !@hasDecl(core.rt, "frameAllocator"))
|
|
835
|
+
{
|
|
836
|
+
@compileError(teaching);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
const Return = function.return_type orelse @compileError(teaching);
|
|
840
|
+
const return_info = @typeInfo(Return);
|
|
841
|
+
if (return_info != .pointer or return_info.pointer.size != .slice or !return_info.pointer.is_const) @compileError(teaching);
|
|
842
|
+
const State = statusItemRecordType(return_info.pointer.child, teaching);
|
|
843
|
+
const info = @typeInfo(State).@"struct";
|
|
844
|
+
if (info.fields.len != 9 or !@hasField(State, "id") or !@hasField(State, "visible") or
|
|
845
|
+
!@hasField(State, "iconPath") or !@hasField(State, "tooltip") or !@hasField(State, "activationCommand") or
|
|
846
|
+
!@hasField(State, "alternateActivationCommand") or !@hasField(State, "openCommand") or
|
|
847
|
+
!@hasField(State, "presentation") or !@hasField(State, "items") or
|
|
848
|
+
!statusItemNumericType(@FieldType(State, "id")) or @FieldType(State, "visible") != bool or
|
|
849
|
+
@FieldType(State, "iconPath") != []const u8 or @FieldType(State, "tooltip") != []const u8 or
|
|
850
|
+
@FieldType(State, "activationCommand") != []const u8 or @FieldType(State, "alternateActivationCommand") != []const u8 or
|
|
851
|
+
@FieldType(State, "openCommand") != []const u8)
|
|
852
|
+
{
|
|
853
|
+
@compileError(teaching);
|
|
854
|
+
}
|
|
855
|
+
const Presentation = statusItemRecordType(@FieldType(State, "presentation"), teaching);
|
|
856
|
+
const presentation_info = @typeInfo(Presentation).@"struct";
|
|
857
|
+
if (presentation_info.fields.len != 5 or !@hasField(Presentation, "title") or !@hasField(Presentation, "width") or
|
|
858
|
+
!@hasField(Presentation, "tone") or !@hasField(Presentation, "iconOpacity") or !@hasField(Presentation, "monospaced") or
|
|
859
|
+
@FieldType(Presentation, "title") != []const u8 or !statusItemNumericType(@FieldType(Presentation, "width")) or
|
|
860
|
+
!statusItemEnumType(@FieldType(Presentation, "tone"), &.{ "normal", "warning", "critical" }) or
|
|
861
|
+
!statusItemNumericType(@FieldType(Presentation, "iconOpacity")) or @FieldType(Presentation, "monospaced") != bool)
|
|
862
|
+
{
|
|
863
|
+
@compileError(teaching);
|
|
864
|
+
}
|
|
865
|
+
const items_info = @typeInfo(@FieldType(State, "items"));
|
|
866
|
+
if (items_info != .pointer or items_info.pointer.size != .slice or !items_info.pointer.is_const) @compileError(teaching);
|
|
867
|
+
const Item = statusItemRecordType(items_info.pointer.child, teaching);
|
|
868
|
+
const item_info = @typeInfo(Item).@"struct";
|
|
869
|
+
if (item_info.fields.len != 9 or !@hasField(Item, "id") or !@hasField(Item, "label") or
|
|
870
|
+
!@hasField(Item, "command") or !@hasField(Item, "separator") or !@hasField(Item, "enabled") or
|
|
871
|
+
!@hasField(Item, "detail") or !@hasField(Item, "role") or !@hasField(Item, "key") or
|
|
872
|
+
!@hasField(Item, "modifiers") or !statusItemNumericType(@FieldType(Item, "id")) or
|
|
873
|
+
@FieldType(Item, "label") != []const u8 or @FieldType(Item, "command") != []const u8 or
|
|
874
|
+
@FieldType(Item, "separator") != bool or @FieldType(Item, "enabled") != bool or
|
|
875
|
+
@FieldType(Item, "detail") != []const u8 or
|
|
876
|
+
!statusItemEnumType(@FieldType(Item, "role"), &.{ "command", "info", "header", "hero", "agent", "context" }) or
|
|
877
|
+
@FieldType(Item, "key") != []const u8)
|
|
878
|
+
{
|
|
879
|
+
@compileError(teaching);
|
|
880
|
+
}
|
|
881
|
+
const Modifiers = statusItemRecordType(@FieldType(Item, "modifiers"), teaching);
|
|
882
|
+
const modifiers_info = @typeInfo(Modifiers).@"struct";
|
|
883
|
+
if (modifiers_info.fields.len != 5 or !@hasField(Modifiers, "primary") or !@hasField(Modifiers, "command") or
|
|
884
|
+
!@hasField(Modifiers, "control") or !@hasField(Modifiers, "option") or !@hasField(Modifiers, "shift") or
|
|
885
|
+
@FieldType(Modifiers, "primary") != bool or @FieldType(Modifiers, "command") != bool or
|
|
886
|
+
@FieldType(Modifiers, "control") != bool or @FieldType(Modifiers, "option") != bool or
|
|
887
|
+
@FieldType(Modifiers, "shift") != bool)
|
|
888
|
+
{
|
|
889
|
+
@compileError(teaching);
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
fn validateWindowsHelper() void {
|
|
894
|
+
const teaching = "TsUiApp: windows must be exported from core.ts as windows(model: Model): readonly WindowDescriptor[]; import WindowDescriptor from @native-sdk/core/events and construct entries with windowDescriptor(...)";
|
|
895
|
+
const helper_info = @typeInfo(@TypeOf(Model.windows));
|
|
896
|
+
if (helper_info != .@"fn") @compileError(teaching);
|
|
897
|
+
const function = helper_info.@"fn";
|
|
898
|
+
if ((function.params.len != 1 and function.params.len != 2) or function.params[0].type == null or function.params[0].type.? != *const Model) @compileError(teaching);
|
|
899
|
+
if (function.params.len == 2) {
|
|
900
|
+
if (function.params[1].type == null or function.params[1].type.? != std.mem.Allocator or
|
|
901
|
+
!@hasDecl(core, "rt") or !@hasDecl(core.rt, "frameAllocator")) @compileError(teaching);
|
|
902
|
+
}
|
|
903
|
+
const Return = function.return_type orelse @compileError(teaching);
|
|
904
|
+
const return_info = @typeInfo(Return);
|
|
905
|
+
if (return_info != .pointer or return_info.pointer.size != .slice or !return_info.pointer.is_const) @compileError(teaching);
|
|
906
|
+
const Window = statusItemRecordType(return_info.pointer.child, teaching);
|
|
907
|
+
const info = @typeInfo(Window).@"struct";
|
|
908
|
+
if (info.fields.len != 18 or !@hasField(Window, "label") or !@hasField(Window, "canvasLabel") or
|
|
909
|
+
!@hasField(Window, "title") or !@hasField(Window, "width") or !@hasField(Window, "height") or
|
|
910
|
+
!@hasField(Window, "x") or !@hasField(Window, "y") or !@hasField(Window, "resizable") or
|
|
911
|
+
!@hasField(Window, "minWidth") or !@hasField(Window, "minHeight") or !@hasField(Window, "titlebar") or
|
|
912
|
+
!@hasField(Window, "transparent") or !@hasField(Window, "alwaysOnTop") or !@hasField(Window, "clickThrough") or
|
|
913
|
+
!@hasField(Window, "activateOnShow") or !@hasField(Window, "allowsFullscreen") or
|
|
914
|
+
!@hasField(Window, "closePolicy") or !@hasField(Window, "onCloseCommand")) @compileError(teaching);
|
|
915
|
+
if (@FieldType(Window, "label") != []const u8 or @FieldType(Window, "canvasLabel") != []const u8 or
|
|
916
|
+
@FieldType(Window, "title") != []const u8 or !statusItemNumericType(@FieldType(Window, "width")) or
|
|
917
|
+
!statusItemNumericType(@FieldType(Window, "height")) or !optionalNumericType(@FieldType(Window, "x")) or
|
|
918
|
+
!optionalNumericType(@FieldType(Window, "y")) or @FieldType(Window, "resizable") != bool or
|
|
919
|
+
!statusItemNumericType(@FieldType(Window, "minWidth")) or !statusItemNumericType(@FieldType(Window, "minHeight")) or
|
|
920
|
+
!statusItemEnumType(@FieldType(Window, "titlebar"), &.{ "standard", "hidden_inset", "hidden_inset_tall", "chromeless" }) or
|
|
921
|
+
@FieldType(Window, "transparent") != bool or @FieldType(Window, "alwaysOnTop") != bool or
|
|
922
|
+
@FieldType(Window, "clickThrough") != bool or @FieldType(Window, "activateOnShow") != bool or
|
|
923
|
+
@FieldType(Window, "allowsFullscreen") != bool or
|
|
924
|
+
!statusItemEnumType(@FieldType(Window, "closePolicy"), &.{ "quit", "hide" }) or
|
|
925
|
+
@FieldType(Window, "onCloseCommand") != []const u8) @compileError(teaching);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
fn optionalNumericType(comptime T: type) bool {
|
|
929
|
+
const info = @typeInfo(T);
|
|
930
|
+
return info == .optional and statusItemNumericType(info.optional.child);
|
|
931
|
+
}
|
|
932
|
+
|
|
640
933
|
fn statusItemNumericType(comptime T: type) bool {
|
|
641
934
|
return @typeInfo(T) == .int or @typeInfo(T) == .float;
|
|
642
935
|
}
|
|
@@ -1130,3 +1423,163 @@ pub fn TsUiApp(comptime core: type) type {
|
|
|
1130
1423
|
}
|
|
1131
1424
|
};
|
|
1132
1425
|
}
|
|
1426
|
+
|
|
1427
|
+
const StatusItemsAdapterTestCore = struct {
|
|
1428
|
+
const Tone = enum { normal, warning, critical };
|
|
1429
|
+
const Role = enum { command, info, header, hero, agent, context };
|
|
1430
|
+
const Modifiers = struct {
|
|
1431
|
+
primary: bool,
|
|
1432
|
+
command: bool,
|
|
1433
|
+
control: bool,
|
|
1434
|
+
option: bool,
|
|
1435
|
+
shift: bool,
|
|
1436
|
+
};
|
|
1437
|
+
const Presentation = struct {
|
|
1438
|
+
title: []const u8,
|
|
1439
|
+
width: f64,
|
|
1440
|
+
tone: Tone,
|
|
1441
|
+
iconOpacity: f64,
|
|
1442
|
+
monospaced: bool,
|
|
1443
|
+
};
|
|
1444
|
+
const Item = struct {
|
|
1445
|
+
id: f64,
|
|
1446
|
+
label: []const u8,
|
|
1447
|
+
command: []const u8,
|
|
1448
|
+
separator: bool,
|
|
1449
|
+
enabled: bool,
|
|
1450
|
+
detail: []const u8,
|
|
1451
|
+
role: Role,
|
|
1452
|
+
key: []const u8,
|
|
1453
|
+
modifiers: Modifiers,
|
|
1454
|
+
};
|
|
1455
|
+
const Descriptor = struct {
|
|
1456
|
+
id: f64,
|
|
1457
|
+
visible: bool,
|
|
1458
|
+
iconPath: []const u8,
|
|
1459
|
+
tooltip: []const u8,
|
|
1460
|
+
activationCommand: []const u8,
|
|
1461
|
+
alternateActivationCommand: []const u8,
|
|
1462
|
+
openCommand: []const u8,
|
|
1463
|
+
presentation: Presentation,
|
|
1464
|
+
items: []const Item,
|
|
1465
|
+
};
|
|
1466
|
+
|
|
1467
|
+
const rows = [_]Item{.{
|
|
1468
|
+
.id = 3,
|
|
1469
|
+
.label = "Refresh",
|
|
1470
|
+
.command = "spend.refresh",
|
|
1471
|
+
.separator = false,
|
|
1472
|
+
.enabled = true,
|
|
1473
|
+
.detail = "$7",
|
|
1474
|
+
.role = .command,
|
|
1475
|
+
.key = "r",
|
|
1476
|
+
.modifiers = .{ .primary = true, .command = false, .control = false, .option = false, .shift = false },
|
|
1477
|
+
}};
|
|
1478
|
+
const descriptors = [_]Descriptor{.{
|
|
1479
|
+
.id = 7,
|
|
1480
|
+
.visible = false,
|
|
1481
|
+
.iconPath = "spend.png",
|
|
1482
|
+
.tooltip = "Vercel spend",
|
|
1483
|
+
.activationCommand = "spend.open",
|
|
1484
|
+
.alternateActivationCommand = "",
|
|
1485
|
+
.openCommand = "spend.refresh",
|
|
1486
|
+
.presentation = .{ .title = "$7", .width = 52, .tone = .warning, .iconOpacity = 0.75, .monospaced = true },
|
|
1487
|
+
.items = &rows,
|
|
1488
|
+
}};
|
|
1489
|
+
|
|
1490
|
+
pub const Msg = union(enum) { noop };
|
|
1491
|
+
pub const Model = struct {
|
|
1492
|
+
pub fn statusItems(_: *const Model) []const Descriptor {
|
|
1493
|
+
return &descriptors;
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
};
|
|
1497
|
+
|
|
1498
|
+
test "TypeScript statusItems adapter validates and projects canonical descriptors" {
|
|
1499
|
+
const Adapter = TsUiApp(StatusItemsAdapterTestCore);
|
|
1500
|
+
comptime Adapter.validateStatusItemsHelper();
|
|
1501
|
+
var model = StatusItemsAdapterTestCore.Model{};
|
|
1502
|
+
var scratch = Adapter.App.StatusItemsScratch{};
|
|
1503
|
+
const descriptors = Adapter.statusItemsAdapter(&model, &scratch);
|
|
1504
|
+
try std.testing.expectEqual(@as(usize, 1), descriptors.len);
|
|
1505
|
+
try std.testing.expectEqual(@as(platform.StatusItemId, 7), descriptors[0].id);
|
|
1506
|
+
try std.testing.expect(!descriptors[0].visible);
|
|
1507
|
+
try std.testing.expectEqualStrings("$7", descriptors[0].state.presentation.title);
|
|
1508
|
+
try std.testing.expectEqualStrings("spend.png", descriptors[0].state.icon_path);
|
|
1509
|
+
try std.testing.expectEqual(@as(usize, 1), descriptors[0].state.items.len);
|
|
1510
|
+
try std.testing.expectEqual(@as(platform.TrayItemId, 3), descriptors[0].state.items[0].id);
|
|
1511
|
+
try std.testing.expect(descriptors[0].state.items[0].modifiers.primary);
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
const WindowsAdapterTestCore = struct {
|
|
1515
|
+
const Titlebar = enum { standard, hidden_inset, hidden_inset_tall, chromeless };
|
|
1516
|
+
const ClosePolicy = enum { quit, hide };
|
|
1517
|
+
const Descriptor = struct {
|
|
1518
|
+
label: []const u8,
|
|
1519
|
+
canvasLabel: []const u8,
|
|
1520
|
+
title: []const u8,
|
|
1521
|
+
width: f64,
|
|
1522
|
+
height: f64,
|
|
1523
|
+
x: ?f64,
|
|
1524
|
+
y: ?f64,
|
|
1525
|
+
resizable: bool,
|
|
1526
|
+
minWidth: f64,
|
|
1527
|
+
minHeight: f64,
|
|
1528
|
+
titlebar: Titlebar,
|
|
1529
|
+
transparent: bool,
|
|
1530
|
+
alwaysOnTop: bool,
|
|
1531
|
+
clickThrough: bool,
|
|
1532
|
+
activateOnShow: bool,
|
|
1533
|
+
allowsFullscreen: bool,
|
|
1534
|
+
closePolicy: ClosePolicy,
|
|
1535
|
+
onCloseCommand: []const u8,
|
|
1536
|
+
};
|
|
1537
|
+
|
|
1538
|
+
const descriptors = [_]Descriptor{
|
|
1539
|
+
.{ .label = "one", .canvasLabel = "one-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .chromeless, .transparent = true, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1540
|
+
.{ .label = "two", .canvasLabel = "two-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1541
|
+
.{ .label = "three", .canvasLabel = "three-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1542
|
+
.{ .label = "four", .canvasLabel = "four-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1543
|
+
.{ .label = "excess", .canvasLabel = "excess-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
pub const Msg = union(enum) { noop };
|
|
1547
|
+
pub const Model = struct {
|
|
1548
|
+
pub fn windows(_: *const Model) []const Descriptor {
|
|
1549
|
+
return &descriptors;
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
};
|
|
1553
|
+
|
|
1554
|
+
test "TypeScript windows adapter keeps the declared prefix on overflow and projects chromeless" {
|
|
1555
|
+
const Adapter = TsUiApp(WindowsAdapterTestCore);
|
|
1556
|
+
comptime Adapter.validateWindowsHelper();
|
|
1557
|
+
var model = WindowsAdapterTestCore.Model{};
|
|
1558
|
+
var scratch = Adapter.App.WindowsScratch{};
|
|
1559
|
+
const descriptors = Adapter.windowsAdapter(&model, &scratch);
|
|
1560
|
+
try std.testing.expectEqual(Adapter.App.max_ui_windows, descriptors.len);
|
|
1561
|
+
try std.testing.expectEqualStrings("one", descriptors[0].label);
|
|
1562
|
+
try std.testing.expectEqual(@import("app_manifest").WindowTitlebarStyle.chromeless, descriptors[0].titlebar);
|
|
1563
|
+
try std.testing.expect(descriptors[0].transparent);
|
|
1564
|
+
try std.testing.expectEqualStrings("four", descriptors[3].label);
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
const WindowCloseCommandTestCore = struct {
|
|
1568
|
+
pub const Msg = union(enum) { closed, noop };
|
|
1569
|
+
pub const Model = struct {};
|
|
1570
|
+
};
|
|
1571
|
+
|
|
1572
|
+
fn mappedWindowCloseCommand(name: []const u8) ?WindowCloseCommandTestCore.Msg {
|
|
1573
|
+
return if (std.mem.eql(u8, name, "settings.closed")) .closed else null;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
test "TypeScript window close commands refuse missing and unmapped command callbacks" {
|
|
1577
|
+
const Adapter = TsUiApp(WindowCloseCommandTestCore);
|
|
1578
|
+
Adapter.command_store = null;
|
|
1579
|
+
try std.testing.expectError(error.MissingCommandMapper, Adapter.windowCloseMsg("settings.closed"));
|
|
1580
|
+
try std.testing.expect((try Adapter.windowCloseMsg("")) == null);
|
|
1581
|
+
|
|
1582
|
+
Adapter.command_store = mappedWindowCloseCommand;
|
|
1583
|
+
try std.testing.expectError(error.UnmappedCommand, Adapter.windowCloseMsg("settings.missing"));
|
|
1584
|
+
try std.testing.expectEqual(WindowCloseCommandTestCore.Msg.closed, (try Adapter.windowCloseMsg("settings.closed")).?);
|
|
1585
|
+
}
|