@native-sdk/cli 0.8.2 → 0.8.4
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 +50 -3
- package/build.zig +134 -360
- package/native-sdk.d.ts +4 -0
- package/package.json +9 -9
- package/packages/core/compile-surface/core.ts +90 -1
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.d.ts +65 -2
- package/packages/core/sdk/core.ts +189 -33
- package/packages/core/sdk/events.d.ts +14 -0
- package/packages/core/sdk/events.ts +18 -0
- package/packages/core/src/checker.ts +61 -1
- package/packages/core/src/devhost.ts +3 -3
- package/packages/core/src/diagnostics.ts +4 -4
- package/skill-data/core/SKILL.md +4 -2
- package/skill-data/core/references/project-anatomy.md +2 -1
- package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
- package/skill-data/native-ui/SKILL.md +8 -8
- package/skill-data/ts-core/SKILL.md +16 -13
- package/src/app_runner/app_assets.zig +138 -0
- package/src/app_runner/root.zig +2 -0
- package/src/app_runner/ts_core_main.zig +27 -3
- package/src/embed/host.zig +6 -0
- package/src/embed/ui_host.zig +2 -0
- package/src/platform/linux/root.zig +1 -0
- package/src/platform/macos/appkit_host.h +10 -0
- package/src/platform/macos/appkit_host.m +515 -93
- package/src/platform/macos/capture_info_plist.c +25 -0
- package/src/platform/macos/cef_host.mm +22 -0
- package/src/platform/macos/root.zig +68 -0
- package/src/platform/null_platform.zig +58 -0
- package/src/platform/root.zig +7 -0
- package/src/platform/types.zig +100 -0
- package/src/platform/windows/root.zig +56 -0
- package/src/platform/windows/webview2_host.cpp +171 -0
- package/src/primitives/app_manifest/types.zig +2 -0
- 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 +321 -115
- package/src/primitives/canvas/widget_runtime_tests.zig +173 -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 +41 -5
- package/src/root.zig +10 -0
- package/src/runtime/automation_widget_dispatch.zig +1 -0
- package/src/runtime/bridge_payload.zig +2 -0
- package/src/runtime/canvas_frame.zig +13 -2
- 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_event_tests.zig +1 -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 +10 -1
- package/src/runtime/canvas_widget_text_tests.zig +112 -3
- package/src/runtime/effects.zig +313 -2
- package/src/runtime/effects_audio_capture_tests.zig +251 -0
- package/src/runtime/root.zig +3 -0
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +401 -32
- package/src/runtime/ts_core_host_tests.zig +407 -0
- package/src/runtime/ts_ui_app.zig +39 -1
- package/src/runtime/ui_app.zig +18 -3
- package/src/runtime/ui_app_tests.zig +48 -0
- package/src/runtime/view.zig +2 -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/tooling/manifest.zig +1034 -0
- package/src/tooling/package.zig +841 -10
- package/src/tooling/raw_manifest.zig +35 -0
- package/src/tooling/templates.zig +55 -0
- package/tools/corewire/emit_facade.zig +36 -0
package/src/tooling/package.zig
CHANGED
|
@@ -62,6 +62,9 @@ pub const PackageOptions = struct {
|
|
|
62
62
|
target: PackageTarget = .macos,
|
|
63
63
|
optimize: []const u8 = "Debug",
|
|
64
64
|
output_path: []const u8,
|
|
65
|
+
/// Project root used to resolve app.zon-relative packaging inputs such
|
|
66
|
+
/// as a custom DMG background. The CLI derives it from --manifest.
|
|
67
|
+
project_dir: []const u8 = ".",
|
|
65
68
|
binary_path: ?[]const u8 = null,
|
|
66
69
|
assets_dir: []const u8 = "assets",
|
|
67
70
|
frontend: ?manifest_tool.FrontendMetadata = null,
|
|
@@ -162,6 +165,16 @@ pub fn createPackage(allocator: std.mem.Allocator, io: std.Io, options: PackageO
|
|
|
162
165
|
return err;
|
|
163
166
|
};
|
|
164
167
|
try validateWebEngineTarget(options.target, options.web_engine);
|
|
168
|
+
if (options.target == .macos and options.archive) {
|
|
169
|
+
manifest_tool.validateDmgPackageSettings(options.metadata) catch |err| {
|
|
170
|
+
std.debug.print("error: app.zon dmg settings are invalid ({s})\n", .{@errorName(err)});
|
|
171
|
+
return err;
|
|
172
|
+
};
|
|
173
|
+
if (try manifest_tool.checkDmgSources(allocator, io, options.project_dir, options.metadata.dmg)) |message| {
|
|
174
|
+
std.debug.print("error: {s}\n", .{message});
|
|
175
|
+
return error.InvalidDmgSource;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
165
178
|
var stats = switch (options.target) {
|
|
166
179
|
.macos => try createMacosApp(allocator, io, options),
|
|
167
180
|
.windows, .linux => try createDesktopArtifact(allocator, io, options),
|
|
@@ -623,10 +636,10 @@ fn assetOutputPath(allocator: std.mem.Allocator, output_path: []const u8, resour
|
|
|
623
636
|
/// app-relative path — Resources/assets by default — so a relative asset
|
|
624
637
|
/// path the app uses at runtime ("assets/music/track.mp3") names the
|
|
625
638
|
/// same file inside the bundle that it names in a dev run: the packaged
|
|
626
|
-
/// macOS host
|
|
627
|
-
/// absolute or parent-escaping --assets directory has no
|
|
628
|
-
/// meaning a packaged process could resolve, so it keeps the
|
|
629
|
-
/// Resources layout.
|
|
639
|
+
/// generated runner and macOS host resolve relative asset paths against
|
|
640
|
+
/// Resources. An absolute or parent-escaping --assets directory has no
|
|
641
|
+
/// app-relative meaning a packaged process could resolve, so it keeps the
|
|
642
|
+
/// flat Resources layout.
|
|
630
643
|
fn macosAssetOutputPath(allocator: std.mem.Allocator, options: PackageOptions) ![]const u8 {
|
|
631
644
|
if (options.frontend != null) return assetOutputPath(allocator, options.output_path, "Contents/Resources", options);
|
|
632
645
|
if (appRelativeAssetSubpath(options.assets_dir)) |subpath| {
|
|
@@ -666,6 +679,8 @@ fn macosInfoPlist(allocator: std.mem.Allocator, metadata: manifest_tool.Metadata
|
|
|
666
679
|
defer allocator.free(document_types);
|
|
667
680
|
const url_types = try macosUrlTypes(allocator, metadata);
|
|
668
681
|
defer allocator.free(url_types);
|
|
682
|
+
const privacy_descriptions = try macosPrivacyUsageDescriptions(allocator, metadata);
|
|
683
|
+
defer allocator.free(privacy_descriptions);
|
|
669
684
|
// The About panel's bottom line in packaged bundles: the manifest
|
|
670
685
|
// description rides NSHumanReadableCopyright, the plist key the
|
|
671
686
|
// standard About panel renders as its footer text — the same line
|
|
@@ -702,11 +717,51 @@ fn macosInfoPlist(allocator: std.mem.Allocator, metadata: manifest_tool.Metadata
|
|
|
702
717
|
\\ <string>{s}</string>
|
|
703
718
|
\\ <key>CFBundleVersion</key>
|
|
704
719
|
\\ <string>{s}</string>
|
|
705
|
-
\\{s}{s}{s}
|
|
720
|
+
\\{s}{s}{s}{s}
|
|
706
721
|
\\</dict>
|
|
707
722
|
\\</plist>
|
|
708
723
|
\\
|
|
709
|
-
, .{ bundle_id, display_name, display_name, executable, icon, version, version, about_line, document_types, url_types });
|
|
724
|
+
, .{ bundle_id, display_name, display_name, executable, icon, version, version, about_line, privacy_descriptions, document_types, url_types });
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
fn metadataHasPermission(metadata: manifest_tool.Metadata, name: []const u8) bool {
|
|
728
|
+
for (metadata.permissions) |permission| {
|
|
729
|
+
if (std.mem.eql(u8, permission, name)) return true;
|
|
730
|
+
}
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
/// Privacy usage strings are generated from the manifest's explicit capture
|
|
735
|
+
/// permissions. ScreenCaptureKit historically uses the screen-recording
|
|
736
|
+
/// consent surface for desktop audio; newer macOS also recognizes the
|
|
737
|
+
/// audio-only usage key, so system capture declares both.
|
|
738
|
+
fn macosPrivacyUsageDescriptions(allocator: std.mem.Allocator, metadata: manifest_tool.Metadata) ![]const u8 {
|
|
739
|
+
const microphone = metadataHasPermission(metadata, "microphone");
|
|
740
|
+
const system_audio = metadataHasPermission(metadata, "system_audio");
|
|
741
|
+
if (!microphone and !system_audio) return allocator.dupe(u8, "");
|
|
742
|
+
const display_name = try xmlEscapeAlloc(allocator, metadata.displayName());
|
|
743
|
+
defer allocator.free(display_name);
|
|
744
|
+
if (microphone and system_audio) return std.fmt.allocPrint(allocator,
|
|
745
|
+
\\ <key>NSMicrophoneUsageDescription</key>
|
|
746
|
+
\\ <string>{s} captures microphone audio when you start recording.</string>
|
|
747
|
+
\\ <key>NSAudioCaptureUsageDescription</key>
|
|
748
|
+
\\ <string>{s} captures system audio when you start recording.</string>
|
|
749
|
+
\\ <key>NSScreenCaptureUsageDescription</key>
|
|
750
|
+
\\ <string>{s} captures system audio when you start recording.</string>
|
|
751
|
+
\\
|
|
752
|
+
, .{ display_name, display_name, display_name });
|
|
753
|
+
if (microphone) return std.fmt.allocPrint(allocator,
|
|
754
|
+
\\ <key>NSMicrophoneUsageDescription</key>
|
|
755
|
+
\\ <string>{s} captures microphone audio when you start recording.</string>
|
|
756
|
+
\\
|
|
757
|
+
, .{display_name});
|
|
758
|
+
return std.fmt.allocPrint(allocator,
|
|
759
|
+
\\ <key>NSAudioCaptureUsageDescription</key>
|
|
760
|
+
\\ <string>{s} captures system audio when you start recording.</string>
|
|
761
|
+
\\ <key>NSScreenCaptureUsageDescription</key>
|
|
762
|
+
\\ <string>{s} captures system audio when you start recording.</string>
|
|
763
|
+
\\
|
|
764
|
+
, .{ display_name, display_name });
|
|
710
765
|
}
|
|
711
766
|
|
|
712
767
|
/// The optional NSHumanReadableCopyright entry (with trailing newline)
|
|
@@ -1960,20 +2015,492 @@ fn createArchive(allocator: std.mem.Allocator, io: std.Io, options: PackageOptio
|
|
|
1960
2015
|
defer allocator.free(archive_command_path);
|
|
1961
2016
|
|
|
1962
2017
|
const ok = switch (options.target) {
|
|
1963
|
-
.macos =>
|
|
2018
|
+
.macos => try createMacosDmg(allocator, io, options, archive_command_path),
|
|
1964
2019
|
.windows => runArchiveCommand(io, &.{ "zip", "-r", archive_command_path, "." }, options.output_path),
|
|
1965
2020
|
.linux => runArchiveCommand(io, &.{ "tar", "czf", archive_command_path, "-C", options.output_path, "." }, null),
|
|
1966
2021
|
.ios, .android => unreachable,
|
|
1967
2022
|
};
|
|
1968
2023
|
|
|
1969
2024
|
if (!ok) {
|
|
1970
|
-
std.debug.print("
|
|
1971
|
-
|
|
1972
|
-
return null;
|
|
2025
|
+
std.debug.print("error: archive creation failed for {s}\n", .{archive_path});
|
|
2026
|
+
return error.ArchiveCreationFailed;
|
|
1973
2027
|
}
|
|
1974
2028
|
return archive_path;
|
|
1975
2029
|
}
|
|
1976
2030
|
|
|
2031
|
+
/// Build the familiar macOS drag-to-Applications image without introducing a
|
|
2032
|
+
/// package-time dependency. A writable image is populated first so Finder can
|
|
2033
|
+
/// persist its icon-view presentation, then converted to the compressed UDZO
|
|
2034
|
+
/// artifact users download. If Finder automation is unavailable (for example
|
|
2035
|
+
/// in a headless build worker), the Applications link and background still
|
|
2036
|
+
/// ship and only the saved window arrangement is omitted.
|
|
2037
|
+
fn createMacosDmg(allocator: std.mem.Allocator, io: std.Io, options: PackageOptions, archive_path: []const u8) !bool {
|
|
2038
|
+
const dmg = options.metadata.dmg;
|
|
2039
|
+
const volume_name = dmg.volume_name orelse options.metadata.displayName();
|
|
2040
|
+
var nonce_bytes: [8]u8 = undefined;
|
|
2041
|
+
std.Io.random(io, &nonce_bytes);
|
|
2042
|
+
const nonce = std.mem.readInt(u64, &nonce_bytes, .little);
|
|
2043
|
+
const work_path = try std.fmt.allocPrint(allocator, "{s}.native-work-{x}", .{ archive_path, nonce });
|
|
2044
|
+
defer allocator.free(work_path);
|
|
2045
|
+
const work_absolute = try absolutePathAlloc(allocator, io, work_path);
|
|
2046
|
+
defer allocator.free(work_absolute);
|
|
2047
|
+
const rw_image_path = try std.fs.path.join(allocator, &.{ work_absolute, "staging.dmg" });
|
|
2048
|
+
defer allocator.free(rw_image_path);
|
|
2049
|
+
const source_path = try std.fs.path.join(allocator, &.{ work_absolute, "source" });
|
|
2050
|
+
defer allocator.free(source_path);
|
|
2051
|
+
const mount_path = try std.fs.path.join(allocator, &.{ work_absolute, "mount" });
|
|
2052
|
+
defer allocator.free(mount_path);
|
|
2053
|
+
const app_path = try absolutePathAlloc(allocator, io, options.output_path);
|
|
2054
|
+
defer allocator.free(app_path);
|
|
2055
|
+
|
|
2056
|
+
var cwd = std.Io.Dir.cwd();
|
|
2057
|
+
try cwd.createDirPath(io, work_path);
|
|
2058
|
+
var work_dir = try cwd.openDir(io, work_path, .{});
|
|
2059
|
+
defer work_dir.close(io);
|
|
2060
|
+
try work_dir.createDirPath(io, "source");
|
|
2061
|
+
try work_dir.createDirPath(io, "mount");
|
|
2062
|
+
|
|
2063
|
+
var attached = false;
|
|
2064
|
+
defer {
|
|
2065
|
+
if (attached) {
|
|
2066
|
+
if (runArchiveCommand(io, &.{ "hdiutil", "detach", "-quiet", mount_path }, null) or
|
|
2067
|
+
runArchiveCommand(io, &.{ "hdiutil", "detach", "-quiet", "-force", mount_path }, null))
|
|
2068
|
+
{
|
|
2069
|
+
attached = false;
|
|
2070
|
+
} else {
|
|
2071
|
+
std.debug.print("warning: could not detach temporary DMG at {s}; leaving {s} for manual cleanup\n", .{ mount_path, work_path });
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
if (!attached) cwd.deleteTree(io, work_path) catch {};
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
const app_name = try dmgAppBundleNameAlloc(allocator, options.metadata);
|
|
2078
|
+
defer allocator.free(app_name);
|
|
2079
|
+
var source_dir = try cwd.openDir(io, source_path, .{});
|
|
2080
|
+
defer source_dir.close(io);
|
|
2081
|
+
try stageDmgItems(allocator, io, options, source_dir, source_path, app_path, app_name);
|
|
2082
|
+
|
|
2083
|
+
const retina_background_source = try dmgRetinaBackgroundSourceAlloc(allocator, io, options.project_dir, dmg.background);
|
|
2084
|
+
defer if (retina_background_source) |path| allocator.free(path);
|
|
2085
|
+
const background_name = try dmgBackgroundNameAlloc(allocator, dmg.background, retina_background_source != null);
|
|
2086
|
+
defer allocator.free(background_name);
|
|
2087
|
+
try stageDmgBackground(allocator, io, options, source_dir, source_path, background_name, retina_background_source);
|
|
2088
|
+
|
|
2089
|
+
// Finder persists portable window presentation in the volume's
|
|
2090
|
+
// `.DS_Store` on HFS+. With hdiutil's current APFS default, the same
|
|
2091
|
+
// successful AppleScript can leave no metadata in the image at all.
|
|
2092
|
+
if (!runArchiveCommand(io, &.{ "hdiutil", "create", "-quiet", "-volname", volume_name, "-srcfolder", source_path, "-ov", "-format", "UDRW", "-fs", "HFS+", rw_image_path }, null)) return false;
|
|
2093
|
+
if (!runArchiveCommand(io, &.{ "hdiutil", "attach", "-quiet", rw_image_path, "-mountpoint", mount_path, "-nobrowse", "-noverify", "-noautoopen" }, null)) return false;
|
|
2094
|
+
attached = true;
|
|
2095
|
+
|
|
2096
|
+
const finder_script = try dmgFinderScriptAlloc(allocator, dmg, mount_path, app_name, background_name);
|
|
2097
|
+
defer allocator.free(finder_script);
|
|
2098
|
+
if (!runArchiveCommand(io, &.{ "osascript", "-e", finder_script }, null)) {
|
|
2099
|
+
std.debug.print("warning: Finder could not save the DMG window layout; the image still includes its configured items and background\n", .{});
|
|
2100
|
+
} else if (!try waitForDmgFinderMetadata(allocator, io, mount_path)) {
|
|
2101
|
+
std.debug.print("warning: Finder returned success but did not persist the DMG window layout; the image still includes its configured items and background\n", .{});
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
if (!runArchiveCommand(io, &.{ "hdiutil", "detach", "-quiet", mount_path }, null)) {
|
|
2105
|
+
if (!runArchiveCommand(io, &.{ "hdiutil", "detach", "-quiet", "-force", mount_path }, null)) return false;
|
|
2106
|
+
}
|
|
2107
|
+
attached = false;
|
|
2108
|
+
return runArchiveCommand(io, &.{ "hdiutil", "convert", "-quiet", rw_image_path, "-ov", "-format", "UDZO", "-imagekey", "zlib-level=9", "-o", archive_path }, null);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
fn dmgAppBundleNameAlloc(allocator: std.mem.Allocator, metadata: manifest_tool.Metadata) ![]u8 {
|
|
2112
|
+
var buffer: [255]u8 = undefined;
|
|
2113
|
+
return allocator.dupe(u8, try manifest_tool.dmgAppBundleName(&buffer, metadata));
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
fn stageDmgItems(
|
|
2117
|
+
allocator: std.mem.Allocator,
|
|
2118
|
+
io: std.Io,
|
|
2119
|
+
options: PackageOptions,
|
|
2120
|
+
source_dir: std.Io.Dir,
|
|
2121
|
+
source_path: []const u8,
|
|
2122
|
+
app_path: []const u8,
|
|
2123
|
+
app_name: []const u8,
|
|
2124
|
+
) !void {
|
|
2125
|
+
const app_destination = try std.fs.path.join(allocator, &.{ source_path, app_name });
|
|
2126
|
+
defer allocator.free(app_destination);
|
|
2127
|
+
if (!runArchiveCommand(io, &.{ "ditto", app_path, app_destination }, null)) {
|
|
2128
|
+
std.debug.print("error: packaged app could not be staged in the DMG\n", .{});
|
|
2129
|
+
return error.DmgItemCopyFailed;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
const dmg = options.metadata.dmg;
|
|
2133
|
+
if (dmg.items.len == 0) {
|
|
2134
|
+
if (dmg.applications_link) try source_dir.symLink(io, "/Applications", "Applications", .{ .is_directory = true });
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
for (dmg.items) |item| switch (item.kind) {
|
|
2139
|
+
.app => {},
|
|
2140
|
+
.applications => try source_dir.symLink(io, "/Applications", "Applications", .{ .is_directory = true }),
|
|
2141
|
+
.file => {
|
|
2142
|
+
const item_path = item.path orelse return error.InvalidDmgItem;
|
|
2143
|
+
const item_name = manifest_tool.dmgItemDestinationName(item) orelse return error.InvalidDmgItem;
|
|
2144
|
+
if (std.ascii.eqlIgnoreCase(item_name, app_name)) {
|
|
2145
|
+
std.debug.print("error: DMG item {s} conflicts with the packaged app name\n", .{item_name});
|
|
2146
|
+
return error.DuplicateDmgItem;
|
|
2147
|
+
}
|
|
2148
|
+
const item_source = try std.fs.path.join(allocator, &.{ options.project_dir, item_path });
|
|
2149
|
+
defer allocator.free(item_source);
|
|
2150
|
+
const item_destination = try std.fs.path.join(allocator, &.{ source_path, item_name });
|
|
2151
|
+
defer allocator.free(item_destination);
|
|
2152
|
+
if (!runArchiveCommand(io, &.{ "ditto", item_source, item_destination }, null)) {
|
|
2153
|
+
std.debug.print("error: DMG item {s} could not be copied from {s}\n", .{ item_name, item_source });
|
|
2154
|
+
return error.DmgItemCopyFailed;
|
|
2155
|
+
}
|
|
2156
|
+
},
|
|
2157
|
+
.link => {
|
|
2158
|
+
const target = item.path orelse return error.InvalidDmgItem;
|
|
2159
|
+
const item_name = manifest_tool.dmgItemDestinationName(item) orelse return error.InvalidDmgItem;
|
|
2160
|
+
if (std.ascii.eqlIgnoreCase(item_name, app_name)) {
|
|
2161
|
+
std.debug.print("error: DMG item {s} conflicts with the packaged app name\n", .{item_name});
|
|
2162
|
+
return error.DuplicateDmgItem;
|
|
2163
|
+
}
|
|
2164
|
+
try source_dir.symLink(io, target, item_name, .{ .is_directory = true });
|
|
2165
|
+
},
|
|
2166
|
+
};
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
fn dmgRetinaBackgroundSourceAlloc(allocator: std.mem.Allocator, io: std.Io, project_dir: []const u8, background: ?[]const u8) !?[]const u8 {
|
|
2170
|
+
const path = background orelse return null;
|
|
2171
|
+
const retina_relative = (try manifest_tool.dmgRetinaRelativePathAlloc(allocator, path)) orelse return null;
|
|
2172
|
+
defer allocator.free(retina_relative);
|
|
2173
|
+
const retina_source = try std.fs.path.join(allocator, &.{ project_dir, retina_relative });
|
|
2174
|
+
errdefer allocator.free(retina_source);
|
|
2175
|
+
var file = std.Io.Dir.cwd().openFile(io, retina_source, .{}) catch {
|
|
2176
|
+
allocator.free(retina_source);
|
|
2177
|
+
return null;
|
|
2178
|
+
};
|
|
2179
|
+
file.close(io);
|
|
2180
|
+
return retina_source;
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
fn stageDmgBackground(
|
|
2184
|
+
allocator: std.mem.Allocator,
|
|
2185
|
+
io: std.Io,
|
|
2186
|
+
options: PackageOptions,
|
|
2187
|
+
source_dir: std.Io.Dir,
|
|
2188
|
+
source_path: []const u8,
|
|
2189
|
+
background_name: []const u8,
|
|
2190
|
+
retina_background_source: ?[]const u8,
|
|
2191
|
+
) !void {
|
|
2192
|
+
const dmg = options.metadata.dmg;
|
|
2193
|
+
try source_dir.createDirPath(io, ".background");
|
|
2194
|
+
const output_path = try std.fs.path.join(allocator, &.{ source_path, ".background", background_name });
|
|
2195
|
+
defer allocator.free(output_path);
|
|
2196
|
+
|
|
2197
|
+
if (dmg.background) |background| {
|
|
2198
|
+
const background_source = try std.fs.path.join(allocator, &.{ options.project_dir, background });
|
|
2199
|
+
defer allocator.free(background_source);
|
|
2200
|
+
if (retina_background_source) |retina_source| {
|
|
2201
|
+
const extension = std.fs.path.extension(background);
|
|
2202
|
+
const one_x_name = try std.fmt.allocPrint(allocator, "background{s}", .{extension});
|
|
2203
|
+
defer allocator.free(one_x_name);
|
|
2204
|
+
const two_x_name = try std.fmt.allocPrint(allocator, "background@2x{s}", .{extension});
|
|
2205
|
+
defer allocator.free(two_x_name);
|
|
2206
|
+
const one_x_subpath = try std.fs.path.join(allocator, &.{ ".background", one_x_name });
|
|
2207
|
+
defer allocator.free(one_x_subpath);
|
|
2208
|
+
const two_x_subpath = try std.fs.path.join(allocator, &.{ ".background", two_x_name });
|
|
2209
|
+
defer allocator.free(two_x_subpath);
|
|
2210
|
+
try std.Io.Dir.copyFile(std.Io.Dir.cwd(), background_source, source_dir, one_x_subpath, io, .{ .make_path = true, .replace = true });
|
|
2211
|
+
try std.Io.Dir.copyFile(std.Io.Dir.cwd(), retina_source, source_dir, two_x_subpath, io, .{ .make_path = true, .replace = true });
|
|
2212
|
+
const one_x_path = try std.fs.path.join(allocator, &.{ source_path, one_x_subpath });
|
|
2213
|
+
defer allocator.free(one_x_path);
|
|
2214
|
+
const two_x_path = try std.fs.path.join(allocator, &.{ source_path, two_x_subpath });
|
|
2215
|
+
defer allocator.free(two_x_path);
|
|
2216
|
+
try assembleRetinaDmgBackground(io, one_x_path, two_x_path, output_path, "custom");
|
|
2217
|
+
try source_dir.deleteFile(io, one_x_subpath);
|
|
2218
|
+
try source_dir.deleteFile(io, two_x_subpath);
|
|
2219
|
+
} else {
|
|
2220
|
+
const output_subpath = try std.fs.path.join(allocator, &.{ ".background", background_name });
|
|
2221
|
+
defer allocator.free(output_subpath);
|
|
2222
|
+
try std.Io.Dir.copyFile(std.Io.Dir.cwd(), background_source, source_dir, output_subpath, io, .{ .make_path = true, .replace = true });
|
|
2223
|
+
}
|
|
2224
|
+
return;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
const generated_1x = try defaultDmgBackgroundAtScale(allocator, dmg, 1);
|
|
2228
|
+
defer allocator.free(generated_1x);
|
|
2229
|
+
const generated_2x = try defaultDmgBackgroundAtScale(allocator, dmg, 2);
|
|
2230
|
+
defer allocator.free(generated_2x);
|
|
2231
|
+
try source_dir.writeFile(io, .{ .sub_path = ".background/background.png", .data = generated_1x });
|
|
2232
|
+
try source_dir.writeFile(io, .{ .sub_path = ".background/background@2x.png", .data = generated_2x });
|
|
2233
|
+
const one_x_path = try std.fs.path.join(allocator, &.{ source_path, ".background", "background.png" });
|
|
2234
|
+
defer allocator.free(one_x_path);
|
|
2235
|
+
const two_x_path = try std.fs.path.join(allocator, &.{ source_path, ".background", "background@2x.png" });
|
|
2236
|
+
defer allocator.free(two_x_path);
|
|
2237
|
+
try assembleRetinaDmgBackground(io, one_x_path, two_x_path, output_path, "generated");
|
|
2238
|
+
try source_dir.deleteFile(io, ".background/background.png");
|
|
2239
|
+
try source_dir.deleteFile(io, ".background/background@2x.png");
|
|
2240
|
+
}
|
|
2241
|
+
|
|
2242
|
+
fn assembleRetinaDmgBackground(io: std.Io, one_x_path: []const u8, two_x_path: []const u8, output_path: []const u8, kind: []const u8) !void {
|
|
2243
|
+
if (!runArchiveCommandQuiet(io, &.{ "tiffutil", "-cathidpicheck", one_x_path, two_x_path, "-out", output_path }, null)) {
|
|
2244
|
+
std.debug.print("error: could not assemble the {s} 1x/2x DMG background with tiffutil; the @2x image must be exactly twice the base image's dimensions\n", .{kind});
|
|
2245
|
+
return error.DmgBackgroundAssemblyFailed;
|
|
2246
|
+
}
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
fn dmgBackgroundNameAlloc(allocator: std.mem.Allocator, background: ?[]const u8, has_retina_sibling: bool) ![]const u8 {
|
|
2250
|
+
const extension = if (background) |path| if (has_retina_sibling) ".tiff" else std.fs.path.extension(path) else ".tiff";
|
|
2251
|
+
return std.fmt.allocPrint(allocator, "background{s}", .{extension});
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
fn defaultDmgBackground(allocator: std.mem.Allocator, dmg: manifest_tool.DmgMetadata) ![]u8 {
|
|
2255
|
+
return defaultDmgBackgroundAtScale(allocator, dmg, 1);
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
fn defaultDmgBackgroundAtScale(allocator: std.mem.Allocator, dmg: manifest_tool.DmgMetadata, scale: usize) ![]u8 {
|
|
2259
|
+
std.debug.assert(scale > 0);
|
|
2260
|
+
const width: usize = @as(usize, dmg.window_width) * scale;
|
|
2261
|
+
const height: usize = @as(usize, dmg.window_height) * scale;
|
|
2262
|
+
const pixels = try allocator.alloc(u8, width * height * 4);
|
|
2263
|
+
defer allocator.free(pixels);
|
|
2264
|
+
|
|
2265
|
+
for (0..height) |y| {
|
|
2266
|
+
const t = if (height > 1) @as(f32, @floatFromInt(y)) / @as(f32, @floatFromInt(height - 1)) else 0;
|
|
2267
|
+
const shade = [3]u8{
|
|
2268
|
+
@intFromFloat(@round(249.0 - 11.0 * t)),
|
|
2269
|
+
@intFromFloat(@round(250.0 - 11.0 * t)),
|
|
2270
|
+
@intFromFloat(@round(252.0 - 10.0 * t)),
|
|
2271
|
+
};
|
|
2272
|
+
for (0..width) |x| {
|
|
2273
|
+
const offset = (y * width + x) * 4;
|
|
2274
|
+
pixels[offset + 0] = shade[0];
|
|
2275
|
+
pixels[offset + 1] = shade[1];
|
|
2276
|
+
pixels[offset + 2] = shade[2];
|
|
2277
|
+
pixels[offset + 3] = 255;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
if (dmgInstallPositions(dmg) != null) drawDmgArrow(pixels, width, height, dmg, scale);
|
|
2282
|
+
return app_icon_tool.encodePng(allocator, pixels, width, height);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
fn drawDmgArrow(pixels: []u8, width: usize, height: usize, dmg: manifest_tool.DmgMetadata, scale: usize) void {
|
|
2286
|
+
const install_positions = dmgInstallPositions(dmg) orelse return;
|
|
2287
|
+
const pixel_scale: f32 = @floatFromInt(scale);
|
|
2288
|
+
const app_x = @as(f32, @floatFromInt(install_positions.app.x)) * pixel_scale;
|
|
2289
|
+
const app_y = @as(f32, @floatFromInt(install_positions.app.y)) * pixel_scale;
|
|
2290
|
+
const applications_x = @as(f32, @floatFromInt(install_positions.applications.x)) * pixel_scale;
|
|
2291
|
+
const applications_y = @as(f32, @floatFromInt(install_positions.applications.y)) * pixel_scale;
|
|
2292
|
+
const dx = applications_x - app_x;
|
|
2293
|
+
const dy = applications_y - app_y;
|
|
2294
|
+
const distance = @sqrt(dx * dx + dy * dy);
|
|
2295
|
+
const app_margin = @as(f32, @floatFromInt(dmg.icon_size)) * pixel_scale * 0.64;
|
|
2296
|
+
// Finder's Applications folder glyph is optically wider than a typical
|
|
2297
|
+
// app glyph at the same icon-size setting. Give that end a little more
|
|
2298
|
+
// breathing room so the arrow reads centered between visible edges.
|
|
2299
|
+
const applications_margin = @as(f32, @floatFromInt(dmg.icon_size)) * pixel_scale * 0.71;
|
|
2300
|
+
if (distance <= app_margin + applications_margin + 28.0 * pixel_scale) return;
|
|
2301
|
+
const ux = dx / distance;
|
|
2302
|
+
const uy = dy / distance;
|
|
2303
|
+
const px = -uy;
|
|
2304
|
+
const py = ux;
|
|
2305
|
+
const start_x = app_x + ux * app_margin;
|
|
2306
|
+
const start_y = app_y + uy * app_margin;
|
|
2307
|
+
const end_x = applications_x - ux * applications_margin;
|
|
2308
|
+
const end_y = applications_y - uy * applications_margin;
|
|
2309
|
+
const head_length: f32 = @min(28.0 * pixel_scale, distance * 0.12);
|
|
2310
|
+
const head_width: f32 = head_length * 0.62;
|
|
2311
|
+
const head_x = end_x - ux * head_length;
|
|
2312
|
+
const head_y = end_y - uy * head_length;
|
|
2313
|
+
|
|
2314
|
+
const segments = [3]DmgArrowSegment{
|
|
2315
|
+
.{ .ax = start_x, .ay = start_y, .bx = end_x, .by = end_y },
|
|
2316
|
+
.{ .ax = end_x, .ay = end_y, .bx = head_x + px * head_width, .by = head_y + py * head_width },
|
|
2317
|
+
.{ .ax = end_x, .ay = end_y, .bx = head_x - px * head_width, .by = head_y - py * head_width },
|
|
2318
|
+
};
|
|
2319
|
+
var shadow_segments = segments;
|
|
2320
|
+
for (&shadow_segments) |*segment| {
|
|
2321
|
+
segment.ay += 2 * pixel_scale;
|
|
2322
|
+
segment.by += 2 * pixel_scale;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2325
|
+
const shadow = [3]u8{ 70, 74, 82 };
|
|
2326
|
+
drawDmgArrowShape(pixels, width, height, &shadow_segments, 8 * pixel_scale, shadow, 0.10);
|
|
2327
|
+
|
|
2328
|
+
const arrow = [3]u8{ 105, 110, 120 };
|
|
2329
|
+
drawDmgArrowShape(pixels, width, height, &segments, 5 * pixel_scale, arrow, 0.58);
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
const DmgInstallPositions = struct {
|
|
2333
|
+
app: manifest_tool.DmgPosition,
|
|
2334
|
+
applications: manifest_tool.DmgPosition,
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2337
|
+
fn dmgInstallPositions(dmg: manifest_tool.DmgMetadata) ?DmgInstallPositions {
|
|
2338
|
+
if (dmg.items.len == 0) {
|
|
2339
|
+
if (!dmg.applications_link) return null;
|
|
2340
|
+
return .{ .app = dmg.app_position, .applications = dmg.applications_position };
|
|
2341
|
+
}
|
|
2342
|
+
var app: ?manifest_tool.DmgPosition = null;
|
|
2343
|
+
var applications: ?manifest_tool.DmgPosition = null;
|
|
2344
|
+
for (dmg.items) |item| switch (item.kind) {
|
|
2345
|
+
.app => app = item.position,
|
|
2346
|
+
.applications => applications = item.position,
|
|
2347
|
+
.file, .link => {},
|
|
2348
|
+
};
|
|
2349
|
+
return .{ .app = app orelse return null, .applications = applications orelse return null };
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2352
|
+
const DmgArrowSegment = struct {
|
|
2353
|
+
ax: f32,
|
|
2354
|
+
ay: f32,
|
|
2355
|
+
bx: f32,
|
|
2356
|
+
by: f32,
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2359
|
+
/// Rasterize the union of rounded line segments and blend it once. Taking the
|
|
2360
|
+
/// maximum coverage prevents translucent joins from becoming darker, while
|
|
2361
|
+
/// the one-pixel analytic fringe keeps diagonal and rounded edges smooth.
|
|
2362
|
+
fn drawDmgArrowShape(pixels: []u8, width: usize, height: usize, segments: []const DmgArrowSegment, thickness: f32, color: [3]u8, alpha: f32) void {
|
|
2363
|
+
if (segments.len == 0 or thickness <= 0 or alpha <= 0) return;
|
|
2364
|
+
const radius = thickness * 0.5;
|
|
2365
|
+
for (0..height) |y| {
|
|
2366
|
+
for (0..width) |x| {
|
|
2367
|
+
const fx = @as(f32, @floatFromInt(x)) + 0.5;
|
|
2368
|
+
const fy = @as(f32, @floatFromInt(y)) + 0.5;
|
|
2369
|
+
var nearest_squared = std.math.inf(f32);
|
|
2370
|
+
for (segments) |segment| {
|
|
2371
|
+
const dx = segment.bx - segment.ax;
|
|
2372
|
+
const dy = segment.by - segment.ay;
|
|
2373
|
+
const length_squared = dx * dx + dy * dy;
|
|
2374
|
+
if (length_squared <= 0.001) continue;
|
|
2375
|
+
const projection = std.math.clamp(((fx - segment.ax) * dx + (fy - segment.ay) * dy) / length_squared, 0.0, 1.0);
|
|
2376
|
+
const distance_x = fx - (segment.ax + projection * dx);
|
|
2377
|
+
const distance_y = fy - (segment.ay + projection * dy);
|
|
2378
|
+
nearest_squared = @min(nearest_squared, distance_x * distance_x + distance_y * distance_y);
|
|
2379
|
+
}
|
|
2380
|
+
if (nearest_squared > (radius + 0.5) * (radius + 0.5)) continue;
|
|
2381
|
+
const coverage = std.math.clamp(radius + 0.5 - @sqrt(@max(nearest_squared, 0)), 0.0, 1.0);
|
|
2382
|
+
if (coverage <= 0) continue;
|
|
2383
|
+
const offset = (y * width + x) * 4;
|
|
2384
|
+
const pixel_alpha = alpha * coverage;
|
|
2385
|
+
const inverse = 1.0 - pixel_alpha;
|
|
2386
|
+
pixels[offset + 0] = @intFromFloat(@round(@as(f32, @floatFromInt(color[0])) * pixel_alpha + @as(f32, @floatFromInt(pixels[offset + 0])) * inverse));
|
|
2387
|
+
pixels[offset + 1] = @intFromFloat(@round(@as(f32, @floatFromInt(color[1])) * pixel_alpha + @as(f32, @floatFromInt(pixels[offset + 1])) * inverse));
|
|
2388
|
+
pixels[offset + 2] = @intFromFloat(@round(@as(f32, @floatFromInt(color[2])) * pixel_alpha + @as(f32, @floatFromInt(pixels[offset + 2])) * inverse));
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
fn dmgFinderScriptAlloc(allocator: std.mem.Allocator, dmg: manifest_tool.DmgMetadata, mount_path: []const u8, app_name: []const u8, background_name: []const u8) ![]u8 {
|
|
2394
|
+
const escaped_mount = try appleScriptStringAlloc(allocator, mount_path);
|
|
2395
|
+
defer allocator.free(escaped_mount);
|
|
2396
|
+
const background_path = try std.fs.path.join(allocator, &.{ mount_path, ".background", background_name });
|
|
2397
|
+
defer allocator.free(background_path);
|
|
2398
|
+
const escaped_background_path = try appleScriptStringAlloc(allocator, background_path);
|
|
2399
|
+
defer allocator.free(escaped_background_path);
|
|
2400
|
+
const position_lines = try dmgFinderPositionLinesAlloc(allocator, dmg, app_name);
|
|
2401
|
+
defer allocator.free(position_lines);
|
|
2402
|
+
const right = 100 + @as(u32, dmg.window_width);
|
|
2403
|
+
// `bounds` includes Finder's title bar; the manifest dimensions describe
|
|
2404
|
+
// the usable icon/background canvas so artwork stays exactly W×H.
|
|
2405
|
+
const bottom = 100 + @as(u32, dmg.window_height) + 36;
|
|
2406
|
+
const inset_right = right - 10;
|
|
2407
|
+
const inset_bottom = bottom - 10;
|
|
2408
|
+
// Capture the window opened from our mount path immediately. Asking
|
|
2409
|
+
// Finder for the container window by disk name can select an older,
|
|
2410
|
+
// read-only copy of the same app DMG that the developer still has mounted.
|
|
2411
|
+
return std.fmt.allocPrint(allocator,
|
|
2412
|
+
\\tell application "Finder"
|
|
2413
|
+
\\ set dmgFolder to POSIX file "{s}" as alias
|
|
2414
|
+
\\ open dmgFolder
|
|
2415
|
+
\\ set dmgWindow to front window
|
|
2416
|
+
\\ delay 1
|
|
2417
|
+
\\ set current view of dmgWindow to icon view
|
|
2418
|
+
\\ set toolbar visible of dmgWindow to false
|
|
2419
|
+
\\ set statusbar visible of dmgWindow to false
|
|
2420
|
+
\\ set pathbar visible of dmgWindow to false
|
|
2421
|
+
\\ set the bounds of dmgWindow to {{100, 100, {d}, {d}}}
|
|
2422
|
+
\\ set theViewOptions to the icon view options of dmgWindow
|
|
2423
|
+
\\ set arrangement of theViewOptions to not arranged
|
|
2424
|
+
\\ set icon size of theViewOptions to {d}
|
|
2425
|
+
\\ set text size of theViewOptions to 13
|
|
2426
|
+
\\ set label position of theViewOptions to bottom
|
|
2427
|
+
\\ set background picture of theViewOptions to (POSIX file "{s}" as alias)
|
|
2428
|
+
\\{s} close dmgWindow
|
|
2429
|
+
\\ open dmgFolder
|
|
2430
|
+
\\ set dmgWindow to front window
|
|
2431
|
+
\\ delay 1
|
|
2432
|
+
\\ set statusbar visible of dmgWindow to false
|
|
2433
|
+
\\ set the bounds of dmgWindow to {{100, 100, {d}, {d}}}
|
|
2434
|
+
\\ delay 1
|
|
2435
|
+
\\ set the bounds of dmgWindow to {{100, 100, {d}, {d}}}
|
|
2436
|
+
\\ update dmgFolder without registering applications
|
|
2437
|
+
\\ delay 1
|
|
2438
|
+
\\ close dmgWindow
|
|
2439
|
+
\\ delay 2
|
|
2440
|
+
\\end tell
|
|
2441
|
+
, .{ escaped_mount, right, bottom, dmg.icon_size, escaped_background_path, position_lines, inset_right, inset_bottom, right, bottom });
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
fn waitForDmgFinderMetadata(allocator: std.mem.Allocator, io: std.Io, mount_path: []const u8) !bool {
|
|
2445
|
+
const ds_store_path = try std.fs.path.join(allocator, &.{ mount_path, ".DS_Store" });
|
|
2446
|
+
defer allocator.free(ds_store_path);
|
|
2447
|
+
const cwd = std.Io.Dir.cwd();
|
|
2448
|
+
for (0..50) |_| {
|
|
2449
|
+
const stat = cwd.statFile(io, ds_store_path, .{}) catch {
|
|
2450
|
+
std.Io.sleep(io, std.Io.Duration.fromMilliseconds(100), .awake) catch return false;
|
|
2451
|
+
continue;
|
|
2452
|
+
};
|
|
2453
|
+
if (stat.size > 0) return true;
|
|
2454
|
+
std.Io.sleep(io, std.Io.Duration.fromMilliseconds(100), .awake) catch return false;
|
|
2455
|
+
}
|
|
2456
|
+
return false;
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
fn dmgFinderPositionLinesAlloc(allocator: std.mem.Allocator, dmg: manifest_tool.DmgMetadata, app_name: []const u8) ![]u8 {
|
|
2460
|
+
var lines: std.ArrayList(u8) = .empty;
|
|
2461
|
+
defer lines.deinit(allocator);
|
|
2462
|
+
|
|
2463
|
+
if (dmg.items.len == 0) {
|
|
2464
|
+
try appendDmgFinderPositionLine(allocator, &lines, app_name, dmg.app_position);
|
|
2465
|
+
if (dmg.applications_link) try appendDmgFinderPositionLine(allocator, &lines, "Applications", dmg.applications_position);
|
|
2466
|
+
return lines.toOwnedSlice(allocator);
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
for (dmg.items) |item| {
|
|
2470
|
+
const name = switch (item.kind) {
|
|
2471
|
+
.app => app_name,
|
|
2472
|
+
.applications => "Applications",
|
|
2473
|
+
.file, .link => manifest_tool.dmgItemDestinationName(item) orelse return error.InvalidDmgItem,
|
|
2474
|
+
};
|
|
2475
|
+
try appendDmgFinderPositionLine(allocator, &lines, name, item.position);
|
|
2476
|
+
}
|
|
2477
|
+
return lines.toOwnedSlice(allocator);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
fn appendDmgFinderPositionLine(allocator: std.mem.Allocator, lines: *std.ArrayList(u8), name: []const u8, position: manifest_tool.DmgPosition) !void {
|
|
2481
|
+
const escaped_name = try appleScriptStringAlloc(allocator, name);
|
|
2482
|
+
defer allocator.free(escaped_name);
|
|
2483
|
+
const line = try std.fmt.allocPrint(allocator, " set position of item \"{s}\" of dmgFolder to {{{d}, {d}}}\n", .{ escaped_name, position.x, position.y });
|
|
2484
|
+
defer allocator.free(line);
|
|
2485
|
+
try lines.appendSlice(allocator, line);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
fn appleScriptStringAlloc(allocator: std.mem.Allocator, value: []const u8) ![]u8 {
|
|
2489
|
+
var escaped: std.ArrayList(u8) = .empty;
|
|
2490
|
+
defer escaped.deinit(allocator);
|
|
2491
|
+
for (value) |byte| {
|
|
2492
|
+
switch (byte) {
|
|
2493
|
+
'\\', '"' => {
|
|
2494
|
+
try escaped.append(allocator, '\\');
|
|
2495
|
+
try escaped.append(allocator, byte);
|
|
2496
|
+
},
|
|
2497
|
+
'\n', '\r' => try escaped.append(allocator, ' '),
|
|
2498
|
+
else => try escaped.append(allocator, byte),
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2501
|
+
return escaped.toOwnedSlice(allocator);
|
|
2502
|
+
}
|
|
2503
|
+
|
|
1977
2504
|
fn absolutePathAlloc(allocator: std.mem.Allocator, io: std.Io, path: []const u8) ![]const u8 {
|
|
1978
2505
|
if (std.fs.path.isAbsolute(path)) return allocator.dupe(u8, path);
|
|
1979
2506
|
const cwd = try std.process.currentPathAlloc(io, allocator);
|
|
@@ -1997,6 +2524,22 @@ fn runArchiveCommand(io: std.Io, argv: []const []const u8, cwd: ?[]const u8) boo
|
|
|
1997
2524
|
};
|
|
1998
2525
|
}
|
|
1999
2526
|
|
|
2527
|
+
fn runArchiveCommandQuiet(io: std.Io, argv: []const []const u8, cwd: ?[]const u8) bool {
|
|
2528
|
+
const child_cwd: std.process.Child.Cwd = if (cwd) |path| .{ .path = path } else .inherit;
|
|
2529
|
+
var child = std.process.spawn(io, .{
|
|
2530
|
+
.argv = argv,
|
|
2531
|
+
.cwd = child_cwd,
|
|
2532
|
+
.stdin = .ignore,
|
|
2533
|
+
.stdout = .ignore,
|
|
2534
|
+
.stderr = .ignore,
|
|
2535
|
+
}) catch return false;
|
|
2536
|
+
const term = child.wait(io) catch return false;
|
|
2537
|
+
return switch (term) {
|
|
2538
|
+
.exited => |code| code == 0,
|
|
2539
|
+
else => false,
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2000
2543
|
pub fn archivePath(allocator: std.mem.Allocator, options: PackageOptions) ![]const u8 {
|
|
2001
2544
|
const dir = std.fs.path.dirname(options.output_path) orelse ".";
|
|
2002
2545
|
return std.fmt.allocPrint(allocator, "{s}/{s}-{s}-{s}-{s}{s}", .{
|
|
@@ -2031,6 +2574,270 @@ test "archive path includes correct suffix per platform" {
|
|
|
2031
2574
|
try std.testing.expect(std.mem.endsWith(u8, win_path, ".zip"));
|
|
2032
2575
|
}
|
|
2033
2576
|
|
|
2577
|
+
test "default DMG background follows the configured window and draws the install arrow" {
|
|
2578
|
+
const gpa = std.testing.allocator;
|
|
2579
|
+
const dmg: manifest_tool.DmgMetadata = .{
|
|
2580
|
+
.window_width = 420,
|
|
2581
|
+
.window_height = 280,
|
|
2582
|
+
.icon_size = 96,
|
|
2583
|
+
.app_position = .{ .x = 110, .y = 140 },
|
|
2584
|
+
.applications_position = .{ .x = 310, .y = 140 },
|
|
2585
|
+
};
|
|
2586
|
+
const encoded = try defaultDmgBackground(gpa, dmg);
|
|
2587
|
+
defer gpa.free(encoded);
|
|
2588
|
+
const header = app_icon_tool.pngHeader(encoded) orelse return error.TestUnexpectedResult;
|
|
2589
|
+
try std.testing.expectEqual(@as(usize, 420), header.width);
|
|
2590
|
+
try std.testing.expectEqual(@as(usize, 280), header.height);
|
|
2591
|
+
|
|
2592
|
+
const retina = try defaultDmgBackgroundAtScale(gpa, dmg, 2);
|
|
2593
|
+
defer gpa.free(retina);
|
|
2594
|
+
const retina_header = app_icon_tool.pngHeader(retina) orelse return error.TestUnexpectedResult;
|
|
2595
|
+
try std.testing.expectEqual(@as(usize, 840), retina_header.width);
|
|
2596
|
+
try std.testing.expectEqual(@as(usize, 560), retina_header.height);
|
|
2597
|
+
|
|
2598
|
+
const decoded = try app_icon_tool.decodePng(gpa, encoded);
|
|
2599
|
+
defer decoded.deinit(gpa);
|
|
2600
|
+
const arrow = (140 * decoded.width + 210) * 4;
|
|
2601
|
+
const clear = (140 * decoded.width + 24) * 4;
|
|
2602
|
+
try std.testing.expect(decoded.pixels[arrow] < decoded.pixels[clear]);
|
|
2603
|
+
try std.testing.expect(decoded.pixels[arrow + 1] < decoded.pixels[clear + 1]);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
test "DMG arrow unions translucent joins and antialiases rounded edges" {
|
|
2607
|
+
var pixels: [20 * 20 * 4]u8 = @splat(255);
|
|
2608
|
+
const segments = [_]DmgArrowSegment{
|
|
2609
|
+
.{ .ax = 4, .ay = 10, .bx = 12, .by = 10 },
|
|
2610
|
+
.{ .ax = 12, .ay = 10, .bx = 9, .by = 7 },
|
|
2611
|
+
.{ .ax = 12, .ay = 10, .bx = 9, .by = 13 },
|
|
2612
|
+
};
|
|
2613
|
+
drawDmgArrowShape(&pixels, 20, 20, &segments, 5, .{ 0, 0, 0 }, 0.5);
|
|
2614
|
+
|
|
2615
|
+
const joined = (9 * 20 + 11) * 4;
|
|
2616
|
+
try std.testing.expectEqual(@as(u8, 128), pixels[joined]);
|
|
2617
|
+
try std.testing.expectEqual(pixels[joined], pixels[joined + 1]);
|
|
2618
|
+
try std.testing.expectEqual(pixels[joined], pixels[joined + 2]);
|
|
2619
|
+
|
|
2620
|
+
const antialiased_edge = (7 * 20 + 6) * 4;
|
|
2621
|
+
try std.testing.expect(pixels[antialiased_edge] > pixels[joined]);
|
|
2622
|
+
try std.testing.expect(pixels[antialiased_edge] < 255);
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
test "DMG Finder script carries custom layout and escapes paths and names" {
|
|
2626
|
+
const script = try dmgFinderScriptAlloc(std.testing.allocator, .{
|
|
2627
|
+
.window_width = 720,
|
|
2628
|
+
.window_height = 440,
|
|
2629
|
+
.icon_size = 144,
|
|
2630
|
+
.app_position = .{ .x = 180, .y = 210 },
|
|
2631
|
+
.applications_position = .{ .x = 540, .y = 210 },
|
|
2632
|
+
}, "/Volumes/Demo \"Installer\"", "Demo \"App\".app", "background.jpeg");
|
|
2633
|
+
defer std.testing.allocator.free(script);
|
|
2634
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "POSIX file \"/Volumes/Demo \\\"Installer\\\"\" as alias") != null);
|
|
2635
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "set the bounds of dmgWindow to {100, 100, 820, 576}") != null);
|
|
2636
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "set the bounds of dmgWindow to {100, 100, 810, 566}") != null);
|
|
2637
|
+
try std.testing.expect(std.mem.count(u8, script, "set the bounds of dmgWindow to {100, 100, 820, 576}") == 2);
|
|
2638
|
+
try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, script, "set dmgWindow to front window"));
|
|
2639
|
+
try std.testing.expectEqual(@as(usize, 2), std.mem.count(u8, script, "close dmgWindow"));
|
|
2640
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "delay 2") != null);
|
|
2641
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "set pathbar visible of dmgWindow to false") != null);
|
|
2642
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "set icon size of theViewOptions to 144") != null);
|
|
2643
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "/Volumes/Demo \\\"Installer\\\"/.background/background.jpeg") != null);
|
|
2644
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Demo \\\"App\\\".app\"") != null);
|
|
2645
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Applications\"") != null);
|
|
2646
|
+
}
|
|
2647
|
+
|
|
2648
|
+
test "DMG Finder script omits the Applications item when its link is disabled" {
|
|
2649
|
+
const script = try dmgFinderScriptAlloc(std.testing.allocator, .{ .applications_link = false }, "Demo", "Demo.app", "background.png");
|
|
2650
|
+
defer std.testing.allocator.free(script);
|
|
2651
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Applications\"") == null);
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
test "DMG Finder script positions the explicit visible item list" {
|
|
2655
|
+
const items = [_]manifest_tool.DmgItemMetadata{
|
|
2656
|
+
.{ .kind = .app, .position = .{ .x = 150, .y = 170 } },
|
|
2657
|
+
.{ .kind = .applications, .position = .{ .x = 510, .y = 170 } },
|
|
2658
|
+
.{ .kind = .file, .path = "docs/README.pdf", .name = "Read \"Me\".pdf", .position = .{ .x = 260, .y = 330 } },
|
|
2659
|
+
.{ .kind = .link, .path = "/Library/QuickLook", .name = "QuickLook", .position = .{ .x = 400, .y = 330 } },
|
|
2660
|
+
};
|
|
2661
|
+
const script = try dmgFinderScriptAlloc(std.testing.allocator, .{ .items = &items }, "/Volumes/Demo", "Demo.app", "background.tiff");
|
|
2662
|
+
defer std.testing.allocator.free(script);
|
|
2663
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Demo.app\" of dmgFolder to {150, 170}") != null);
|
|
2664
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Applications\" of dmgFolder to {510, 170}") != null);
|
|
2665
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"Read \\\"Me\\\".pdf\" of dmgFolder to {260, 330}") != null);
|
|
2666
|
+
try std.testing.expect(std.mem.indexOf(u8, script, "item \"QuickLook\" of dmgFolder to {400, 330}") != null);
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
test "DMG background discovers an adjacent retina source" {
|
|
2670
|
+
var cwd = std.Io.Dir.cwd();
|
|
2671
|
+
const root = ".zig-cache/test-package-dmg-retina";
|
|
2672
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2673
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2674
|
+
try cwd.createDirPath(std.testing.io, root ++ "/art");
|
|
2675
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/art/installer@2x.png", .data = "fixture" });
|
|
2676
|
+
|
|
2677
|
+
const retina = (try dmgRetinaBackgroundSourceAlloc(std.testing.allocator, std.testing.io, root, "art/installer.png")).?;
|
|
2678
|
+
defer std.testing.allocator.free(retina);
|
|
2679
|
+
try std.testing.expectEqualStrings(root ++ "/art/installer@2x.png", retina);
|
|
2680
|
+
const background_name = try dmgBackgroundNameAlloc(std.testing.allocator, "art/installer.png", true);
|
|
2681
|
+
defer std.testing.allocator.free(background_name);
|
|
2682
|
+
try std.testing.expectEqualStrings("background.tiff", background_name);
|
|
2683
|
+
}
|
|
2684
|
+
|
|
2685
|
+
test "assembled DMG background does not retain source images" {
|
|
2686
|
+
if (@import("builtin").os.tag != .macos) return error.SkipZigTest;
|
|
2687
|
+
var cwd = std.Io.Dir.cwd();
|
|
2688
|
+
const root = ".zig-cache/test-package-dmg-background-cleanup";
|
|
2689
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2690
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2691
|
+
try cwd.createDirPath(std.testing.io, root ++ "/source");
|
|
2692
|
+
|
|
2693
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2694
|
+
.id = "dev.example.demo",
|
|
2695
|
+
.name = "demo",
|
|
2696
|
+
.version = "1.0.0",
|
|
2697
|
+
.dmg = .{
|
|
2698
|
+
.window_width = 320,
|
|
2699
|
+
.window_height = 240,
|
|
2700
|
+
.applications_link = false,
|
|
2701
|
+
},
|
|
2702
|
+
};
|
|
2703
|
+
var source_dir = try cwd.openDir(std.testing.io, root ++ "/source", .{});
|
|
2704
|
+
defer source_dir.close(std.testing.io);
|
|
2705
|
+
try stageDmgBackground(std.testing.allocator, std.testing.io, .{
|
|
2706
|
+
.metadata = metadata,
|
|
2707
|
+
.output_path = root ++ "/Demo.app",
|
|
2708
|
+
}, source_dir, root ++ "/source", "background.tiff", null);
|
|
2709
|
+
|
|
2710
|
+
var background = try cwd.openFile(std.testing.io, root ++ "/source/.background/background.tiff", .{});
|
|
2711
|
+
background.close(std.testing.io);
|
|
2712
|
+
try std.testing.expectError(error.FileNotFound, cwd.openFile(std.testing.io, root ++ "/source/.background/background.png", .{}));
|
|
2713
|
+
try std.testing.expectError(error.FileNotFound, cwd.openFile(std.testing.io, root ++ "/source/.background/background@2x.png", .{}));
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
test "macOS archive rejects an invalid DMG background before staging the app" {
|
|
2717
|
+
var cwd = std.Io.Dir.cwd();
|
|
2718
|
+
const root = ".zig-cache/test-package-dmg-invalid-background";
|
|
2719
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2720
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2721
|
+
try cwd.createDirPath(std.testing.io, root ++ "/art");
|
|
2722
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/art/installer.png", .data = "not a png" });
|
|
2723
|
+
|
|
2724
|
+
try std.testing.expectError(error.InvalidDmgSource, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2725
|
+
.metadata = .{
|
|
2726
|
+
.id = "dev.example.demo",
|
|
2727
|
+
.name = "demo",
|
|
2728
|
+
.display_name = "Demo",
|
|
2729
|
+
.version = "1.0.0",
|
|
2730
|
+
.dmg = .{ .background = "art/installer.png" },
|
|
2731
|
+
},
|
|
2732
|
+
.target = .macos,
|
|
2733
|
+
.output_path = root ++ "/Demo.app",
|
|
2734
|
+
.project_dir = root,
|
|
2735
|
+
.archive = true,
|
|
2736
|
+
}));
|
|
2737
|
+
try std.testing.expectError(error.FileNotFound, cwd.openDir(std.testing.io, root ++ "/Demo.app", .{}));
|
|
2738
|
+
}
|
|
2739
|
+
|
|
2740
|
+
test "macOS archive rejects an app-name collision before staging the app" {
|
|
2741
|
+
var cwd = std.Io.Dir.cwd();
|
|
2742
|
+
const root = ".zig-cache/test-package-dmg-app-name-collision";
|
|
2743
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2744
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2745
|
+
|
|
2746
|
+
const items = [_]manifest_tool.DmgItemMetadata{
|
|
2747
|
+
.{ .kind = .app, .position = .{ .x = 170, .y = 182 } },
|
|
2748
|
+
.{ .kind = .link, .path = "/Applications", .name = "Demo.app", .position = .{ .x = 490, .y = 182 } },
|
|
2749
|
+
};
|
|
2750
|
+
try std.testing.expectError(error.DuplicateDmgItem, createPackage(std.testing.allocator, std.testing.io, .{
|
|
2751
|
+
.metadata = .{
|
|
2752
|
+
.id = "dev.example.demo",
|
|
2753
|
+
.name = "demo",
|
|
2754
|
+
.display_name = "Demo",
|
|
2755
|
+
.version = "1.0.0",
|
|
2756
|
+
.dmg = .{ .items = &items },
|
|
2757
|
+
},
|
|
2758
|
+
.target = .macos,
|
|
2759
|
+
.output_path = root ++ "/Demo.app",
|
|
2760
|
+
.archive = true,
|
|
2761
|
+
}));
|
|
2762
|
+
try std.testing.expectError(error.FileNotFound, cwd.openDir(std.testing.io, root ++ "/Demo.app", .{}));
|
|
2763
|
+
}
|
|
2764
|
+
|
|
2765
|
+
test "DMG app bundle uses the display name or explicit item override" {
|
|
2766
|
+
const default_name = try dmgAppBundleNameAlloc(std.testing.allocator, .{
|
|
2767
|
+
.id = "dev.example.demo",
|
|
2768
|
+
.name = "demo",
|
|
2769
|
+
.display_name = "Demo/Studio",
|
|
2770
|
+
.version = "1.0.0",
|
|
2771
|
+
});
|
|
2772
|
+
defer std.testing.allocator.free(default_name);
|
|
2773
|
+
try std.testing.expectEqualStrings("Demo-Studio.app", default_name);
|
|
2774
|
+
|
|
2775
|
+
const items = [_]manifest_tool.DmgItemMetadata{
|
|
2776
|
+
.{ .kind = .app, .name = "Branded Installer.app", .position = .{ .x = 170, .y = 182 } },
|
|
2777
|
+
};
|
|
2778
|
+
const overridden = try dmgAppBundleNameAlloc(std.testing.allocator, .{
|
|
2779
|
+
.id = "dev.example.demo",
|
|
2780
|
+
.name = "demo",
|
|
2781
|
+
.display_name = "Demo Studio",
|
|
2782
|
+
.version = "1.0.0",
|
|
2783
|
+
.dmg = .{ .items = &items },
|
|
2784
|
+
});
|
|
2785
|
+
defer std.testing.allocator.free(overridden);
|
|
2786
|
+
try std.testing.expectEqualStrings("Branded Installer.app", overridden);
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
test "DMG explicit items stage the branded app, project contents, and links" {
|
|
2790
|
+
if (@import("builtin").os.tag != .macos) return error.SkipZigTest;
|
|
2791
|
+
var cwd = std.Io.Dir.cwd();
|
|
2792
|
+
const root = ".zig-cache/test-package-dmg-items";
|
|
2793
|
+
try cwd.deleteTree(std.testing.io, root);
|
|
2794
|
+
defer cwd.deleteTree(std.testing.io, root) catch {};
|
|
2795
|
+
try cwd.createDirPath(std.testing.io, root ++ "/Demo.app/Contents");
|
|
2796
|
+
try cwd.createDirPath(std.testing.io, root ++ "/project/Extras");
|
|
2797
|
+
try cwd.createDirPath(std.testing.io, root ++ "/source");
|
|
2798
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/Demo.app/Contents/marker", .data = "app" });
|
|
2799
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/project/README.pdf", .data = "readme" });
|
|
2800
|
+
try cwd.writeFile(std.testing.io, .{ .sub_path = root ++ "/project/Extras/note.txt", .data = "bonus" });
|
|
2801
|
+
|
|
2802
|
+
const items = [_]manifest_tool.DmgItemMetadata{
|
|
2803
|
+
.{ .kind = .app, .name = "Branded Demo", .position = .{ .x = 150, .y = 170 } },
|
|
2804
|
+
.{ .kind = .applications, .position = .{ .x = 510, .y = 170 } },
|
|
2805
|
+
.{ .kind = .file, .path = "README.pdf", .name = "Read Me.pdf", .position = .{ .x = 220, .y = 330 } },
|
|
2806
|
+
.{ .kind = .file, .path = "Extras", .name = "Bonus", .position = .{ .x = 330, .y = 330 } },
|
|
2807
|
+
.{ .kind = .link, .path = "/Applications", .name = "System Applications", .position = .{ .x = 440, .y = 330 } },
|
|
2808
|
+
};
|
|
2809
|
+
const metadata: manifest_tool.Metadata = .{
|
|
2810
|
+
.id = "dev.example.demo",
|
|
2811
|
+
.name = "demo",
|
|
2812
|
+
.display_name = "Demo",
|
|
2813
|
+
.version = "1.0.0",
|
|
2814
|
+
.dmg = .{ .items = &items },
|
|
2815
|
+
};
|
|
2816
|
+
try manifest_tool.validateDmgSettings(metadata.dmg);
|
|
2817
|
+
const app_name = try dmgAppBundleNameAlloc(std.testing.allocator, metadata);
|
|
2818
|
+
defer std.testing.allocator.free(app_name);
|
|
2819
|
+
try std.testing.expectEqualStrings("Branded Demo.app", app_name);
|
|
2820
|
+
|
|
2821
|
+
var source_dir = try cwd.openDir(std.testing.io, root ++ "/source", .{});
|
|
2822
|
+
defer source_dir.close(std.testing.io);
|
|
2823
|
+
try stageDmgItems(std.testing.allocator, std.testing.io, .{
|
|
2824
|
+
.metadata = metadata,
|
|
2825
|
+
.output_path = root ++ "/Demo.app",
|
|
2826
|
+
.project_dir = root ++ "/project",
|
|
2827
|
+
}, source_dir, root ++ "/source", root ++ "/Demo.app", app_name);
|
|
2828
|
+
|
|
2829
|
+
var app_marker = try cwd.openFile(std.testing.io, root ++ "/source/Branded Demo.app/Contents/marker", .{});
|
|
2830
|
+
app_marker.close(std.testing.io);
|
|
2831
|
+
var readme = try cwd.openFile(std.testing.io, root ++ "/source/Read Me.pdf", .{});
|
|
2832
|
+
readme.close(std.testing.io);
|
|
2833
|
+
var bonus = try cwd.openFile(std.testing.io, root ++ "/source/Bonus/note.txt", .{});
|
|
2834
|
+
bonus.close(std.testing.io);
|
|
2835
|
+
var applications = try cwd.openDir(std.testing.io, root ++ "/source/Applications", .{});
|
|
2836
|
+
applications.close(std.testing.io);
|
|
2837
|
+
var system_applications = try cwd.openDir(std.testing.io, root ++ "/source/System Applications", .{});
|
|
2838
|
+
system_applications.close(std.testing.io);
|
|
2839
|
+
}
|
|
2840
|
+
|
|
2034
2841
|
test "archive command reports nonzero exit" {
|
|
2035
2842
|
if (@import("builtin").os.tag == .windows) return error.SkipZigTest;
|
|
2036
2843
|
try std.testing.expect(!runArchiveCommand(std.testing.io, &.{ "sh", "-c", "exit 7" }, null));
|
|
@@ -2297,6 +3104,30 @@ test "plist template includes identity executable and version" {
|
|
|
2297
3104
|
try std.testing.expect(std.mem.indexOf(u8, bare_plist, "NSHumanReadableCopyright") == null);
|
|
2298
3105
|
}
|
|
2299
3106
|
|
|
3107
|
+
test "plist capture usage descriptions follow manifest permissions" {
|
|
3108
|
+
const capture_permissions = [_][]const u8{ "microphone", "system_audio" };
|
|
3109
|
+
const capture: manifest_tool.Metadata = .{
|
|
3110
|
+
.id = "dev.example.recorder",
|
|
3111
|
+
.name = "recorder",
|
|
3112
|
+
.display_name = "Audio & Voice",
|
|
3113
|
+
.version = "1.0.0",
|
|
3114
|
+
.permissions = &capture_permissions,
|
|
3115
|
+
};
|
|
3116
|
+
const plist = try macosInfoPlist(std.testing.allocator, capture, "recorder");
|
|
3117
|
+
defer std.testing.allocator.free(plist);
|
|
3118
|
+
try std.testing.expect(std.mem.indexOf(u8, plist, "NSMicrophoneUsageDescription") != null);
|
|
3119
|
+
try std.testing.expect(std.mem.indexOf(u8, plist, "NSAudioCaptureUsageDescription") != null);
|
|
3120
|
+
try std.testing.expect(std.mem.indexOf(u8, plist, "NSScreenCaptureUsageDescription") != null);
|
|
3121
|
+
try std.testing.expect(std.mem.indexOf(u8, plist, "Audio & Voice captures microphone audio") != null);
|
|
3122
|
+
|
|
3123
|
+
const bare: manifest_tool.Metadata = .{ .id = "dev.example.app", .name = "demo", .version = "1.0.0" };
|
|
3124
|
+
const bare_plist = try macosInfoPlist(std.testing.allocator, bare, "demo");
|
|
3125
|
+
defer std.testing.allocator.free(bare_plist);
|
|
3126
|
+
try std.testing.expect(std.mem.indexOf(u8, bare_plist, "NSMicrophoneUsageDescription") == null);
|
|
3127
|
+
try std.testing.expect(std.mem.indexOf(u8, bare_plist, "NSAudioCaptureUsageDescription") == null);
|
|
3128
|
+
try std.testing.expect(std.mem.indexOf(u8, bare_plist, "NSScreenCaptureUsageDescription") == null);
|
|
3129
|
+
}
|
|
3130
|
+
|
|
2300
3131
|
test "plist template includes document and URL registrations" {
|
|
2301
3132
|
const extensions = [_][]const u8{ "md", ".markdown" };
|
|
2302
3133
|
const mime_types = [_][]const u8{"text/markdown"};
|