@native-sdk/cli 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +905 -61
- package/build.zig +674 -373
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +6 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +455 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +214 -2
- package/packages/core/sdk/core.ts +715 -42
- package/packages/core/sdk/events.d.ts +50 -0
- package/packages/core/sdk/events.ts +75 -0
- package/packages/core/src/checker.ts +528 -15
- package/packages/core/src/cli.ts +143 -3
- package/packages/core/src/contract.ts +26 -5
- package/packages/core/src/devhost.ts +1849 -18
- package/packages/core/src/devhost_journal.mjs +181 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +84 -18
- package/packages/core/src/frontend.ts +204 -34
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +3 -2
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +55 -8
- package/skill-data/ts-core/SKILL.md +92 -40
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +603 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +104 -4
- package/src/app_runner/ts_core_main.zig +268 -4
- package/src/automation/snapshot.zig +23 -5
- package/src/embed/app_exports.zig +11 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +115 -1
- package/src/embed/root.zig +7 -0
- package/src/embed/tests.zig +213 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +121 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +1 -1
- package/src/platform/linux/gtk_host.c +89 -17
- package/src/platform/linux/gtk_host.h +3 -0
- package/src/platform/linux/root.zig +41 -18
- package/src/platform/macos/appkit_host.h +26 -3
- package/src/platform/macos/appkit_host.m +1051 -129
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +270 -36
- package/src/platform/macos/root.zig +312 -34
- package/src/platform/null_platform.zig +281 -19
- package/src/platform/null_platform_tests.zig +74 -0
- package/src/platform/root.zig +16 -0
- package/src/platform/types.zig +279 -15
- package/src/platform/windows/root.zig +243 -21
- package/src/platform/windows/webview2_host.cpp +464 -46
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +34 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/primitives/canvas/code_tests.zig +9 -9
- package/src/primitives/canvas/events.zig +12 -11
- package/src/primitives/canvas/frame.zig +44 -9
- package/src/primitives/canvas/icons/mic.svg +1 -0
- package/src/primitives/canvas/icons.zig +2 -0
- package/src/primitives/canvas/root.zig +8 -0
- package/src/primitives/canvas/text_span_tests.zig +39 -0
- package/src/primitives/canvas/ui.zig +23 -4
- package/src/primitives/canvas/ui_markup.zig +15 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
- package/src/primitives/canvas/ui_markup_tests.zig +5 -0
- package/src/primitives/canvas/ui_markup_view.zig +9 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
- package/src/primitives/canvas/ui_schema.zig +19 -10
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +18 -4
- package/src/primitives/canvas/widget_invalidation.zig +9 -2
- package/src/primitives/canvas/widget_render.zig +296 -114
- package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
- package/src/primitives/canvas/widget_text_input.zig +10 -10
- package/src/primitives/canvas/widget_tree.zig +1 -1
- package/src/primitives/canvas/widgets.zig +29 -5
- package/src/root.zig +56 -0
- package/src/runtime/api.zig +11 -0
- package/src/runtime/automation_snapshot.zig +4 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/bridge_permission_tests.zig +23 -2
- package/src/runtime/bridge_responses.zig +3 -1
- package/src/runtime/canvas_frame.zig +31 -13
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
- package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
- package/src/runtime/canvas_widget_events.zig +69 -24
- package/src/runtime/canvas_widget_runtime.zig +101 -6
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
- package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
- package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
- package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
- package/src/runtime/canvas_widget_state.zig +6 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +133 -1
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +2568 -75
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/flow.zig +14 -1
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +42 -0
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +52 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +1 -1
- package/src/runtime/session_journal.zig +102 -0
- package/src/runtime/session_record.zig +177 -0
- package/src/runtime/session_replay.zig +109 -4
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +6 -0
- package/src/runtime/system_services.zig +49 -10
- package/src/runtime/tests.zig +5 -0
- package/src/runtime/ts_core_host.zig +1189 -118
- package/src/runtime/ts_core_host_tests.zig +638 -11
- package/src/runtime/ts_ui_app.zig +537 -1
- package/src/runtime/ui_app.zig +160 -19
- package/src/runtime/ui_app_tests.zig +203 -5
- package/src/runtime/validation.zig +22 -0
- package/src/runtime/view.zig +11 -0
- package/src/runtime/view_widget_scroll.zig +56 -5
- package/src/runtime/view_widget_text.zig +24 -5
- package/src/runtime/view_widget_tree.zig +1 -1
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +1248 -2
- package/src/tooling/package.zig +953 -6
- package/src/tooling/raw_manifest.zig +65 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +216 -4
- package/src/tooling/ts_core.zig +283 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +414 -23
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
package/src/runtime/ui_app.zig
CHANGED
|
@@ -32,6 +32,7 @@ const builtin = @import("builtin");
|
|
|
32
32
|
const geometry = @import("geometry");
|
|
33
33
|
const canvas = @import("canvas");
|
|
34
34
|
const app_manifest = @import("app_manifest");
|
|
35
|
+
const security = @import("../security/root.zig");
|
|
35
36
|
const platform = @import("../platform/root.zig");
|
|
36
37
|
const core = @import("core.zig");
|
|
37
38
|
const canvas_frame = @import("canvas_frame.zig");
|
|
@@ -250,15 +251,31 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
250
251
|
/// Menu items: `label` is the visible title, `command` the
|
|
251
252
|
/// name handed to `on_command`, `id` a unique non-zero id.
|
|
252
253
|
items: []const platform.TrayMenuItem = &.{},
|
|
254
|
+
/// Optional lifecycle commands: ordinary click (then open),
|
|
255
|
+
/// Option-click (without opening), and every menu-open. All
|
|
256
|
+
/// enter the same `on_command` route as menu rows.
|
|
257
|
+
activation_command: []const u8 = "",
|
|
258
|
+
alternate_activation_command: []const u8 = "",
|
|
259
|
+
open_command: []const u8 = "",
|
|
253
260
|
};
|
|
254
261
|
|
|
255
262
|
/// Model-derived status-item state returned by
|
|
256
|
-
/// `Options.status_item_fn`:
|
|
263
|
+
/// `Options.status_item_fn`: install-time shell fields plus the
|
|
264
|
+
/// live button presentation and menu.
|
|
257
265
|
/// Slices may point at the scratch the fn received, the model, or
|
|
258
266
|
/// static strings — they only need to outlive the apply (the
|
|
259
267
|
/// runtime and platform copy what they keep).
|
|
260
268
|
pub const StatusItemState = struct {
|
|
261
269
|
title: []const u8 = "",
|
|
270
|
+
presentation: platform.TrayPresentation = .{},
|
|
271
|
+
/// Install-time shell fields. A TypeScript core has no Zig
|
|
272
|
+
/// options block, so its statusItem record supplies these on
|
|
273
|
+
/// the first frame. Empty fields inherit StatusItemOptions.
|
|
274
|
+
icon_path: []const u8 = "",
|
|
275
|
+
tooltip: []const u8 = "",
|
|
276
|
+
activation_command: []const u8 = "",
|
|
277
|
+
alternate_activation_command: []const u8 = "",
|
|
278
|
+
open_command: []const u8 = "",
|
|
262
279
|
items: []const platform.TrayMenuItem = &.{},
|
|
263
280
|
};
|
|
264
281
|
|
|
@@ -269,6 +286,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
269
286
|
/// apply.
|
|
270
287
|
pub const StatusItemScratch = struct {
|
|
271
288
|
title_buffer: [platform.max_tray_title_bytes]u8 = undefined,
|
|
289
|
+
arena_buffer: [2048]u8 = undefined,
|
|
272
290
|
items: [platform.max_tray_items]platform.TrayMenuItem = undefined,
|
|
273
291
|
};
|
|
274
292
|
|
|
@@ -329,6 +347,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
329
347
|
always_on_top: bool = false,
|
|
330
348
|
click_through: bool = false,
|
|
331
349
|
activate_on_show: bool = true,
|
|
350
|
+
/// Whether macOS offers native fullscreen for this window.
|
|
351
|
+
/// False leaves the window resizable but disables the green
|
|
352
|
+
/// fullscreen affordance and fullscreen command.
|
|
353
|
+
allows_fullscreen: bool = true,
|
|
332
354
|
/// Msg dispatched when the USER closes the window (never for
|
|
333
355
|
/// a reconcile close the model itself initiated). The
|
|
334
356
|
/// dismissal precedent: the window is already gone as an
|
|
@@ -418,6 +440,14 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
418
440
|
/// The scaffold wires this to app.zon's `theme` field
|
|
419
441
|
/// through `app_runner.manifestThemePack()`.
|
|
420
442
|
theme: canvas.ThemePack = .house,
|
|
443
|
+
/// Model-derived built-in theme pack. When set, this is
|
|
444
|
+
/// consulted on every rebuild instead of the static `theme`
|
|
445
|
+
/// field, while the runtime continues to own the live system
|
|
446
|
+
/// appearance axes (scheme, contrast, reduced motion), the
|
|
447
|
+
/// surface scale, and `theme_accent`. Explicit `tokens` or
|
|
448
|
+
/// `tokens_fn` still take precedence because those paths own
|
|
449
|
+
/// the complete token register.
|
|
450
|
+
theme_fn: ?*const fn (model: *const ModelT) canvas.ThemePack = null,
|
|
421
451
|
/// The app's ONE-accent brand statement over the stock
|
|
422
452
|
/// tokens: when set (and the app claims neither `tokens`
|
|
423
453
|
/// nor `tokens_fn` — apps that own their tokens own their
|
|
@@ -1375,15 +1405,35 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1375
1405
|
fn bindEffectsChannel(self: *Self, runtime: *Runtime) void {
|
|
1376
1406
|
self.effects.bindServices(&runtime.options.platform.services);
|
|
1377
1407
|
self.effects.bindEnviron(runtime.options.environ);
|
|
1408
|
+
if (runtime.options.record_store) |binding| {
|
|
1409
|
+
self.effects.bindRecordStore(binding);
|
|
1410
|
+
}
|
|
1411
|
+
if (runtime.options.relational_store) |binding| {
|
|
1412
|
+
self.effects.bindRelationalStore(binding);
|
|
1413
|
+
}
|
|
1414
|
+
self.effects.bindCredentialsStore(.{
|
|
1415
|
+
.services = &runtime.options.platform.services,
|
|
1416
|
+
.service = runtime.options.platform.app_info.bundle_id,
|
|
1417
|
+
.permitted = runtime.options.credentials_enabled and
|
|
1418
|
+
security.hasPermission(runtime.options.security.permissions, security.permission_credentials),
|
|
1419
|
+
});
|
|
1378
1420
|
self.effects.bindImages(runtime.canvasImageRegistryBinding());
|
|
1379
1421
|
self.effects.bindMediaSurfaces(runtime.mediaSurfaceBinding());
|
|
1380
1422
|
self.effects.bindWindowActions(.{
|
|
1381
1423
|
.context = runtime,
|
|
1382
1424
|
.close_fn = effectsCloseWindowByLabel,
|
|
1383
1425
|
.minimize_fn = effectsMinimizeWindowByLabel,
|
|
1426
|
+
.hide_fn = effectsHideWindowByLabel,
|
|
1384
1427
|
.show_fn = effectsShowWindowByLabel,
|
|
1428
|
+
.dock_presence_fn = effectsSetDockPresence,
|
|
1385
1429
|
.quit_fn = effectsQuitApp,
|
|
1386
1430
|
});
|
|
1431
|
+
self.effects.bindSystemServices(.{
|
|
1432
|
+
.context = runtime,
|
|
1433
|
+
.open_external_url_fn = effectsOpenExternalUrl,
|
|
1434
|
+
.reveal_path_fn = effectsRevealPath,
|
|
1435
|
+
.format_local_time_fn = effectsFormatLocalTime,
|
|
1436
|
+
});
|
|
1387
1437
|
if (runtime.options.session_recorder) |recorder| {
|
|
1388
1438
|
self.effects.bindJournal(recorder.effectJournal());
|
|
1389
1439
|
}
|
|
@@ -1428,13 +1478,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1428
1478
|
switch (control) {
|
|
1429
1479
|
.arm => self.effects.armReplay(),
|
|
1430
1480
|
.feed => |record| switch (record.kind) {
|
|
1431
|
-
.line => try self.effects.
|
|
1481
|
+
.line => try self.effects.feedLineWithMetadata(record.key, record.payload, record.truncated, record.dropped),
|
|
1432
1482
|
.exit => {
|
|
1433
1483
|
if (record.payload.len > 0) try self.effects.feedOutput(record.key, record.payload);
|
|
1434
1484
|
if (record.stderr_tail.len > 0) try self.effects.feedStderr(record.key, record.stderr_tail);
|
|
1435
1485
|
try self.effects.feedExitReason(record.key, record.code, record.exit_reason);
|
|
1436
1486
|
},
|
|
1437
|
-
.response => try self.effects.
|
|
1487
|
+
.response => try self.effects.feedResponseOutcomeWithMetadata(
|
|
1488
|
+
record.key,
|
|
1489
|
+
record.fetch_outcome,
|
|
1490
|
+
record.status,
|
|
1491
|
+
record.payload,
|
|
1492
|
+
record.truncated,
|
|
1493
|
+
record.dropped,
|
|
1494
|
+
),
|
|
1438
1495
|
.file => try self.effects.feedFileResult(record.key, record.file_outcome, record.payload),
|
|
1439
1496
|
.clipboard => try self.effects.feedClipboardResult(record.key, record.clipboard_outcome, record.payload),
|
|
1440
1497
|
// `.host` records ride the route in `code` (0 ok / 1
|
|
@@ -1442,12 +1499,26 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1442
1499
|
// `.rejected` and regenerate from the same
|
|
1443
1500
|
// deterministic validation, like `.timer` records.
|
|
1444
1501
|
.host => try self.effects.feedHostResult(record.key, record.code == 0, record.payload),
|
|
1502
|
+
.credentials => try self.effects.feedCredentialsResult(
|
|
1503
|
+
record.key,
|
|
1504
|
+
record.credentials_operation,
|
|
1505
|
+
record.credentials_outcome,
|
|
1506
|
+
record.credentials_secret_len,
|
|
1507
|
+
record.credentials_digest,
|
|
1508
|
+
),
|
|
1509
|
+
.db => try self.effects.feedDbResult(
|
|
1510
|
+
record.key,
|
|
1511
|
+
runtime_effects.dbKindFromJournalCode(record.code) orelse return error.ReplayDamagedRecord,
|
|
1512
|
+
runtime_effects.dbOutcomeFromJournalCode(record.code) orelse return error.ReplayDamagedRecord,
|
|
1513
|
+
record.payload,
|
|
1514
|
+
),
|
|
1445
1515
|
.clock => try self.effects.pushReplayClock(record.clock_wall_ms),
|
|
1446
1516
|
// `.env` records carry the arm name in `stderr_tail`
|
|
1447
1517
|
// and the value in `payload`; the TS adapter's
|
|
1448
1518
|
// envMsgs dispatch consumes the queue on the
|
|
1449
1519
|
// replayed installing frame (zero env reads).
|
|
1450
1520
|
.env => try self.effects.pushReplayEnv(record.stderr_tail, record.payload),
|
|
1521
|
+
.persist => try self.effects.pushReplayPersist(record.persist_outcome, record.payload),
|
|
1451
1522
|
// `.image` records deliver the RECORDED terminal
|
|
1452
1523
|
// verbatim (byte-identical Msg stream on any host)
|
|
1453
1524
|
// and re-register the journaled source bytes —
|
|
@@ -1604,6 +1675,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1604
1675
|
} else {
|
|
1605
1676
|
self.options.update.?(&self.model, msg);
|
|
1606
1677
|
}
|
|
1678
|
+
// One update call is one complete command batch. Re-run live
|
|
1679
|
+
// relational reads only after the batch has walked so several
|
|
1680
|
+
// writes touching the same table still coalesce into one result.
|
|
1681
|
+
self.effects.flushDbSubscriptions();
|
|
1607
1682
|
}
|
|
1608
1683
|
|
|
1609
1684
|
/// Drain the effect completion queue on the loop thread: every
|
|
@@ -1732,7 +1807,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1732
1807
|
},
|
|
1733
1808
|
.contrast = if (self.system_appearance.high_contrast) .high else .standard,
|
|
1734
1809
|
.reduce_motion = self.system_appearance.reduce_motion,
|
|
1735
|
-
.pack = self.options.theme,
|
|
1810
|
+
.pack = if (self.options.theme_fn) |theme_fn| theme_fn(&self.model) else self.options.theme,
|
|
1736
1811
|
});
|
|
1737
1812
|
if (self.options.theme_accent) |accent| {
|
|
1738
1813
|
// The manifest accent layers over the resolved pack —
|
|
@@ -2663,6 +2738,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2663
2738
|
.always_on_top = descriptor.always_on_top,
|
|
2664
2739
|
.click_through = descriptor.click_through,
|
|
2665
2740
|
.activate_on_show = descriptor.activate_on_show,
|
|
2741
|
+
.allows_fullscreen = descriptor.allows_fullscreen,
|
|
2666
2742
|
.min_width = descriptor.min_width,
|
|
2667
2743
|
.min_height = descriptor.min_height,
|
|
2668
2744
|
// Deterministic reopen: the descriptor is the geometry
|
|
@@ -3599,31 +3675,46 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
3599
3675
|
/// Selecting one of its items dispatches the item's `command`
|
|
3600
3676
|
/// through the ordinary `on_command` path (source `.tray`).
|
|
3601
3677
|
/// Unsupported platforms degrade to a logged warning. With a
|
|
3602
|
-
/// `status_item_fn`, the model's derived
|
|
3678
|
+
/// `status_item_fn`, the model's derived presentation/items win from
|
|
3603
3679
|
/// the very first frame (the static options keep icon+tooltip).
|
|
3604
3680
|
fn installStatusItem(self: *Self, runtime: *Runtime) void {
|
|
3605
3681
|
if (self.status_item_installed) return;
|
|
3606
3682
|
if (self.options.status_item == null and self.options.status_item_fn == null) return;
|
|
3607
3683
|
self.status_item_installed = true;
|
|
3608
3684
|
const static = self.options.status_item orelse StatusItemOptions{};
|
|
3609
|
-
var title = static.title;
|
|
3685
|
+
var presentation = platform.TrayPresentation{ .title = static.title };
|
|
3686
|
+
var icon_path = static.icon_path;
|
|
3687
|
+
var tooltip = static.tooltip;
|
|
3688
|
+
var activation_command = static.activation_command;
|
|
3689
|
+
var alternate_activation_command = static.alternate_activation_command;
|
|
3690
|
+
var open_command = static.open_command;
|
|
3610
3691
|
var items = static.items;
|
|
3611
3692
|
if (self.options.status_item_fn) |state_fn| {
|
|
3612
3693
|
const state = state_fn(&self.model, &self.tray_scratch);
|
|
3613
|
-
|
|
3694
|
+
presentation = state.presentation;
|
|
3695
|
+
if (presentation.title.len == 0) presentation.title = state.title;
|
|
3696
|
+
if (state.icon_path.len > 0) icon_path = state.icon_path;
|
|
3697
|
+
if (state.tooltip.len > 0) tooltip = state.tooltip;
|
|
3698
|
+
if (state.activation_command.len > 0) activation_command = state.activation_command;
|
|
3699
|
+
if (state.alternate_activation_command.len > 0) alternate_activation_command = state.alternate_activation_command;
|
|
3700
|
+
if (state.open_command.len > 0) open_command = state.open_command;
|
|
3614
3701
|
items = state.items;
|
|
3615
3702
|
}
|
|
3616
3703
|
runtime.createTray(.{
|
|
3617
|
-
.title = title,
|
|
3618
|
-
.icon_path =
|
|
3619
|
-
.tooltip =
|
|
3704
|
+
.title = presentation.title,
|
|
3705
|
+
.icon_path = icon_path,
|
|
3706
|
+
.tooltip = tooltip,
|
|
3620
3707
|
.items = items,
|
|
3708
|
+
.presentation = presentation,
|
|
3709
|
+
.activation_command = activation_command,
|
|
3710
|
+
.alternate_activation_command = alternate_activation_command,
|
|
3711
|
+
.open_command = open_command,
|
|
3621
3712
|
}) catch |err| {
|
|
3622
3713
|
ui_app_log.warn("status item install failed: {s}", .{@errorName(err)});
|
|
3623
3714
|
return;
|
|
3624
3715
|
};
|
|
3625
3716
|
self.tray_created = true;
|
|
3626
|
-
self.tray_title_hash =
|
|
3717
|
+
self.tray_title_hash = hashTrayPresentation(presentation);
|
|
3627
3718
|
self.tray_menu_hash = hashTrayMenu(items);
|
|
3628
3719
|
}
|
|
3629
3720
|
|
|
@@ -3635,17 +3726,19 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
3635
3726
|
const state_fn = self.options.status_item_fn orelse return;
|
|
3636
3727
|
if (!self.tray_created) return;
|
|
3637
3728
|
const state = state_fn(&self.model, &self.tray_scratch);
|
|
3729
|
+
var presentation = state.presentation;
|
|
3730
|
+
if (presentation.title.len == 0) presentation.title = state.title;
|
|
3638
3731
|
|
|
3639
|
-
const title_hash =
|
|
3732
|
+
const title_hash = hashTrayPresentation(presentation);
|
|
3640
3733
|
if (title_hash != self.tray_title_hash) {
|
|
3641
3734
|
self.tray_title_hash = title_hash;
|
|
3642
3735
|
if (!self.tray_title_unsupported) {
|
|
3643
|
-
runtime.
|
|
3736
|
+
runtime.updateTrayPresentation(presentation) catch |err| {
|
|
3644
3737
|
if (err == error.UnsupportedService) {
|
|
3645
3738
|
self.tray_title_unsupported = true;
|
|
3646
|
-
ui_app_log.warn("status item
|
|
3739
|
+
ui_app_log.warn("status item presentation updates unsupported on this platform: the menu keeps updating", .{});
|
|
3647
3740
|
} else {
|
|
3648
|
-
ui_app_log.warn("status item
|
|
3741
|
+
ui_app_log.warn("status item presentation update failed: {s}", .{@errorName(err)});
|
|
3649
3742
|
}
|
|
3650
3743
|
};
|
|
3651
3744
|
}
|
|
@@ -4180,6 +4273,10 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4180
4273
|
self.init_fx_ran = true;
|
|
4181
4274
|
self.bindEffectsChannel(runtime);
|
|
4182
4275
|
init_fx(&self.model, &self.effects);
|
|
4276
|
+
// init_fx has the same batch contract as update_fx;
|
|
4277
|
+
// subscriptions dirtied by boot transactions must be
|
|
4278
|
+
// current before their staged results are drained.
|
|
4279
|
+
self.effects.flushDbSubscriptions();
|
|
4183
4280
|
self.publishAudioState(runtime);
|
|
4184
4281
|
// Launch lap (env-gated): boot-effect cost (asset
|
|
4185
4282
|
// decode/registration) splits out of the
|
|
@@ -4449,9 +4546,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4449
4546
|
/// Change-detection hashes for the model-derived tray state:
|
|
4450
4547
|
/// field lengths are folded in so adjacent slices can
|
|
4451
4548
|
/// never alias across boundaries.
|
|
4452
|
-
fn
|
|
4453
|
-
var hasher = std.hash.Wyhash.init(
|
|
4454
|
-
hasher.update(title);
|
|
4549
|
+
fn hashTrayPresentation(presentation: platform.TrayPresentation) u64 {
|
|
4550
|
+
var hasher = std.hash.Wyhash.init(0x7261795f70726573); // "ray_pres"
|
|
4551
|
+
hasher.update(presentation.title);
|
|
4552
|
+
hasher.update(std.mem.asBytes(&presentation.width));
|
|
4553
|
+
hasher.update(std.mem.asBytes(&presentation.icon_opacity));
|
|
4554
|
+
hasher.update(&.{ @intFromEnum(presentation.tone), @intFromBool(presentation.monospaced) });
|
|
4455
4555
|
return hasher.final();
|
|
4456
4556
|
}
|
|
4457
4557
|
|
|
@@ -4464,7 +4564,20 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
4464
4564
|
hasher.update(item.label);
|
|
4465
4565
|
hasher.update(std.mem.asBytes(&item.command.len));
|
|
4466
4566
|
hasher.update(item.command);
|
|
4467
|
-
hasher.update(
|
|
4567
|
+
hasher.update(std.mem.asBytes(&item.detail.len));
|
|
4568
|
+
hasher.update(item.detail);
|
|
4569
|
+
hasher.update(std.mem.asBytes(&item.key.len));
|
|
4570
|
+
hasher.update(item.key);
|
|
4571
|
+
hasher.update(&.{
|
|
4572
|
+
@intFromBool(item.separator),
|
|
4573
|
+
@intFromBool(item.enabled),
|
|
4574
|
+
@intFromEnum(item.role),
|
|
4575
|
+
@intFromBool(item.modifiers.primary),
|
|
4576
|
+
@intFromBool(item.modifiers.command),
|
|
4577
|
+
@intFromBool(item.modifiers.control),
|
|
4578
|
+
@intFromBool(item.modifiers.option),
|
|
4579
|
+
@intFromBool(item.modifiers.shift),
|
|
4580
|
+
});
|
|
4468
4581
|
}
|
|
4469
4582
|
return hasher.final();
|
|
4470
4583
|
}
|
|
@@ -6076,6 +6189,13 @@ fn effectsMinimizeWindowByLabel(context: *anyopaque, window_label: []const u8) b
|
|
|
6076
6189
|
return true;
|
|
6077
6190
|
}
|
|
6078
6191
|
|
|
6192
|
+
fn effectsHideWindowByLabel(context: *anyopaque, window_label: []const u8) bool {
|
|
6193
|
+
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6194
|
+
const window_id = effectsWindowIdByLabel(runtime, window_label) orelse return false;
|
|
6195
|
+
runtime.hideWindow(window_id) catch return false;
|
|
6196
|
+
return true;
|
|
6197
|
+
}
|
|
6198
|
+
|
|
6079
6199
|
fn effectsShowWindowByLabel(context: *anyopaque, window_label: []const u8) bool {
|
|
6080
6200
|
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6081
6201
|
// A policy-hidden window keeps `open` true, so the same live-window
|
|
@@ -6085,12 +6205,33 @@ fn effectsShowWindowByLabel(context: *anyopaque, window_label: []const u8) bool
|
|
|
6085
6205
|
return true;
|
|
6086
6206
|
}
|
|
6087
6207
|
|
|
6208
|
+
fn effectsSetDockPresence(context: *anyopaque, visible: bool) bool {
|
|
6209
|
+
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6210
|
+
runtime.options.platform.services.setDockPresence(visible) catch return false;
|
|
6211
|
+
return true;
|
|
6212
|
+
}
|
|
6213
|
+
|
|
6088
6214
|
fn effectsQuitApp(context: *anyopaque) bool {
|
|
6089
6215
|
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6090
6216
|
runtime.quitApp() catch return false;
|
|
6091
6217
|
return true;
|
|
6092
6218
|
}
|
|
6093
6219
|
|
|
6220
|
+
fn effectsOpenExternalUrl(context: *anyopaque, url: []const u8) anyerror!void {
|
|
6221
|
+
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6222
|
+
return runtime.openExternalUrl(url);
|
|
6223
|
+
}
|
|
6224
|
+
|
|
6225
|
+
fn effectsRevealPath(context: *anyopaque, path: []const u8) anyerror!void {
|
|
6226
|
+
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6227
|
+
return runtime.revealPath(path);
|
|
6228
|
+
}
|
|
6229
|
+
|
|
6230
|
+
fn effectsFormatLocalTime(context: *anyopaque, timestamp_ms: i64, style: platform.LocalTimeStyle, buffer: []u8) anyerror![]const u8 {
|
|
6231
|
+
const runtime: *Runtime = @ptrCast(@alignCast(context));
|
|
6232
|
+
return runtime.formatLocalTime(timestamp_ms, style, buffer);
|
|
6233
|
+
}
|
|
6234
|
+
|
|
6094
6235
|
/// The build storage pinned under a presented native context menu:
|
|
6095
6236
|
/// which canvas's arena pair and which generation (index) of that pair
|
|
6096
6237
|
/// built the presented tree. The canvas is named by STABLE window
|
|
@@ -43,6 +43,10 @@ fn counterCommand(name: []const u8) ?CounterMsg {
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
fn counterThemePack(model: *const CounterModel) canvas.ThemePack {
|
|
47
|
+
return if (model.count == 0) .house else .geist;
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
const counter_views = [_]app_manifest.ShellView{
|
|
47
51
|
.{ .label = canvas_label, .kind = .gpu_surface, .fill = true, .gpu_backend = .metal },
|
|
48
52
|
};
|
|
@@ -105,6 +109,156 @@ fn retainedTextExists(runtime: *core.Runtime, text: []const u8) !bool {
|
|
|
105
109
|
return false;
|
|
106
110
|
}
|
|
107
111
|
|
|
112
|
+
const RelationalUiModel = struct {
|
|
113
|
+
pages: u32 = 0,
|
|
114
|
+
rows: u32 = 0,
|
|
115
|
+
done: u32 = 0,
|
|
116
|
+
execs: u32 = 0,
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const RelationalUiMsg = union(enum) {
|
|
120
|
+
add,
|
|
121
|
+
db: effects_mod.EffectDbResult,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const RelationalUiApp = ui_app_model.UiApp(RelationalUiModel, RelationalUiMsg);
|
|
125
|
+
const RelationalUiEffects = RelationalUiApp.Effects;
|
|
126
|
+
|
|
127
|
+
fn relationalUiInit(_: *RelationalUiModel, fx: *RelationalUiEffects) void {
|
|
128
|
+
fx.dbExec(.{
|
|
129
|
+
.key = 101,
|
|
130
|
+
.statements = &.{.{ .sql = "CREATE TABLE note(id INTEGER PRIMARY KEY) STRICT;" }},
|
|
131
|
+
.on_result = RelationalUiEffects.dbMsg(.db),
|
|
132
|
+
});
|
|
133
|
+
fx.dbSubscribe(.{
|
|
134
|
+
.key = 102,
|
|
135
|
+
.sql = "SELECT id FROM note ORDER BY id;",
|
|
136
|
+
.tables = &.{"note"},
|
|
137
|
+
.on_result = RelationalUiEffects.dbMsg(.db),
|
|
138
|
+
});
|
|
139
|
+
fx.dbExec(.{
|
|
140
|
+
.key = 103,
|
|
141
|
+
.statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(1);" }},
|
|
142
|
+
.on_result = RelationalUiEffects.dbMsg(.db),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn relationalUiUpdate(model: *RelationalUiModel, msg: RelationalUiMsg, fx: *RelationalUiEffects) void {
|
|
147
|
+
switch (msg) {
|
|
148
|
+
.add => fx.dbExec(.{
|
|
149
|
+
.key = 104,
|
|
150
|
+
.statements = &.{.{ .sql = "INSERT INTO note(id) VALUES(2);" }},
|
|
151
|
+
.on_result = RelationalUiEffects.dbMsg(.db),
|
|
152
|
+
}),
|
|
153
|
+
.db => |result| {
|
|
154
|
+
if (result.outcome != .ok) return;
|
|
155
|
+
switch (result.kind) {
|
|
156
|
+
.page => {
|
|
157
|
+
model.pages += 1;
|
|
158
|
+
model.rows += std.mem.readInt(u32, result.bytes[4..8], .little);
|
|
159
|
+
},
|
|
160
|
+
.done => model.done += 1,
|
|
161
|
+
.exec => model.execs += 1,
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fn relationalUiView(ui: *RelationalUiApp.Ui, model: *const RelationalUiModel) RelationalUiApp.Ui.Node {
|
|
168
|
+
return ui.text(.{}, ui.fmt("{d} relational pages", .{model.pages}));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
test "record-store test harness binds one hermetic in-memory database" {
|
|
172
|
+
const harness = try core.TestHarness().createWithRecordStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
173
|
+
defer harness.destroy(std.testing.allocator);
|
|
174
|
+
try std.testing.expect(harness.record_store != null);
|
|
175
|
+
try std.testing.expect(harness.runtime.options.record_store != null);
|
|
176
|
+
harness.null_platform.gpu_surfaces = true;
|
|
177
|
+
|
|
178
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
179
|
+
defer std.testing.allocator.destroy(app_state);
|
|
180
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, counterOptions());
|
|
181
|
+
defer app_state.deinit();
|
|
182
|
+
const app = app_state.app();
|
|
183
|
+
try harness.start(app);
|
|
184
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
185
|
+
.label = canvas_label,
|
|
186
|
+
.size = geometry.SizeF.init(400, 300),
|
|
187
|
+
.scale_factor = 1,
|
|
188
|
+
.frame_index = 1,
|
|
189
|
+
.timestamp_ns = 1_000_000,
|
|
190
|
+
.nonblank = true,
|
|
191
|
+
} });
|
|
192
|
+
try app_state.dispatch(&harness.runtime, 1, .increment);
|
|
193
|
+
try std.testing.expect(app_state.effects.record_store_binding != null);
|
|
194
|
+
try harness.stop(app);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
test "relational test harness binds one hermetic in-memory database" {
|
|
198
|
+
const harness = try core.TestHarness().createWithRelationalStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
199
|
+
defer harness.destroy(std.testing.allocator);
|
|
200
|
+
try std.testing.expect(harness.relational_store != null);
|
|
201
|
+
try std.testing.expect(harness.runtime.options.relational_store != null);
|
|
202
|
+
harness.null_platform.gpu_surfaces = true;
|
|
203
|
+
|
|
204
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
205
|
+
defer std.testing.allocator.destroy(app_state);
|
|
206
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, counterOptions());
|
|
207
|
+
defer app_state.deinit();
|
|
208
|
+
const app = app_state.app();
|
|
209
|
+
try harness.start(app);
|
|
210
|
+
try app_state.dispatch(&harness.runtime, 1, .increment);
|
|
211
|
+
try std.testing.expect(app_state.effects.relational_store_binding != null);
|
|
212
|
+
try harness.stop(app);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
test "ui app flushes relational live queries after init and update command batches" {
|
|
216
|
+
const harness = try core.TestHarness().createWithRelationalStore(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
217
|
+
defer harness.destroy(std.testing.allocator);
|
|
218
|
+
harness.null_platform.gpu_surfaces = true;
|
|
219
|
+
|
|
220
|
+
const app_state = try std.testing.allocator.create(RelationalUiApp);
|
|
221
|
+
defer std.testing.allocator.destroy(app_state);
|
|
222
|
+
app_state.* = RelationalUiApp.init(std.heap.page_allocator, .{}, .{
|
|
223
|
+
.name = "ui-app-relational-live",
|
|
224
|
+
.scene = counter_scene,
|
|
225
|
+
.canvas_label = canvas_label,
|
|
226
|
+
.update_fx = relationalUiUpdate,
|
|
227
|
+
.init_fx = relationalUiInit,
|
|
228
|
+
.view = relationalUiView,
|
|
229
|
+
});
|
|
230
|
+
defer app_state.deinit();
|
|
231
|
+
const app = app_state.app();
|
|
232
|
+
try harness.start(app);
|
|
233
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
234
|
+
.label = canvas_label,
|
|
235
|
+
.size = geometry.SizeF.init(400, 300),
|
|
236
|
+
.scale_factor = 1,
|
|
237
|
+
.frame_index = 1,
|
|
238
|
+
.timestamp_ns = 1_000_000,
|
|
239
|
+
.nonblank = true,
|
|
240
|
+
} });
|
|
241
|
+
|
|
242
|
+
// init_fx creates the table, subscribes while it is empty, then inserts.
|
|
243
|
+
// Its one flush therefore delivers the initial empty page and one
|
|
244
|
+
// refreshed one-row page.
|
|
245
|
+
try app_state.drainEffects(&harness.runtime);
|
|
246
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.model.pages);
|
|
247
|
+
try std.testing.expectEqual(@as(u32, 1), app_state.model.rows);
|
|
248
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.model.done);
|
|
249
|
+
try std.testing.expectEqual(@as(u32, 2), app_state.model.execs);
|
|
250
|
+
|
|
251
|
+
// A later update_fx transaction must invalidate and rerun the same live
|
|
252
|
+
// query without the Zig app manually reaching into the effects host.
|
|
253
|
+
try app_state.dispatch(&harness.runtime, 1, .add);
|
|
254
|
+
try app_state.drainEffects(&harness.runtime);
|
|
255
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.model.pages);
|
|
256
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.model.rows);
|
|
257
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.model.done);
|
|
258
|
+
try std.testing.expectEqual(@as(u32, 3), app_state.model.execs);
|
|
259
|
+
try harness.stop(app);
|
|
260
|
+
}
|
|
261
|
+
|
|
108
262
|
test "ui app owns install, dispatch, and rebuild end to end" {
|
|
109
263
|
// The runtime and the app are both large structs; keep them off the
|
|
110
264
|
// test thread's stack.
|
|
@@ -1679,6 +1833,50 @@ test "unthemed apps follow the system appearance live; explicit tokens opt out"
|
|
|
1679
1833
|
try std.testing.expectEqualDeep(light.colors.background, fixed_state.effectiveTokens().colors.background);
|
|
1680
1834
|
}
|
|
1681
1835
|
|
|
1836
|
+
test "model-derived theme packs retain live appearance, accent, and surface scale" {
|
|
1837
|
+
var options = counterOptions();
|
|
1838
|
+
options.theme = .geist; // The model-derived pack wins this fallback.
|
|
1839
|
+
options.theme_fn = counterThemePack;
|
|
1840
|
+
options.theme_accent = canvas.Color.rgb8(0xdf, 0x26, 0x70);
|
|
1841
|
+
|
|
1842
|
+
const app_state = try std.testing.allocator.create(CounterApp);
|
|
1843
|
+
defer std.testing.allocator.destroy(app_state);
|
|
1844
|
+
app_state.* = CounterApp.init(std.heap.page_allocator, .{}, options);
|
|
1845
|
+
defer app_state.deinit();
|
|
1846
|
+
app_state.system_appearance = .{ .color_scheme = .dark, .reduce_motion = true };
|
|
1847
|
+
app_state.pixel_snap_scale = 2;
|
|
1848
|
+
|
|
1849
|
+
var house = canvas.DesignTokens.theme(.{
|
|
1850
|
+
.color_scheme = .dark,
|
|
1851
|
+
.reduce_motion = true,
|
|
1852
|
+
.pack = .house,
|
|
1853
|
+
});
|
|
1854
|
+
house = house.withOverrides(canvas.accentOverrides(options.theme_accent.?, .dark));
|
|
1855
|
+
var actual = app_state.effectiveTokens();
|
|
1856
|
+
try std.testing.expectEqualDeep(house.colors.background, actual.colors.background);
|
|
1857
|
+
try std.testing.expectEqualDeep(house.colors.accent, actual.colors.accent);
|
|
1858
|
+
try std.testing.expectEqualDeep(house.colors.focus_ring, actual.colors.focus_ring);
|
|
1859
|
+
try std.testing.expectEqual(house.metrics.control_height, actual.metrics.control_height);
|
|
1860
|
+
try std.testing.expectEqual(@as(u32, 0), actual.motion.normal_ms);
|
|
1861
|
+
try std.testing.expectEqual(@as(f32, 2), actual.pixel_snap.scale);
|
|
1862
|
+
|
|
1863
|
+
app_state.model.count = 1;
|
|
1864
|
+
var geist = canvas.DesignTokens.theme(.{
|
|
1865
|
+
.color_scheme = .dark,
|
|
1866
|
+
.reduce_motion = true,
|
|
1867
|
+
.pack = .geist,
|
|
1868
|
+
});
|
|
1869
|
+
geist = geist.withOverrides(canvas.accentOverrides(options.theme_accent.?, .dark));
|
|
1870
|
+
actual = app_state.effectiveTokens();
|
|
1871
|
+
try std.testing.expectEqualDeep(geist.colors.background, actual.colors.background);
|
|
1872
|
+
try std.testing.expectEqualDeep(geist.colors.accent, actual.colors.accent);
|
|
1873
|
+
try std.testing.expectEqualDeep(geist.colors.focus_ring, actual.colors.focus_ring);
|
|
1874
|
+
try std.testing.expectEqual(geist.metrics.control_height, actual.metrics.control_height);
|
|
1875
|
+
try std.testing.expect(house.metrics.control_height != geist.metrics.control_height);
|
|
1876
|
+
try std.testing.expectEqual(@as(u32, 0), actual.motion.normal_ms);
|
|
1877
|
+
try std.testing.expectEqual(@as(f32, 2), actual.pixel_snap.scale);
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1682
1880
|
test "static tokens carry the surface scale and re-snap on a scale change" {
|
|
1683
1881
|
const harness = try core.TestHarness().create(std.testing.allocator, .{ .size = geometry.SizeF.init(400, 300) });
|
|
1684
1882
|
defer harness.destroy(std.testing.allocator);
|
|
@@ -3866,7 +4064,7 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
|
|
|
3866
4064
|
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = frame_event });
|
|
3867
4065
|
|
|
3868
4066
|
// The snapshot exposes the applied tray: model-derived title, every
|
|
3869
|
-
// dropdown row with
|
|
4067
|
+
// dropdown row with its action and rich presentation fields, and separators —
|
|
3870
4068
|
// the menu bar is outside every window capture, so this is the only
|
|
3871
4069
|
// automation-visible evidence the model-driven tray exists.
|
|
3872
4070
|
{
|
|
@@ -3875,10 +4073,10 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
|
|
|
3875
4073
|
try automation.snapshot.writeText(harness.runtime.automationSnapshot("Tray"), &writer);
|
|
3876
4074
|
const text = writer.buffered();
|
|
3877
4075
|
try std.testing.expect(std.mem.indexOf(u8, text, "tray title=\"ZN 3\" items=4\n") != null);
|
|
3878
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true\n") != null);
|
|
4076
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
3879
4077
|
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
|
|
3880
4078
|
// The fixture disables the SELECTED row (initially issue 0).
|
|
3881
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false\n") != null);
|
|
4079
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
3882
4080
|
}
|
|
3883
4081
|
|
|
3884
4082
|
// `tray-action <id>` drives a dropdown row through the same platform
|
|
@@ -3891,8 +4089,8 @@ test "ui app tray state rides automation snapshots and tray-action drives a row"
|
|
|
3891
4089
|
var writer = std.Io.Writer.fixed(&buffer);
|
|
3892
4090
|
try automation.snapshot.writeText(harness.runtime.automationSnapshot("Tray"), &writer);
|
|
3893
4091
|
const text = writer.buffered();
|
|
3894
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #11 label=\"Adopt the tray seam\" command=\"issue.select.1\" enabled=false\n") != null);
|
|
3895
|
-
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=true\n") != null);
|
|
4092
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #11 label=\"Adopt the tray seam\" command=\"issue.select.1\" enabled=false detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
4093
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
3896
4094
|
}
|
|
3897
4095
|
|
|
3898
4096
|
// Unknown or malformed item ids are loud driver misuse, never a
|
|
@@ -119,7 +119,14 @@ fn validateCredentialField(value: []const u8, max_len: usize) !void {
|
|
|
119
119
|
pub fn validateTrayOptions(options: platform.TrayOptions) !void {
|
|
120
120
|
try validateTrayField(options.icon_path, platform.max_tray_icon_path_bytes);
|
|
121
121
|
try validateTrayField(options.title, platform.max_tray_title_bytes);
|
|
122
|
+
try validateTrayPresentation(options.presentation);
|
|
122
123
|
try validateTrayField(options.tooltip, platform.max_tray_tooltip_bytes);
|
|
124
|
+
try validateTrayField(options.activation_command, platform.max_tray_item_command_bytes);
|
|
125
|
+
try validateTrayField(options.alternate_activation_command, platform.max_tray_item_command_bytes);
|
|
126
|
+
try validateTrayField(options.open_command, platform.max_tray_item_command_bytes);
|
|
127
|
+
if (options.activation_command.len > 0) try validateCommandName(options.activation_command);
|
|
128
|
+
if (options.alternate_activation_command.len > 0) try validateCommandName(options.alternate_activation_command);
|
|
129
|
+
if (options.open_command.len > 0) try validateCommandName(options.open_command);
|
|
123
130
|
try validateTrayMenuItems(options.items);
|
|
124
131
|
}
|
|
125
132
|
|
|
@@ -127,11 +134,22 @@ pub fn validateTrayTitle(title: []const u8) !void {
|
|
|
127
134
|
try validateTrayField(title, platform.max_tray_title_bytes);
|
|
128
135
|
}
|
|
129
136
|
|
|
137
|
+
pub fn validateTrayPresentation(presentation: platform.TrayPresentation) !void {
|
|
138
|
+
try validateTrayTitle(presentation.title);
|
|
139
|
+
if (!std.math.isFinite(presentation.width) or presentation.width < 0) return error.InvalidTrayOptions;
|
|
140
|
+
if (!std.math.isFinite(presentation.icon_opacity) or presentation.icon_opacity < 0 or presentation.icon_opacity > 1) return error.InvalidTrayOptions;
|
|
141
|
+
}
|
|
142
|
+
|
|
130
143
|
pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
|
|
131
144
|
if (items.len > platform.max_tray_items) return error.InvalidTrayOptions;
|
|
132
145
|
for (items, 0..) |item, index| {
|
|
133
146
|
try validateTrayField(item.label, platform.max_tray_item_label_bytes);
|
|
134
147
|
try validateTrayField(item.command, platform.max_tray_item_command_bytes);
|
|
148
|
+
try validateTrayField(item.detail, platform.max_tray_item_detail_bytes);
|
|
149
|
+
try validateTrayField(item.key, platform.max_menu_key_bytes);
|
|
150
|
+
if (item.role != .command and item.role != .agent and item.command.len > 0) return error.InvalidTrayOptions;
|
|
151
|
+
if (item.detail.len > 0 and item.role != .info and item.role != .hero and item.role != .agent and item.role != .context) return error.InvalidTrayOptions;
|
|
152
|
+
if (item.separator and (item.detail.len > 0 or item.role != .command)) return error.InvalidTrayOptions;
|
|
135
153
|
if (item.id != 0) {
|
|
136
154
|
for (items[0..index]) |previous| {
|
|
137
155
|
if (previous.id == item.id) return error.InvalidTrayOptions;
|
|
@@ -142,6 +160,10 @@ pub fn validateTrayMenuItems(items: []const platform.TrayMenuItem) !void {
|
|
|
142
160
|
try validateCommandName(item.command);
|
|
143
161
|
}
|
|
144
162
|
if (!item.separator and item.label.len == 0) return error.InvalidTrayOptions;
|
|
163
|
+
if (item.key.len > 0) {
|
|
164
|
+
if (item.separator or item.command.len == 0) return error.InvalidTrayOptions;
|
|
165
|
+
if (!platform.isValidShortcutBinding(item.key, item.modifiers)) return error.InvalidTrayOptions;
|
|
166
|
+
}
|
|
145
167
|
}
|
|
146
168
|
}
|
|
147
169
|
|