@native-sdk/cli 0.9.0 → 0.9.2
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 +357 -33
- package/build.zig +234 -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 +170 -13
- 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 +18 -12
- package/skill-data/ts-core/SKILL.md +54 -21
- 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 +122 -6
- package/src/app_runner/ts_core_main.zig +9 -4
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/app_runner/window_placement.zig +63 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +3 -1
- package/src/embed/conversions.zig +1 -0
- package/src/embed/host.zig +10 -3
- package/src/embed/root.zig +2 -0
- package/src/embed/tests.zig +41 -1
- package/src/embed/types.zig +2 -0
- package/src/embed/ui_host.zig +94 -4
- package/src/platform/android/NativeSdkActivity.java +49 -4
- package/src/platform/android/android_host.c +3 -3
- package/src/platform/android/native_sdk_app.h +1 -1
- package/src/platform/ios/apple_image_fit.h +38 -0
- package/src/platform/ios/files.zig +1 -0
- package/src/platform/ios/native_sdk_app.h +1 -1
- package/src/platform/ios/uikit_host.m +28 -5
- package/src/platform/linux/cef_host.cpp +17 -3
- package/src/platform/linux/gtk_host.c +243 -15
- package/src/platform/linux/gtk_host.h +5 -4
- package/src/platform/linux/root.zig +91 -11
- package/src/platform/macos/appkit_host.h +18 -11
- package/src/platform/macos/appkit_host.m +402 -128
- package/src/platform/macos/cef_host.mm +342 -122
- package/src/platform/macos/image_fit_test.m +44 -0
- package/src/platform/macos/root.zig +231 -39
- package/src/platform/null_platform.zig +251 -54
- package/src/platform/null_platform_tests.zig +97 -4
- package/src/platform/root.zig +12 -0
- package/src/platform/types.zig +174 -35
- package/src/platform/windows/root.zig +42 -13
- package/src/platform/windows/webview2_host.cpp +72 -11
- package/src/primitives/app_manifest/root.zig +3 -0
- package/src/primitives/app_manifest/tests.zig +24 -0
- package/src/primitives/app_manifest/types.zig +13 -0
- package/src/primitives/app_manifest/validation.zig +24 -0
- package/src/primitives/canvas/a11y_audit.zig +9 -7
- package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
- package/src/primitives/canvas/events.zig +50 -0
- package/src/primitives/canvas/layout_audit.zig +6 -6
- package/src/primitives/canvas/markdown.zig +4 -0
- package/src/primitives/canvas/markdown_tests.zig +1 -0
- package/src/primitives/canvas/png.zig +138 -0
- package/src/primitives/canvas/root.zig +13 -2
- package/src/primitives/canvas/text_span_tests.zig +5 -3
- package/src/primitives/canvas/text_spans.zig +2 -0
- package/src/primitives/canvas/text_tests.zig +20 -0
- package/src/primitives/canvas/ui.zig +55 -2
- package/src/primitives/canvas/ui_markup.zig +40 -13
- package/src/primitives/canvas/ui_markup_binary.zig +8 -6
- package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
- package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +52 -0
- package/src/primitives/canvas/ui_markup_tests.zig +11 -2
- package/src/primitives/canvas/ui_markup_view.zig +8 -2
- package/src/primitives/canvas/ui_markup_view_tests.zig +49 -4
- package/src/primitives/canvas/ui_schema.zig +17 -13
- package/src/primitives/canvas/ui_tests.zig +47 -0
- package/src/primitives/canvas/widget_access.zig +3 -3
- package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +580 -32
- package/src/primitives/canvas/widget_invalidation.zig +33 -6
- package/src/primitives/canvas/widget_layout.zig +333 -126
- package/src/primitives/canvas/widget_layout_tests.zig +169 -0
- package/src/primitives/canvas/widget_metrics.zig +7 -8
- package/src/primitives/canvas/widget_render.zig +76 -44
- package/src/primitives/canvas/widget_render_controls.zig +110 -32
- package/src/primitives/canvas/widget_render_style.zig +58 -18
- package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
- package/src/primitives/canvas/widget_routing.zig +40 -34
- package/src/primitives/canvas/widget_runtime.zig +11 -2
- package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
- package/src/primitives/canvas/widget_semantics.zig +8 -3
- package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
- package/src/primitives/canvas/widget_tree.zig +99 -5
- package/src/primitives/canvas/widgets.zig +20 -7
- package/src/root.zig +10 -0
- package/src/runtime/api.zig +14 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/automation_widget_dispatch.zig +48 -6
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +16 -3
- package/src/runtime/canvas_frame_packet_tests.zig +22 -13
- package/src/runtime/canvas_image_tests.zig +146 -2
- package/src/runtime/canvas_images.zig +35 -16
- package/src/runtime/canvas_limits.zig +13 -3
- package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
- package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
- package/src/runtime/canvas_widget_control_tests.zig +31 -1
- package/src/runtime/canvas_widget_events.zig +151 -26
- package/src/runtime/canvas_widget_floating_tests.zig +48 -0
- package/src/runtime/canvas_widget_runtime.zig +322 -102
- package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
- package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
- package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
- package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
- package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
- package/src/runtime/canvas_widget_state.zig +33 -7
- package/src/runtime/core.zig +28 -6
- package/src/runtime/effects.zig +1337 -49
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_image_tests.zig +91 -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/gpu_surface_events.zig +25 -2
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +7 -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 +110 -15
- package/src/runtime/session_tests.zig +192 -4
- package/src/runtime/shell_layout_tests.zig +12 -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 +142 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +330 -112
- package/src/runtime/ui_app_tests.zig +251 -25
- package/src/runtime/ui_app_window_tests.zig +74 -8
- package/src/runtime/validation.zig +20 -0
- package/src/runtime/view.zig +3 -0
- package/src/runtime/view_widget_control.zig +18 -0
- package/src/runtime/view_widget_scroll.zig +112 -18
- package/src/runtime/view_widget_tree.zig +110 -13
- package/src/runtime/widget_bridge.zig +2 -0
- package/src/runtime/window_command_bridge_tests.zig +86 -0
- package/src/runtime/window_storage.zig +16 -1
- package/src/runtime/window_views.zig +1 -0
- package/src/tooling/ios.zig +3 -0
- package/src/tooling/manifest.zig +90 -2
- package/src/tooling/package.zig +67 -2
- package/src/tooling/raw_manifest.zig +10 -0
- package/src/tooling/templates.zig +156 -18
- package/src/tooling/ts_core.zig +83 -0
- package/src/tooling/web_engine.zig +1 -1
- 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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Verify without writing:
|
|
7
7
|
node packages/core/scripts/gen_service_surface.mjs --check -->
|
|
8
8
|
|
|
9
|
-
# Service compile surface — scriptc 0.0.
|
|
9
|
+
# Service compile surface — scriptc 0.0.31
|
|
10
10
|
|
|
11
11
|
What TypeScript under `src/services/` can use, as stated by the pinned
|
|
12
12
|
compiler itself (surface manifest schema 1, 527 entries:
|
|
@@ -600,4 +600,5 @@ statuses promise, verbatim:
|
|
|
600
600
|
- The engine-free fetch projection targets Node 24.15.0 with bundled Undici 7.24.4. Each projected row names the differential evidence that guards it; changing the pinned Node or Undici version is an explicit profile update.
|
|
601
601
|
- The fetch profile also contains a runtime-reflected census of the selected fetch, abort, Headers, and readable-stream interfaces plus RequestInit/ResponseInit dictionary reads. Static, dynamic-only, and unsupported census rows are projected here; its explicitly out-of-scope metadata rows and adjacent-interface exclusions remain in the profile so absence is deliberate rather than ambiguous.
|
|
602
602
|
- Process-level diagnostic codes are not surface entries: SC0001-SC0004 are preflight gates, SC1110 is a comptime evaluation failure, SC3001/SC3002 are backend/target tier refusals, SC9001/SC9002 are internal errors.
|
|
603
|
+
- Entry statuses are projected for the desktop targets. The mobile targets (aarch64-apple-ios, aarch64-apple-ios-simulator, aarch64-linux-android) compile library-mode archives only: the library-admissible surface (what SC4005's async_free requirement and the library link set admit) is supported there, the executable lane refuses those triples with SC3002, and no entry outside the library-admissible surface carries a mobile support claim. iOS archives build for iOS 15.0 on darwin hosts; Android archives build against NDK API level 26.
|
|
603
604
|
- No scheduling metadata is published; entry ids are the stable diff keys across releases.
|
package/skill-data/zig/SKILL.md
CHANGED
|
@@ -12,7 +12,7 @@ Two rules resolve most failures:
|
|
|
12
12
|
- Operations on the outside world take a `std.Io` first (or right after the receiver). Get one from `init.io` in `main(init: std.process.Init)`, from `std.testing.io` in tests, or from `std.Io.Threaded` in code with no `Init` to thread through.
|
|
13
13
|
- Containers are unmanaged: initialize with `.empty` and pass the allocator to every mutating call.
|
|
14
14
|
|
|
15
|
-
In a UiApp, `update` never sees an `Io` — persistence, record and relational storage, secure credentials, subprocesses, HTTP, clocks, and timers go through the typed effects channel (`fx.persist`, `fx.storeSet`/`storeGet`/`storeDelete`/`storeScan`/`storeSetMany`, `fx.dbQuery`/`dbExec`, `fx.credentialsSet`/`credentialsGet`/`credentialsDelete`, `fx.readFile
|
|
15
|
+
In a UiApp, `update` never sees an `Io` — persistence, record and relational storage, secure credentials, subprocesses, HTTP, clocks, and timers go through the typed effects channel (`fx.persist`, `fx.storeSet`/`storeGet`/`storeDelete`/`storeScan`/`storeSetMany`, `fx.dbQuery`/`dbExec`, `fx.credentialsSet`/`credentialsGet`/`credentialsDelete`, `fx.readFile`/`appendFile`/`statFile`/`deleteFile`/streaming file verbs, `fx.spawn`, `fx.fetch`, `fx.wallMs`, `fx.startTimer`; see `native skills get native-ui`). Whole-file IO stays capped at 1 MiB; streamed reads deliver 256-KiB chunks, and streamed writes finalize atomically on close. External raw paths require the `filesystem` permission, while the app's six resolved directories are exempt after symlink-safe canonicalization. Raw `std.Io` belongs in `main`, tests, and standalone tools. Record-store apps declare `"store"`; relational apps declare `"sqlite"`; credentials require both the `"credentials"` capability and permission. Credential Msg arms carry `EffectCredentialsResult`; consume successful get bytes immediately and never retain them in Model. The engine owns database paths and app-scoped credential namespaces, while every result still returns as a Msg and crosses the replay journal (credential bytes are redacted). Use `TestHarness().createWithRelationalStore` for a hermetic in-memory relational database and `TestHarness().createWithCredentials` for a hermetic in-memory credential store. And because Zig analyzes lazily, a 0.15-ism can hide in code only one build path references: run BOTH `zig build` and `zig build test` before calling a change done.
|
|
16
16
|
|
|
17
17
|
## error: struct 'heap' has no member named 'GeneralPurposeAllocator' — allocators come from `main(init: std.process.Init)`
|
|
18
18
|
|
package/src/app_runner/root.zig
CHANGED
|
@@ -3,9 +3,16 @@ const build_options = @import("build_options");
|
|
|
3
3
|
const native_sdk = @import("native_sdk");
|
|
4
4
|
const app_manifest = @import("app_manifest_zon");
|
|
5
5
|
const built_relational_migrations = @import("relational_migrations");
|
|
6
|
+
const window_placement = @import("window_placement.zig");
|
|
6
7
|
const manifest_shortcuts = if (@hasField(@TypeOf(app_manifest), "shortcuts")) app_manifest.shortcuts else .{};
|
|
7
8
|
const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
|
|
8
9
|
|
|
10
|
+
fn manifestImagePixelBudget() usize {
|
|
11
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "images")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
12
|
+
if (comptime !@hasField(@TypeOf(app_manifest.images), "max_image_pixel_bytes")) return native_sdk.max_registered_canvas_image_pixel_bytes;
|
|
13
|
+
return app_manifest.images.max_image_pixel_bytes;
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
pub const app_assets = @import("app_assets.zig");
|
|
10
17
|
|
|
11
18
|
pub const StdoutTraceSink = struct {
|
|
@@ -49,6 +56,8 @@ pub const RunOptions = struct {
|
|
|
49
56
|
icon_path: []const u8 = "assets/icon.png",
|
|
50
57
|
default_frame: native_sdk.geometry.RectF = native_sdk.geometry.RectF.init(0, 0, 1100, 760),
|
|
51
58
|
restore_state: bool = true,
|
|
59
|
+
restore_policy: native_sdk.WindowRestorePolicy = .clamp_to_visible_screen,
|
|
60
|
+
initial_placement: native_sdk.WindowInitialPlacement = .default,
|
|
52
61
|
bridge: ?native_sdk.BridgeDispatcher = null,
|
|
53
62
|
builtin_bridge: native_sdk.BridgePolicy = .{},
|
|
54
63
|
js_window_api: bool = false,
|
|
@@ -61,6 +70,10 @@ pub const RunOptions = struct {
|
|
|
61
70
|
record_store: ?native_sdk.RecordStoreBinding = null,
|
|
62
71
|
relational_store: ?native_sdk.RelationalStoreBinding = null,
|
|
63
72
|
credentials_enabled: bool = false,
|
|
73
|
+
file_access: ?native_sdk.FileAccessBinding = null,
|
|
74
|
+
/// Migration/testing switch. Shipping defaults to the final enforced
|
|
75
|
+
/// posture; set false for the preceding warn-only behavior.
|
|
76
|
+
file_access_enforce: bool = true,
|
|
64
77
|
relational_migrations: []const native_sdk.relational_store.Migration = &built_relational_migrations.migrations,
|
|
65
78
|
|
|
66
79
|
fn appInfo(self: RunOptions, buffers: *StateBuffers) native_sdk.AppInfo {
|
|
@@ -75,6 +88,7 @@ pub const RunOptions = struct {
|
|
|
75
88
|
.description = manifestStringField("description"),
|
|
76
89
|
.has_web_content = manifestHasWebContent(),
|
|
77
90
|
.declares_tray = manifestDeclaresTrayCapability(),
|
|
91
|
+
.dock_visible = manifestDockVisible(),
|
|
78
92
|
.window_title = self.window_title,
|
|
79
93
|
.bundle_id = self.bundle_id,
|
|
80
94
|
.icon_path = self.icon_path,
|
|
@@ -84,6 +98,8 @@ pub const RunOptions = struct {
|
|
|
84
98
|
.title = self.window_title,
|
|
85
99
|
.default_frame = self.default_frame,
|
|
86
100
|
.restore_state = self.restore_state,
|
|
101
|
+
.restore_policy = self.restore_policy,
|
|
102
|
+
.initial_placement = self.initial_placement,
|
|
87
103
|
},
|
|
88
104
|
};
|
|
89
105
|
const windows = manifestWindowOptions(buffers);
|
|
@@ -99,8 +115,12 @@ pub const RunOptions = struct {
|
|
|
99
115
|
// a canvas-first startup window is created ordered-out and
|
|
100
116
|
// shown after its first canvas frame presents, so launch
|
|
101
117
|
// never flashes a blank window.
|
|
118
|
+
info.main_window.default_frame = manifestShellStartupFrame(info.main_window.default_frame);
|
|
119
|
+
info.main_window.restore_state = manifestShellStartupRestoreState(info.main_window.restore_state);
|
|
102
120
|
info.main_window.titlebar = manifestShellStartupTitlebar();
|
|
103
121
|
info.main_window.resizable = manifestShellStartupResizable();
|
|
122
|
+
info.main_window.restore_policy = manifestShellStartupRestorePolicy(info.main_window.restore_policy);
|
|
123
|
+
info.main_window.initial_placement = manifestShellStartupInitialPlacement(info.main_window.initial_placement);
|
|
104
124
|
info.main_window.show = manifestShellStartupShowMode();
|
|
105
125
|
info.main_window.transparent = manifestShellStartupBool("transparent", false);
|
|
106
126
|
info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
|
|
@@ -172,6 +192,7 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
|
|
|
172
192
|
.resizable = windowBool(window, "resizable", true),
|
|
173
193
|
.restore_state = windowBool(window, "restore_state", true),
|
|
174
194
|
.restore_policy = windowRestorePolicy(window),
|
|
195
|
+
.initial_placement = if (windowHasExplicitOrigin(window)) .explicit else .default,
|
|
175
196
|
.titlebar = windowTitlebarStyle(window),
|
|
176
197
|
.show = if (windowBool(window, "initially_hidden", false)) .hidden else .immediate,
|
|
177
198
|
.transparent = windowBool(window, "transparent", false),
|
|
@@ -407,6 +428,60 @@ fn windowRestorePolicy(comptime window: anytype) native_sdk.WindowRestorePolicy
|
|
|
407
428
|
@compileError("unknown app.zon window restore_policy");
|
|
408
429
|
}
|
|
409
430
|
|
|
431
|
+
fn windowHasExplicitOrigin(comptime window: anytype) bool {
|
|
432
|
+
return @hasField(@TypeOf(window), "x") or @hasField(@TypeOf(window), "y");
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/// The host creates the first scene window before the scene loads, so its
|
|
436
|
+
/// authored frame must ride AppInfo with the other creation-time options.
|
|
437
|
+
/// Omitted fields preserve RunOptions' direct-SDK fallback independently.
|
|
438
|
+
fn manifestShellStartupFrame(fallback: native_sdk.geometry.RectF) native_sdk.geometry.RectF {
|
|
439
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
440
|
+
const shell = app_manifest.shell;
|
|
441
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
442
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
443
|
+
const window = shell.windows[0];
|
|
444
|
+
return native_sdk.geometry.RectF.init(
|
|
445
|
+
windowFloatFallback(window, "x", fallback.x),
|
|
446
|
+
windowFloatFallback(window, "y", fallback.y),
|
|
447
|
+
windowFloatFallback(window, "width", fallback.width),
|
|
448
|
+
windowFloatFallback(window, "height", fallback.height),
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
fn windowFloatFallback(comptime window: anytype, comptime field: []const u8, fallback: f32) f32 {
|
|
453
|
+
if (comptime @hasField(@TypeOf(window), field)) return @field(window, field);
|
|
454
|
+
return fallback;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
fn manifestShellStartupRestoreState(fallback: bool) bool {
|
|
458
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
459
|
+
const shell = app_manifest.shell;
|
|
460
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
461
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
462
|
+
const window = shell.windows[0];
|
|
463
|
+
if (comptime @hasField(@TypeOf(window), "restore_state")) return window.restore_state;
|
|
464
|
+
return fallback;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
fn manifestShellStartupRestorePolicy(fallback: native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
|
|
468
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
469
|
+
const shell = app_manifest.shell;
|
|
470
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
471
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
472
|
+
const window = shell.windows[0];
|
|
473
|
+
const declared: ?native_sdk.WindowRestorePolicy = if (comptime @hasField(@TypeOf(window), "restore_policy")) windowRestorePolicy(window) else null;
|
|
474
|
+
return window_placement.applyShellRestorePolicy(fallback, declared);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
fn manifestShellStartupInitialPlacement(fallback: native_sdk.WindowInitialPlacement) native_sdk.WindowInitialPlacement {
|
|
478
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
|
|
479
|
+
const shell = app_manifest.shell;
|
|
480
|
+
if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
|
|
481
|
+
if (comptime shell.windows.len == 0) return fallback;
|
|
482
|
+
return window_placement.applyShellInitialPlacement(fallback, windowHasExplicitOrigin(shell.windows[0]));
|
|
483
|
+
}
|
|
484
|
+
|
|
410
485
|
/// What the window's close affordance does, from app.zon. `.hide` is
|
|
411
486
|
/// validated against the TARGET platform at comptime: a host with no
|
|
412
487
|
/// affordance to bring a hidden window back (GTK has no status item;
|
|
@@ -443,6 +518,17 @@ fn manifestDeclaresTrayCapability() bool {
|
|
|
443
518
|
return false;
|
|
444
519
|
}
|
|
445
520
|
|
|
521
|
+
/// Initial Dock/app-switcher presence. The validation is repeated at
|
|
522
|
+
/// comptime so a custom/ejected build cannot bypass the same safety
|
|
523
|
+
/// rule as `native validate` and strand an accessory app with no tray.
|
|
524
|
+
fn manifestDockVisible() bool {
|
|
525
|
+
const visible = if (comptime @hasField(@TypeOf(app_manifest), "dock_visible")) app_manifest.dock_visible else true;
|
|
526
|
+
if (comptime !visible and !manifestDeclaresTrayCapability()) {
|
|
527
|
+
@compileError("app.zon dock_visible = false requires the \"tray\" capability: an accessory app has no Dock/app-switcher route back to hidden windows - add \"tray\" to .capabilities and install a status item, or keep dock_visible = true (the default)");
|
|
528
|
+
}
|
|
529
|
+
return visible;
|
|
530
|
+
}
|
|
531
|
+
|
|
446
532
|
/// Whether app.zon declares the Tier-2 record store. This is comptime so
|
|
447
533
|
/// apps without the capability never analyze the SQLite open/deinit path.
|
|
448
534
|
fn manifestDeclaresStore() bool {
|
|
@@ -508,6 +594,27 @@ pub fn runWithOptions(app: native_sdk.App, options: RunOptions, init: std.proces
|
|
|
508
594
|
var record_store_open = false;
|
|
509
595
|
var resolved_options = options;
|
|
510
596
|
resolved_options.credentials_enabled = manifestDeclaresCredentials();
|
|
597
|
+
var file_root_buffers: [6][1024]u8 = undefined;
|
|
598
|
+
var file_roots: [6][]const u8 = undefined;
|
|
599
|
+
const resolved_file_dirs = native_sdk.app_dirs.resolve(
|
|
600
|
+
.{ .name = options.bundle_id },
|
|
601
|
+
native_sdk.app_dirs.currentPlatform(),
|
|
602
|
+
native_sdk.debug.envFromMap(init.environ_map),
|
|
603
|
+
native_sdk.app_dirs.Buffers.fromArray(1024, &file_root_buffers),
|
|
604
|
+
) catch null;
|
|
605
|
+
var file_root_count: usize = 0;
|
|
606
|
+
if (resolved_file_dirs) |dirs| {
|
|
607
|
+
file_roots = .{ dirs.config, dirs.cache, dirs.data, dirs.state, dirs.logs, dirs.temp };
|
|
608
|
+
file_root_count = file_roots.len;
|
|
609
|
+
}
|
|
610
|
+
// Fail closed if app-dir resolution is unavailable: a filesystem grant
|
|
611
|
+
// still opens arbitrary paths, while an ungranted app gets no accidental
|
|
612
|
+
// unrestricted fallback merely because HOME/XDG data was malformed.
|
|
613
|
+
resolved_options.file_access = .{
|
|
614
|
+
.roots = file_roots[0..file_root_count],
|
|
615
|
+
.permitted = native_sdk.security.hasPermission(options.security.permissions, native_sdk.security.permission_filesystem),
|
|
616
|
+
.enforce = options.file_access_enforce,
|
|
617
|
+
};
|
|
511
618
|
if (comptime manifestDeclaresStore()) {
|
|
512
619
|
var data_dir_buffer: [512]u8 = undefined;
|
|
513
620
|
const app_data_dir = native_sdk.app_dirs.resolveOne(
|
|
@@ -601,6 +708,7 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
601
708
|
defer runtime.deinit();
|
|
602
709
|
native_sdk.Runtime.initAt(runtime, .{
|
|
603
710
|
.platform = null_platform.platform(),
|
|
711
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
604
712
|
.trace_sink = runtime_trace_sink,
|
|
605
713
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
606
714
|
.bridge = options.bridge,
|
|
@@ -616,6 +724,7 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
616
724
|
.record_store = options.record_store,
|
|
617
725
|
.relational_store = options.relational_store,
|
|
618
726
|
.credentials_enabled = options.credentials_enabled,
|
|
727
|
+
.file_access = options.file_access,
|
|
619
728
|
.environ = init.minimal.environ,
|
|
620
729
|
.session_recorder = session_recorder,
|
|
621
730
|
});
|
|
@@ -668,6 +777,7 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
668
777
|
defer runtime.deinit();
|
|
669
778
|
native_sdk.Runtime.initAt(runtime, .{
|
|
670
779
|
.platform = mac_platform.platform(),
|
|
780
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
671
781
|
.trace_sink = runtime_trace_sink,
|
|
672
782
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
673
783
|
.bridge = options.bridge,
|
|
@@ -683,6 +793,7 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
683
793
|
.record_store = options.record_store,
|
|
684
794
|
.relational_store = options.relational_store,
|
|
685
795
|
.credentials_enabled = options.credentials_enabled,
|
|
796
|
+
.file_access = options.file_access,
|
|
686
797
|
.environ = init.minimal.environ,
|
|
687
798
|
.session_recorder = session_recorder,
|
|
688
799
|
});
|
|
@@ -732,6 +843,7 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
732
843
|
defer runtime.deinit();
|
|
733
844
|
native_sdk.Runtime.initAt(runtime, .{
|
|
734
845
|
.platform = linux_platform.platform(),
|
|
846
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
735
847
|
.trace_sink = runtime_trace_sink,
|
|
736
848
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
737
849
|
.bridge = options.bridge,
|
|
@@ -747,6 +859,7 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
747
859
|
.record_store = options.record_store,
|
|
748
860
|
.relational_store = options.relational_store,
|
|
749
861
|
.credentials_enabled = options.credentials_enabled,
|
|
862
|
+
.file_access = options.file_access,
|
|
750
863
|
.environ = init.minimal.environ,
|
|
751
864
|
.session_recorder = session_recorder,
|
|
752
865
|
});
|
|
@@ -795,6 +908,7 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
795
908
|
defer runtime.deinit();
|
|
796
909
|
native_sdk.Runtime.initAt(runtime, .{
|
|
797
910
|
.platform = windows_platform.platform(),
|
|
911
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
798
912
|
.trace_sink = runtime_trace_sink,
|
|
799
913
|
.log_path = if (log_setup) |setup| setup.paths.log_file else null,
|
|
800
914
|
.bridge = options.bridge,
|
|
@@ -810,6 +924,7 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
810
924
|
.record_store = options.record_store,
|
|
811
925
|
.relational_store = options.relational_store,
|
|
812
926
|
.credentials_enabled = options.credentials_enabled,
|
|
927
|
+
.file_access = options.file_access,
|
|
813
928
|
.environ = init.minimal.environ,
|
|
814
929
|
.session_recorder = session_recorder,
|
|
815
930
|
});
|
|
@@ -949,6 +1064,7 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
|
|
|
949
1064
|
// the journal and restores nothing.
|
|
950
1065
|
native_sdk.Runtime.initAt(runtime, .{
|
|
951
1066
|
.platform = replay_platform,
|
|
1067
|
+
.max_image_pixel_bytes = manifestImagePixelBudget(),
|
|
952
1068
|
.bridge = options.bridge,
|
|
953
1069
|
.builtin_bridge = options.builtin_bridge,
|
|
954
1070
|
.js_window_api = options.js_window_api,
|
|
@@ -1040,15 +1156,15 @@ fn prepareStateStore(io: std.Io, env_map: *std.process.Environ.Map, app_info: *n
|
|
|
1040
1156
|
const restored_windows = buffers.restored_windows[0..app_info.windows.len];
|
|
1041
1157
|
for (restored_windows, 0..) |*window, index| {
|
|
1042
1158
|
if (!window.restore_state) continue;
|
|
1043
|
-
if (store.loadWindow(window.label, &buffers.read) catch null)
|
|
1044
|
-
|
|
1045
|
-
|
|
1159
|
+
if (window_placement.applySavedWindow(window, store.loadWindow(window.label, &buffers.read) catch null)) {
|
|
1160
|
+
if (index == 0) {
|
|
1161
|
+
app_info.main_window.default_frame = window.default_frame;
|
|
1162
|
+
app_info.main_window.initial_placement = .restored;
|
|
1163
|
+
}
|
|
1046
1164
|
}
|
|
1047
1165
|
}
|
|
1048
1166
|
} else if (app_info.main_window.restore_state) {
|
|
1049
|
-
|
|
1050
|
-
app_info.main_window.default_frame = saved.frame;
|
|
1051
|
-
}
|
|
1167
|
+
_ = window_placement.applySavedWindow(&app_info.main_window, store.loadWindow(app_info.main_window.label, &buffers.read) catch null);
|
|
1052
1168
|
}
|
|
1053
1169
|
return store;
|
|
1054
1170
|
}
|
|
@@ -65,6 +65,7 @@ pub const core = @import("core.zig");
|
|
|
65
65
|
const services = @import("services.zig");
|
|
66
66
|
const service_carrier = @import("service_carrier.zig");
|
|
67
67
|
const relational_migrations = @import("migrations.zig");
|
|
68
|
+
const window_views = @import("window_views.zig");
|
|
68
69
|
|
|
69
70
|
pub const panic = std.debug.FullPanic(native_sdk.debug.capturePanic);
|
|
70
71
|
|
|
@@ -99,6 +100,10 @@ pub fn main(init: std.process.Init) !void {
|
|
|
99
100
|
.theme = comptime runner.manifestThemePack(),
|
|
100
101
|
.theme_accent = comptime runner.manifestThemeAccent(),
|
|
101
102
|
};
|
|
103
|
+
if (comptime @hasDecl(core.Model, "windows")) {
|
|
104
|
+
options.window_view = window_views.build;
|
|
105
|
+
options.fragment_watch = .{ .fragments = &window_views.fragments, .io = init.io };
|
|
106
|
+
}
|
|
102
107
|
if (comptime @hasDecl(core, "commandMsg")) {
|
|
103
108
|
// Menus, shortcuts, and chrome tabs dispatch through the core's
|
|
104
109
|
// exported command mapper.
|
|
@@ -394,10 +399,10 @@ const ImageAsset = struct {
|
|
|
394
399
|
path: []const u8,
|
|
395
400
|
};
|
|
396
401
|
|
|
397
|
-
///
|
|
398
|
-
/// entry (the views keep the initials fallback)
|
|
399
|
-
/// launch path hostage to a mis-sized asset.
|
|
400
|
-
const max_boot_image_bytes: usize =
|
|
402
|
+
/// Boot images and runtime image loads share one encoded-source contract:
|
|
403
|
+
/// over-bound files skip their entry (the views keep the initials fallback)
|
|
404
|
+
/// instead of holding the launch path hostage to a mis-sized asset.
|
|
405
|
+
const max_boot_image_bytes: usize = native_sdk.max_effect_image_source_bytes;
|
|
401
406
|
|
|
402
407
|
fn manifestImages() []const ImageAsset {
|
|
403
408
|
comptime {
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
//! The generated mobile wiring for a TypeScript app core — staged (never
|
|
2
|
+
//! written into the app) by the framework build beside the desktop entry
|
|
3
|
+
//! when the tree carries src/core.ts and the target is iOS or Android. The
|
|
4
|
+
//! embed static library's `app` module roots here: the file satisfies the
|
|
5
|
+
//! embed host's AppDef contract (`Model`, `Msg`, `initModel`,
|
|
6
|
+
//! `mobileOptions` — see `src/embed/ui_host.zig`) over the same staged
|
|
7
|
+
//! mirror (core.zig), markup (app.native), service registry (services.zig),
|
|
8
|
+
//! and carrier constant (service_carrier.zig) the desktop wiring uses.
|
|
9
|
+
//!
|
|
10
|
+
//! What differs from ts_core_main.zig is only the shell:
|
|
11
|
+
//!
|
|
12
|
+
//! scene the canonical single-surface mobile scene (window 1, one
|
|
13
|
+
//! gpu_surface labeled "mobile-surface") plus the app.zon
|
|
14
|
+
//! shell's declared platform chrome (tabs, primary action) —
|
|
15
|
+
//! the toolkit hosts project those as real system controls.
|
|
16
|
+
//! services the in-process pool is the ONLY carrier on mobile (no
|
|
17
|
+
//! child processes exist there); the build graph resolves
|
|
18
|
+
//! auto to in_process, and this file refuses a staged child
|
|
19
|
+
//! selection at comptime. The pool's marker/relay files live
|
|
20
|
+
//! in the OS app-data directory the shim installs through
|
|
21
|
+
//! `native_sdk_app_set_data_root` (the `serviceDataRoot`
|
|
22
|
+
//! hook below).
|
|
23
|
+
//! data dir a core exporting `envMsgs` with `NATIVE_SDK_APP_DATA_DIR`
|
|
24
|
+
//! receives the same shim-installed directory as a journaled
|
|
25
|
+
//! Msg right after the boot command.
|
|
26
|
+
//!
|
|
27
|
+
//! Model persistence (`persist`), boot images, and URL media caching are
|
|
28
|
+
//! not wired on mobile yet; the corresponding core commands degrade the
|
|
29
|
+
//! way the adapter documents (snapshots never write, views keep their
|
|
30
|
+
//! fallbacks, URL playback re-streams).
|
|
31
|
+
//!
|
|
32
|
+
//! Editing this file is never core-level work: it carries no app logic and
|
|
33
|
+
//! regenerates from the SDK on every build.
|
|
34
|
+
|
|
35
|
+
const std = @import("std");
|
|
36
|
+
const native_sdk = @import("native_sdk");
|
|
37
|
+
const manifest = @import("app_manifest_zon");
|
|
38
|
+
pub const core = @import("core.zig");
|
|
39
|
+
const services = @import("services.zig");
|
|
40
|
+
const service_carrier = @import("service_carrier.zig");
|
|
41
|
+
|
|
42
|
+
const Adapter = native_sdk.TsUiApp(core);
|
|
43
|
+
|
|
44
|
+
/// Re-exported for the embed host's AppDef contract (and any test that
|
|
45
|
+
/// reflects the core's real surface).
|
|
46
|
+
pub const Model = core.Model;
|
|
47
|
+
pub const Msg = core.Msg;
|
|
48
|
+
|
|
49
|
+
pub const app_markup = @embedFile("app.native");
|
|
50
|
+
|
|
51
|
+
comptime {
|
|
52
|
+
// The build graph resolves the carrier before staging this file; a
|
|
53
|
+
// staged child selection on a mobile target is a build-graph defect,
|
|
54
|
+
// not an app author's error.
|
|
55
|
+
if (services.enabled and service_carrier.kind == .child) {
|
|
56
|
+
@compileError("mobile TypeScript services run on the in-process pool; the child carrier cannot be staged here");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const use_pool = services.enabled and service_carrier.kind == .in_process;
|
|
61
|
+
const PoolTransport = native_sdk.ServicePool(services);
|
|
62
|
+
|
|
63
|
+
const app_data_dir_env = "NATIVE_SDK_APP_DATA_DIR";
|
|
64
|
+
|
|
65
|
+
const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
|
|
66
|
+
|
|
67
|
+
/// The canonical mobile surface plus the app's declared platform chrome.
|
|
68
|
+
const mobile_scene: native_sdk.app_manifest.ShellConfig = .{
|
|
69
|
+
.windows = native_sdk.embed.mobile_shell_scene.windows,
|
|
70
|
+
.chrome = shell_scene.chrome,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// Adapter-held mobile state (container-level, like the adapter's own
|
|
74
|
+
// install stores — one live app per core module is the v1 contract): the
|
|
75
|
+
// pool, its executor, and the shim-installed app-data directory.
|
|
76
|
+
var pool_io_state: std.Io.Threaded = undefined;
|
|
77
|
+
var pool_transport: PoolTransport = undefined;
|
|
78
|
+
var data_root_buffer: [native_sdk.embed.max_mobile_asset_root_bytes]u8 = undefined;
|
|
79
|
+
var env_entries: [envMsgsLen()]Adapter.EnvValue = undefined;
|
|
80
|
+
var env_entry_count: usize = 0;
|
|
81
|
+
var env_value_copies: [envMsgsLen()][]u8 = undefined;
|
|
82
|
+
var env_value_copy_count: usize = 0;
|
|
83
|
+
var data_root_env_indices: [envMsgsLen()]usize = undefined;
|
|
84
|
+
var data_root_env_count: usize = 0;
|
|
85
|
+
|
|
86
|
+
/// The embed host calls `mobileOptions()` first (UiAppHost.create), so the
|
|
87
|
+
/// boot model is committed by the time `initModel` reads it.
|
|
88
|
+
pub fn initModel() Model {
|
|
89
|
+
return Adapter.Host.model().*;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub fn mobileOptions() Adapter.Options {
|
|
93
|
+
if (comptime @hasDecl(core.Model, "windows")) {
|
|
94
|
+
@compileError("model-declared secondary windows are a desktop shell capability; omit windows(model) from mobile targets");
|
|
95
|
+
}
|
|
96
|
+
var options: Adapter.Options = .{
|
|
97
|
+
.name = manifest.name,
|
|
98
|
+
.scene = mobile_scene,
|
|
99
|
+
.canvas_label = native_sdk.embed.mobile_gpu_surface_label,
|
|
100
|
+
.markup = .{ .source = app_markup },
|
|
101
|
+
// app.zon's theme pack and one-accent override, same as desktop.
|
|
102
|
+
.theme = comptime manifestThemePack(),
|
|
103
|
+
.theme_accent = comptime manifestThemeAccent(),
|
|
104
|
+
};
|
|
105
|
+
if (comptime @hasDecl(core, "commandMsg")) {
|
|
106
|
+
// Projected chrome (tabs, primary action) dispatches through the
|
|
107
|
+
// core's exported command mapper.
|
|
108
|
+
options.on_command = core.commandMsg;
|
|
109
|
+
}
|
|
110
|
+
return Adapter.mobileOptions(coreOptions(), options);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn coreOptions() Adapter.CoreOptions {
|
|
114
|
+
freeEnvValueCopies();
|
|
115
|
+
var core_options: Adapter.CoreOptions = .{};
|
|
116
|
+
if (comptime use_pool) {
|
|
117
|
+
// The pool's own executor: mobile has no `std.process.Init` to
|
|
118
|
+
// thread an Io from. Nothing starts before the first real request,
|
|
119
|
+
// so constructing the pool here keeps replay semantics intact.
|
|
120
|
+
pool_io_state = std.Io.Threaded.init(std.heap.page_allocator, .{});
|
|
121
|
+
pool_transport = PoolTransport.init(
|
|
122
|
+
std.heap.page_allocator,
|
|
123
|
+
pool_io_state.io(),
|
|
124
|
+
"",
|
|
125
|
+
.{ .max_workers = service_carrier.pool_workers },
|
|
126
|
+
);
|
|
127
|
+
core_options.host_calls = pool_transport.binding();
|
|
128
|
+
}
|
|
129
|
+
if (comptime services.enabled) {
|
|
130
|
+
core_options.service_results = .{
|
|
131
|
+
.index_fn = services.indexOf,
|
|
132
|
+
.streaming_fn = services.isStreaming,
|
|
133
|
+
.decode_fn = services.resultDecoder(core),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
env_entry_count = 0;
|
|
137
|
+
data_root_env_count = 0;
|
|
138
|
+
if (comptime @hasDecl(core, "envMsgs")) {
|
|
139
|
+
inline for (core.envMsgs) |entry| {
|
|
140
|
+
if (comptime std.mem.eql(u8, entry.env, app_data_dir_env)) {
|
|
141
|
+
// The embed host installs the authoritative app-data path
|
|
142
|
+
// after mobileOptions(), before start. Keep its compacted
|
|
143
|
+
// slot so serviceDataRoot can fill it without trusting an
|
|
144
|
+
// ambient value for this reserved variable.
|
|
145
|
+
data_root_env_indices[data_root_env_count] = env_entry_count;
|
|
146
|
+
data_root_env_count += 1;
|
|
147
|
+
env_entries[env_entry_count] = .{ .msg = entry.msg, .value = "" };
|
|
148
|
+
env_entry_count += 1;
|
|
149
|
+
} else if (std.c.getenv(entry.env)) |value| {
|
|
150
|
+
// Snapshot the process value at launch, matching the desktop
|
|
151
|
+
// runner. Keep an owned copy because later setenv calls may
|
|
152
|
+
// invalidate getenv storage before the first installing frame.
|
|
153
|
+
if (std.heap.page_allocator.dupe(u8, std.mem.span(value))) |copy| {
|
|
154
|
+
env_value_copies[env_value_copy_count] = copy;
|
|
155
|
+
env_value_copy_count += 1;
|
|
156
|
+
env_entries[env_entry_count] = .{ .msg = entry.msg, .value = copy };
|
|
157
|
+
env_entry_count += 1;
|
|
158
|
+
} else |_| {}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
core_options.env_values = env_entries[0..env_entry_count];
|
|
163
|
+
return core_options;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// Embed-host hook (`native_sdk_app_set_data_root`, before start): the
|
|
167
|
+
/// OS-owned app-data directory. The pool's cooperative-cancellation
|
|
168
|
+
/// markers and stream-relay files move here — the one writable directory
|
|
169
|
+
/// both mobile sandboxes guarantee — and a core's `envMsgs` request for
|
|
170
|
+
/// the data directory resolves to it.
|
|
171
|
+
pub fn serviceDataRoot(root: []const u8) void {
|
|
172
|
+
// UiAppHost validates this against the same exported ABI limit before
|
|
173
|
+
// invoking the hook, so every accepted path fits whole.
|
|
174
|
+
std.debug.assert(root.len <= data_root_buffer.len);
|
|
175
|
+
@memcpy(data_root_buffer[0..root.len], root);
|
|
176
|
+
const installed = data_root_buffer[0..root.len];
|
|
177
|
+
if (comptime use_pool) pool_transport.cwd = installed;
|
|
178
|
+
// Keep the whole projection out of a serviceDataRoot instantiation when
|
|
179
|
+
// this core exports no envMsgs. Zig still analyzes a runtime loop body
|
|
180
|
+
// over a zero-length array, so relying on data_root_env_count == 0 would
|
|
181
|
+
// leave `env_entries[index]` as an illegal index into [0]EnvValue.
|
|
182
|
+
if (comptime envMsgsLen() > 0) {
|
|
183
|
+
for (data_root_env_indices[0..data_root_env_count]) |index| {
|
|
184
|
+
env_entries[index].value = installed;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// Embed-host hook (destroy): the pool's shutdown already ran through the
|
|
190
|
+
/// effects binding; this returns its queues and executor.
|
|
191
|
+
pub fn serviceTeardown() void {
|
|
192
|
+
if (comptime use_pool) {
|
|
193
|
+
pool_transport.deinit();
|
|
194
|
+
pool_io_state.deinit();
|
|
195
|
+
}
|
|
196
|
+
freeEnvValueCopies();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
fn freeEnvValueCopies() void {
|
|
200
|
+
for (env_value_copies[0..env_value_copy_count]) |copy| {
|
|
201
|
+
std.heap.page_allocator.free(copy);
|
|
202
|
+
}
|
|
203
|
+
env_value_copy_count = 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn envMsgsLen() usize {
|
|
207
|
+
comptime {
|
|
208
|
+
if (!@hasDecl(core, "envMsgs")) return 0;
|
|
209
|
+
return core.envMsgs.len;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/// app.zon's theme pack, resolved at comptime (the desktop runner's
|
|
214
|
+
/// `manifestThemePack`, restated here because the mobile module never
|
|
215
|
+
/// links the runner).
|
|
216
|
+
fn manifestThemePack() native_sdk.canvas.ThemePack {
|
|
217
|
+
if (comptime !@hasField(@TypeOf(manifest), "theme")) return .house;
|
|
218
|
+
const name: []const u8 = manifest.theme;
|
|
219
|
+
return comptime native_sdk.canvas.ThemePack.fromName(name) orelse
|
|
220
|
+
@compileError("unknown app.zon theme \"" ++ name ++ "\" — expected one of: house, geist");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/// app.zon's one-accent brand override, resolved at comptime (the desktop
|
|
224
|
+
/// runner's `manifestThemeAccent`).
|
|
225
|
+
fn manifestThemeAccent() ?native_sdk.canvas.Color {
|
|
226
|
+
if (comptime !@hasField(@TypeOf(manifest), "theme_accent")) return null;
|
|
227
|
+
const value: []const u8 = manifest.theme_accent;
|
|
228
|
+
return comptime parseHexColor(value) orelse
|
|
229
|
+
@compileError("invalid app.zon theme_accent \"" ++ value ++ "\" — expected a #rrggbb hex color");
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
fn parseHexColor(comptime value: []const u8) ?native_sdk.canvas.Color {
|
|
233
|
+
comptime {
|
|
234
|
+
if (value.len != 7 or value[0] != '#') return null;
|
|
235
|
+
var channels: [3]u8 = undefined;
|
|
236
|
+
for (&channels, 0..) |*channel, index| {
|
|
237
|
+
channel.* = std.fmt.parseInt(u8, value[1 + index * 2 .. 3 + index * 2], 16) catch return null;
|
|
238
|
+
}
|
|
239
|
+
return native_sdk.canvas.Color.rgb8(channels[0], channels[1], channels[2]);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const native_sdk = @import("native_sdk");
|
|
3
|
+
|
|
4
|
+
/// Apply the state-store lookup result at the one layer that can distinguish
|
|
5
|
+
/// an actual restore from a fresh launch with persistence merely enabled.
|
|
6
|
+
pub fn applySavedWindow(window: *native_sdk.WindowOptions, saved: ?native_sdk.WindowState) bool {
|
|
7
|
+
const state = saved orelse return false;
|
|
8
|
+
window.default_frame = state.frame;
|
|
9
|
+
window.initial_placement = .restored;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/// An omitted shell field must not erase the caller's direct-SDK fallback.
|
|
14
|
+
pub fn applyShellRestorePolicy(fallback: native_sdk.WindowRestorePolicy, declared: ?native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
|
|
15
|
+
return declared orelse fallback;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/// Only an authored shell origin overrides the caller's placement reason.
|
|
19
|
+
pub fn applyShellInitialPlacement(fallback: native_sdk.WindowInitialPlacement, has_explicit_origin: bool) native_sdk.WindowInitialPlacement {
|
|
20
|
+
return if (has_explicit_origin) .explicit else fallback;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test "fresh default-restoring window keeps default placement on a store miss" {
|
|
24
|
+
var window: native_sdk.WindowOptions = .{ .restore_state = true };
|
|
25
|
+
try std.testing.expect(!applySavedWindow(&window, null));
|
|
26
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.default, window.initial_placement);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test "fresh explicitly positioned window keeps explicit placement on a store miss" {
|
|
30
|
+
var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
|
|
31
|
+
try std.testing.expect(!applySavedWindow(&window, null));
|
|
32
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.explicit, window.initial_placement);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
test "state-store hit replaces the frame and marks it restored" {
|
|
36
|
+
var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
|
|
37
|
+
const frame = native_sdk.geometry.RectF.init(40, 60, 900, 640);
|
|
38
|
+
try std.testing.expect(applySavedWindow(&window, .{ .frame = frame }));
|
|
39
|
+
try std.testing.expectEqual(frame, window.default_frame);
|
|
40
|
+
try std.testing.expectEqual(native_sdk.WindowInitialPlacement.restored, window.initial_placement);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
test "omitted shell placement fields preserve direct runner fallbacks" {
|
|
44
|
+
try std.testing.expectEqual(
|
|
45
|
+
native_sdk.WindowRestorePolicy.center_on_primary,
|
|
46
|
+
applyShellRestorePolicy(.center_on_primary, null),
|
|
47
|
+
);
|
|
48
|
+
try std.testing.expectEqual(
|
|
49
|
+
native_sdk.WindowInitialPlacement.restored,
|
|
50
|
+
applyShellInitialPlacement(.restored, false),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test "authored shell placement fields override direct runner fallbacks" {
|
|
55
|
+
try std.testing.expectEqual(
|
|
56
|
+
native_sdk.WindowRestorePolicy.clamp_to_visible_screen,
|
|
57
|
+
applyShellRestorePolicy(.center_on_primary, .clamp_to_visible_screen),
|
|
58
|
+
);
|
|
59
|
+
try std.testing.expectEqual(
|
|
60
|
+
native_sdk.WindowInitialPlacement.explicit,
|
|
61
|
+
applyShellInitialPlacement(.restored, true),
|
|
62
|
+
);
|
|
63
|
+
}
|
|
@@ -51,7 +51,11 @@ pub const fingerprint: u64 = layout_fingerprint.hash(layoutDescription(semantic_
|
|
|
51
51
|
/// enum). Declared-shape changes — new verbs, renamed actions, budget
|
|
52
52
|
/// or naming changes — need NO action here: the fingerprint moves on
|
|
53
53
|
/// its own.
|
|
54
|
-
|
|
54
|
+
/// Epoch 2: status-item snapshots gained stable item identifiers and
|
|
55
|
+
/// visibility, and `tray-action` gained the explicit
|
|
56
|
+
/// `<status-item-id> <menu-item-id>` form (the old one-id primary-item
|
|
57
|
+
/// shorthand remains valid).
|
|
58
|
+
pub const semantic_epoch: u32 = 2;
|
|
55
59
|
|
|
56
60
|
/// The canonical description the protocol fingerprint hashes: the
|
|
57
61
|
/// command vocabulary (the `Action` enum, reflected — names and values,
|