@ng-native/desktop 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (256) hide show
  1. package/README.md +6 -3
  2. package/bin/app-config.mjs +1 -0
  3. package/bin/archive.mjs +166 -0
  4. package/bin/autolink.mjs +61 -30
  5. package/bin/cli.mjs +127 -27
  6. package/bin/host.mjs +255 -58
  7. package/bin/package-linux.mjs +1394 -0
  8. package/bin/package.mjs +171 -35
  9. package/bin/plist.mjs +6 -2
  10. package/bin/png-icon.mjs +315 -0
  11. package/bin/prebuilt.mjs +147 -26
  12. package/bin/toolchain.mjs +258 -19
  13. package/native/CMakeLists.txt +64 -6
  14. package/native/appkit/CMakeLists.txt +2 -1
  15. package/native/appkit/appkit-backend.h +1 -0
  16. package/native/appkit/appkit-backend.mm +13 -0
  17. package/native/appkit/header-toolbar.mm +28 -25
  18. package/native/appkit/host-view.h +10 -0
  19. package/native/appkit/host-view.mm +146 -40
  20. package/native/appkit/input-replay.h +6 -0
  21. package/native/appkit/input-replay.mm +21 -12
  22. package/native/appkit/main.mm +11 -7
  23. package/native/appkit/native-controls.mm +13 -1
  24. package/native/appkit/split-view.mm +7 -13
  25. package/native/appkit/text-input-field.h +4 -0
  26. package/native/appkit/text-input-field.mm +20 -1
  27. package/native/cmake/curl.cmake +79 -0
  28. package/native/cmake/libraries/react-native-reanimated.cmake +5 -0
  29. package/native/cmake/libraries/react-native-worklets.cmake +5 -0
  30. package/native/cmake/linked-modules.cmake +20 -4
  31. package/native/cmake/react-native.cmake +18 -1
  32. package/native/core/include/ngn/accent-colors.h +38 -0
  33. package/native/core/include/ngn/accessibility-relations.h +65 -0
  34. package/native/core/include/ngn/accessibility.h +26 -0
  35. package/native/core/include/ngn/animated-frame-loop.h +56 -0
  36. package/native/core/include/ngn/app-info.h +24 -8
  37. package/native/core/include/ngn/app-menus.h +14 -1
  38. package/native/core/include/ngn/app-windows.h +15 -2
  39. package/native/core/include/ngn/aria-role.h +96 -0
  40. package/native/core/include/ngn/audio.h +2 -0
  41. package/native/core/include/ngn/camera.h +9 -0
  42. package/native/core/include/ngn/control-sizes.h +7 -2
  43. package/native/core/include/ngn/crash-report.h +31 -0
  44. package/native/core/include/ngn/curl-network.h +93 -0
  45. package/native/core/include/ngn/dbus-menu.h +39 -0
  46. package/native/core/include/ngn/default-menu.h +36 -0
  47. package/native/core/include/ngn/desktop-expo.h +7 -1
  48. package/native/core/include/ngn/desktop-modules.h +22 -0
  49. package/native/core/include/ngn/desktop-props.h +21 -1
  50. package/native/core/include/ngn/desktop-view-props.h +6 -0
  51. package/native/core/include/ngn/focus-order.h +10 -0
  52. package/native/core/include/ngn/header-bar.h +22 -0
  53. package/native/core/include/ngn/host-os.h +6 -0
  54. package/native/core/include/ngn/host-reload.h +21 -0
  55. package/native/core/include/ngn/host-state.h +23 -0
  56. package/native/core/include/ngn/image-source.h +26 -1
  57. package/native/core/include/ngn/input-script.h +3 -3
  58. package/native/core/include/ngn/input.h +4 -1
  59. package/native/core/include/ngn/launch-frame.h +21 -0
  60. package/native/core/include/ngn/launch-settings.h +23 -5
  61. package/native/core/include/ngn/mounting-backend.h +5 -0
  62. package/native/core/include/ngn/mounting-manager.h +1 -0
  63. package/native/core/include/ngn/native-controls.h +26 -5
  64. package/native/core/include/ngn/notification-schedule.h +74 -0
  65. package/native/core/include/ngn/notifications.h +2 -1
  66. package/native/core/include/ngn/openssl-update-crypto.h +15 -0
  67. package/native/core/include/ngn/photo-library.h +60 -20
  68. package/native/core/include/ngn/posix-locale.h +43 -0
  69. package/native/core/include/ngn/runtime.h +5 -0
  70. package/native/core/include/ngn/safe-areas.h +14 -2
  71. package/native/core/include/ngn/split-view.h +78 -0
  72. package/native/core/include/ngn/surface-metrics.h +7 -0
  73. package/native/core/include/ngn/system.h +14 -0
  74. package/native/core/include/ngn/text-input.h +13 -0
  75. package/native/core/include/ngn/text-units.h +38 -0
  76. package/native/core/include/ngn/updates.h +14 -2
  77. package/native/core/include/ngn/view-box.h +40 -0
  78. package/native/core/include/ngn/view-transform.h +15 -0
  79. package/native/core/include/ngn/web-browser.h +46 -0
  80. package/native/core/src/accent-colors.cpp +88 -0
  81. package/native/core/src/accessibility-relations.cpp +138 -0
  82. package/native/core/src/accessibility.cpp +50 -0
  83. package/native/core/src/animated-frame-loop.cpp +166 -0
  84. package/native/core/src/app-menus.cpp +26 -9
  85. package/native/core/src/app-windows.cpp +27 -6
  86. package/native/core/src/aria-role.cpp +127 -0
  87. package/native/core/src/control-sizes.cpp +9 -5
  88. package/native/core/src/crash-report.cpp +196 -0
  89. package/native/core/src/curl-network.cpp +1562 -0
  90. package/native/core/src/dbus-menu.cpp +71 -0
  91. package/native/core/src/default-menu.cpp +134 -0
  92. package/native/core/src/desktop-view-props.cpp +14 -0
  93. package/native/core/src/focus-order.cpp +19 -0
  94. package/native/core/src/header-bar.cpp +20 -0
  95. package/native/core/src/host-os.cpp +19 -0
  96. package/native/core/src/host-reload.cpp +45 -0
  97. package/native/core/src/host-state.cpp +8 -0
  98. package/native/core/src/image-source.cpp +90 -0
  99. package/native/core/src/input-dispatcher.cpp +27 -5
  100. package/native/core/src/input-script.cpp +3 -2
  101. package/native/core/src/launch-settings.cpp +76 -0
  102. package/native/core/src/libraries/react-native-reanimated.cpp +6 -1
  103. package/native/core/src/modules/app-info.cpp +55 -6
  104. package/native/core/src/modules/app-modules.cpp +1 -1
  105. package/native/core/src/modules/audio.cpp +4 -2
  106. package/native/core/src/modules/camera.cpp +8 -11
  107. package/native/core/src/modules/desktop-expo.cpp +10 -5
  108. package/native/core/src/modules/desktop-modules.cpp +106 -41
  109. package/native/core/src/modules/file-photo-picker.cpp +408 -0
  110. package/native/core/src/modules/notifications.cpp +13 -17
  111. package/native/core/src/modules/photo-library.cpp +42 -13
  112. package/native/core/src/modules/web-browser.cpp +89 -0
  113. package/native/core/src/mounting-manager.cpp +12 -0
  114. package/native/core/src/native-controls.cpp +42 -1
  115. package/native/core/src/notification-schedule.cpp +429 -0
  116. package/native/core/src/openssl-update-crypto.cpp +83 -0
  117. package/native/core/src/posix-locale.cpp +192 -0
  118. package/native/core/src/runtime.cpp +30 -1
  119. package/native/core/src/safe-areas.cpp +19 -4
  120. package/native/core/src/spawn-rules.cpp +4 -1
  121. package/native/core/src/split-view.cpp +93 -0
  122. package/native/core/src/system.cpp +19 -0
  123. package/native/core/src/text-input.cpp +18 -1
  124. package/native/core/src/text-units.cpp +99 -0
  125. package/native/core/src/updates.cpp +76 -17
  126. package/native/core/src/view-box.cpp +75 -40
  127. package/native/core/src/view-transform.cpp +28 -0
  128. package/native/docker/Dockerfile +38 -0
  129. package/native/docker/Dockerfile.fedora +36 -0
  130. package/native/docker/glibc-floor.sh +49 -0
  131. package/native/gtk/CMakeLists.txt +137 -0
  132. package/native/gtk/accent-colour.cpp +57 -0
  133. package/native/gtk/accent-colour.h +41 -0
  134. package/native/gtk/accessibility-settings.cpp +159 -0
  135. package/native/gtk/accessibility-settings.h +62 -0
  136. package/native/gtk/accessible-text.cpp +151 -0
  137. package/native/gtk/accessible-text.h +49 -0
  138. package/native/gtk/accessible.cpp +306 -0
  139. package/native/gtk/accessible.h +75 -0
  140. package/native/gtk/alerts.cpp +267 -0
  141. package/native/gtk/alerts.h +30 -0
  142. package/native/gtk/animation-frames.cpp +159 -0
  143. package/native/gtk/animation-frames.h +20 -0
  144. package/native/gtk/app-info.cpp +91 -0
  145. package/native/gtk/app-info.h +25 -0
  146. package/native/gtk/app-windows.cpp +439 -0
  147. package/native/gtk/app-windows.h +150 -0
  148. package/native/gtk/audio.cpp +370 -0
  149. package/native/gtk/audio.h +54 -0
  150. package/native/gtk/auth-session.cpp +73 -0
  151. package/native/gtk/auth-session.h +16 -0
  152. package/native/gtk/battery.cpp +110 -0
  153. package/native/gtk/battery.h +19 -0
  154. package/native/gtk/box-paint.cpp +262 -0
  155. package/native/gtk/box-paint.h +32 -0
  156. package/native/gtk/cairo-canvas.cpp +755 -0
  157. package/native/gtk/cairo-canvas.h +49 -0
  158. package/native/gtk/camera.cpp +909 -0
  159. package/native/gtk/camera.h +69 -0
  160. package/native/gtk/capture.cpp +46 -0
  161. package/native/gtk/capture.h +19 -0
  162. package/native/gtk/clock-format.cpp +151 -0
  163. package/native/gtk/clock-format.h +36 -0
  164. package/native/gtk/crypto.cpp +75 -0
  165. package/native/gtk/crypto.h +14 -0
  166. package/native/gtk/dbus-properties.cpp +131 -0
  167. package/native/gtk/dbus-properties.h +61 -0
  168. package/native/gtk/drag-and-drop.cpp +339 -0
  169. package/native/gtk/drag-and-drop.h +30 -0
  170. package/native/gtk/file-dialogs.cpp +239 -0
  171. package/native/gtk/file-dialogs.h +21 -0
  172. package/native/gtk/file-system.cpp +212 -0
  173. package/native/gtk/file-system.h +25 -0
  174. package/native/gtk/focus.cpp +282 -0
  175. package/native/gtk/focus.h +37 -0
  176. package/native/gtk/fonts.cpp +89 -0
  177. package/native/gtk/fonts.h +22 -0
  178. package/native/gtk/gst-frames.cpp +150 -0
  179. package/native/gtk/gst-frames.h +47 -0
  180. package/native/gtk/gst-playback.cpp +496 -0
  181. package/native/gtk/gst-playback.h +81 -0
  182. package/native/gtk/gtk-backend.cpp +690 -0
  183. package/native/gtk/gtk-backend.h +134 -0
  184. package/native/gtk/host-sources.cpp +354 -0
  185. package/native/gtk/host-sources.h +46 -0
  186. package/native/gtk/image-manipulator.cpp +254 -0
  187. package/native/gtk/image-manipulator.h +30 -0
  188. package/native/gtk/image-view.cpp +256 -0
  189. package/native/gtk/image-view.h +54 -0
  190. package/native/gtk/input-replay.cpp +299 -0
  191. package/native/gtk/input-replay.h +36 -0
  192. package/native/gtk/launcher-badge.cpp +29 -0
  193. package/native/gtk/launcher-badge.h +21 -0
  194. package/native/gtk/locales.cpp +131 -0
  195. package/native/gtk/locales.h +23 -0
  196. package/native/gtk/location.cpp +274 -0
  197. package/native/gtk/location.h +19 -0
  198. package/native/gtk/main.cpp +1092 -0
  199. package/native/gtk/menus.cpp +447 -0
  200. package/native/gtk/menus.h +100 -0
  201. package/native/gtk/native-controls.cpp +831 -0
  202. package/native/gtk/native-controls.h +58 -0
  203. package/native/gtk/network-state.cpp +72 -0
  204. package/native/gtk/network-state.h +24 -0
  205. package/native/gtk/notifications.cpp +235 -0
  206. package/native/gtk/notifications.h +30 -0
  207. package/native/gtk/pango-text.cpp +274 -0
  208. package/native/gtk/pango-text.h +73 -0
  209. package/native/gtk/portal.cpp +451 -0
  210. package/native/gtk/portal.h +71 -0
  211. package/native/gtk/printing.cpp +338 -0
  212. package/native/gtk/printing.h +34 -0
  213. package/native/gtk/proxy-resolver.cpp +74 -0
  214. package/native/gtk/proxy-resolver.h +20 -0
  215. package/native/gtk/screens.cpp +1461 -0
  216. package/native/gtk/screens.h +274 -0
  217. package/native/gtk/scroll-view.cpp +414 -0
  218. package/native/gtk/scroll-view.h +82 -0
  219. package/native/gtk/secret-store.cpp +120 -0
  220. package/native/gtk/secret-store.h +27 -0
  221. package/native/gtk/settings-portal.cpp +129 -0
  222. package/native/gtk/settings-portal.h +47 -0
  223. package/native/gtk/split-view.cpp +1105 -0
  224. package/native/gtk/split-view.h +195 -0
  225. package/native/gtk/status-notifier.cpp +487 -0
  226. package/native/gtk/status-notifier.h +43 -0
  227. package/native/gtk/surface-input.cpp +251 -0
  228. package/native/gtk/surface-input.h +57 -0
  229. package/native/gtk/system-access.cpp +295 -0
  230. package/native/gtk/system-access.h +37 -0
  231. package/native/gtk/text-field.cpp +827 -0
  232. package/native/gtk/text-field.h +78 -0
  233. package/native/gtk/video.cpp +527 -0
  234. package/native/gtk/video.h +47 -0
  235. package/native/gtk/view-widget.cpp +431 -0
  236. package/native/gtk/view-widget.h +105 -0
  237. package/native/gtk/window-scale.cpp +95 -0
  238. package/native/gtk/window-scale.h +35 -0
  239. package/native/scripts/atspi-check.py +310 -0
  240. package/native/scripts/atspi-check.test.py +48 -0
  241. package/native/scripts/build.sh +20 -3
  242. package/native/scripts/compilers.sh +17 -0
  243. package/native/scripts/deb-depends-check.sh +22 -0
  244. package/native/scripts/fetch.sh +23 -2
  245. package/native/scripts/launch-cell.sh +157 -0
  246. package/native/scripts/launch-probe.sh +14 -3
  247. package/native/scripts/make-prebuilt.mjs +133 -44
  248. package/native/scripts/prebuilt-host-cache.mjs +71 -40
  249. package/native/scripts/reset-for-compilers.sh +44 -0
  250. package/native/scripts/start-xvfb.sh +35 -0
  251. package/native/shim/paragraph-platform/react/renderer/components/text/HostPlatformParagraphProps.h +35 -0
  252. package/native/shim/view-platform/react/renderer/components/view/HostPlatformViewTraitsInitializer.h +5 -2
  253. package/native/shim/worklets/linux-reanimated-props.h +14 -0
  254. package/native/shim/worklets/linux-worklets.h +23 -0
  255. package/package.json +6 -3
  256. package/prebuilt.json +70 -6
package/bin/package.mjs CHANGED
@@ -19,6 +19,7 @@ import path from 'node:path';
19
19
  import { parseArgs } from 'node:util';
20
20
 
21
21
  import { hostCapabilities } from './app-config.mjs';
22
+ import { checkLinuxFlags, LINUX_FORMATS, packageLinux } from './package-linux.mjs';
22
23
  import { plist } from './plist.mjs';
23
24
  import { prepareHost, readExpoConfig, UsageError } from './host.mjs';
24
25
 
@@ -28,68 +29,167 @@ export const MINIMUM_MACOS = '14.0';
28
29
  /** Where the packages go, in the app's directory, unless `--output` says otherwise. */
29
30
  export const DEFAULT_OUTPUT = 'dist/macos';
30
31
 
31
- const FORMATS = ['app', 'dmg', 'mas'];
32
+ /**
33
+ * What `package` makes for each OS, `app` first as the default, and where by default.
34
+ *
35
+ * @type {Record<'macos' | 'linux', { formats: readonly string[], output: string }>}
36
+ */
37
+ export const PACKAGE_OSES = {
38
+ macos: { formats: ['app', 'dmg', 'mas'], output: DEFAULT_OUTPUT },
39
+ linux: { formats: [...LINUX_FORMATS], output: 'dist/linux' },
40
+ };
32
41
  const HERMES_FRAMEWORK = 'hermesvm.framework';
33
42
 
34
- export const PACKAGE_USAGE = `Usage: ng-native-desktop package [--format app|dmg|mas] [--output <dir>] [--feed-url <url> [--sparkle-key <key>]] [--skip-notarize]
43
+ /** @type {readonly string[]} */
44
+ const ARCHES = ['x64', 'arm64', 'all'];
45
+
46
+ /** The flags only a Linux package takes. */
47
+ const LINUX_FLAGS = /** @type {const} */ (['license', 'homepage', 'categories', 'maintainer']);
48
+
49
+ export const PACKAGE_USAGE = `Usage: ng-native-desktop package [--os macos|linux] [--arch x64|arm64|all] [--format <format>] [--output <dir>]
50
+ [--feed-url <url> [--sparkle-key <key>]] [--skip-notarize]
51
+ [--license <spdx>] [--homepage <url>] [--categories <list>] [--maintainer <name and email>]
35
52
 
36
- Builds the app for release, universal for arm64 and x86_64, into dist/macos. Needs full Xcode.
53
+ Builds the app for release into dist/<os>: for macOS universal for arm64 and x86_64 (needs full
54
+ Xcode), for Linux one package for each architecture.
37
55
 
56
+ --os <os> the OS to package for: macos or linux (default: this machine's)
57
+ --arch <arch> x64, arm64 or all (default): macOS keeps only the one asked for of its
58
+ universal build; Linux makes a package for each
59
+ --output <dir> where the packages go (default: dist/<os>)
60
+
61
+ macOS formats:
38
62
  --format app an ad-hoc signed .app (default)
39
63
  --format dmg a Developer ID signed, notarised and stapled .dmg
40
64
  --format mas a sandboxed Mac App Store .pkg
41
- --output <dir> where the packages go (default: dist/macos)
42
65
  --feed-url <url> dmg only: the Sparkle appcast the app updates from, embedding Sparkle
43
66
  --sparkle-key <key> with --feed-url: Sparkle's public EdDSA key, which updates are checked
44
67
  against (or NGN_SPARKLE_PUBLIC_KEY)
45
68
  --skip-notarize dmg only, for testing on this Mac: no notarisation, and signed ad hoc
46
69
  unless NGN_SIGN_IDENTITY is set. Gatekeeper refuses it on any other Mac.
47
70
 
71
+ Linux formats, each with a desktop entry, hicolor icons and AppStream metainfo:
72
+ --format app a runnable folder and its .tar.gz (default)
73
+ --format deb a .deb for Debian 13 and Ubuntu 24.04 or later
74
+ --format rpm an .rpm for Fedora and the RHEL family 9 or later (rpmbuild, or a container)
75
+ --format flatpak a .flatpak on the GNOME runtime, its OSTree repo and manifest (flatpak-builder,
76
+ or a container)
77
+ --license <spdx> the app's license: rpm and flatpak need it
78
+ --homepage <url> the app's web page
79
+ --categories <list> freedesktop categories, with a main one (default: Utility)
80
+ --maintainer <name and email> "Ada Lovelace <ada@example.com>": deb needs it
81
+ rpm and flatpak run in a container (AlmaLinux 9, Fedora 44) through Docker or Podman where the
82
+ tool is not installed, which is how a Mac makes them.
83
+
48
84
  Signing and notarising read the environment:
49
85
  NGN_SIGN_IDENTITY the codesign identity (dmg: Developer ID Application, mas: Apple Distribution)
50
86
  NGN_NOTARY_PROFILE a notarytool keychain profile (xcrun notarytool store-credentials), or
51
87
  APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER an App Store Connect API key
52
88
  mas: NGN_INSTALLER_IDENTITY, NGN_PROVISIONING_PROFILE and APPLE_TEAM_ID
53
- dmg with ios.usesAppleSignIn: NGN_PROVISIONING_PROFILE (Developer ID) and APPLE_TEAM_ID`;
89
+ dmg with ios.usesAppleSignIn: NGN_PROVISIONING_PROFILE (Developer ID) and APPLE_TEAM_ID
90
+ NGN_GPG_KEY Linux: the GPG key that signs an app's .tar.gz, an rpm and a
91
+ Flatpak repo, in the agent or GNUPGHOME`;
54
92
 
55
93
  /**
56
- * @typedef {{ command: 'package', format: 'app' | 'dmg' | 'mas', output: string, feedUrl: string | undefined, sparkleKey: string | undefined, skipNotarize: boolean }} PackageCommand
94
+ * @typedef {{ command: 'package', os: 'macos', arch: 'x64' | 'arm64' | 'all', format: 'app' | 'dmg' | 'mas', output: string, feedUrl: string | undefined, sparkleKey: string | undefined, skipNotarize: boolean }} MacPackageCommand
95
+ * @typedef {{ command: 'package', os: 'linux' } & import('./package-linux.mjs').LinuxPackageCommand} LinuxCommand
96
+ * @typedef {MacPackageCommand | LinuxCommand} PackageCommand
57
97
  * @typedef {import('./host.mjs').system} System
58
98
  * @typedef {import('./app-config.mjs').DesktopAppConfig} DesktopAppConfig
59
99
  */
60
100
 
101
+ /**
102
+ * @typedef {{ os?: string, arch: string, format: string, output?: string, 'feed-url'?: string, 'sparkle-key'?: string, 'skip-notarize': boolean, license?: string, homepage?: string, categories?: string, maintainer?: string }} PackageFlags
103
+ */
104
+
61
105
  /**
62
106
  * @param {string[]} args the arguments after `package`
107
+ * @param {string} [platform] this machine's, which `--os` defaults to
63
108
  * @returns {PackageCommand}
64
109
  */
65
- export function parsePackage(args) {
110
+ export function parsePackage(args, platform = process.platform) {
66
111
  const { values } = parseArgs({
67
112
  args,
68
113
  options: {
114
+ os: { type: 'string' },
115
+ arch: { type: 'string', default: 'all' },
69
116
  format: { type: 'string', default: 'app' },
70
- output: { type: 'string', default: DEFAULT_OUTPUT },
117
+ output: { type: 'string' },
71
118
  'feed-url': { type: 'string' },
72
119
  'sparkle-key': { type: 'string' },
73
120
  'skip-notarize': { type: 'boolean', default: false },
121
+ license: { type: 'string' },
122
+ homepage: { type: 'string' },
123
+ categories: { type: 'string' },
124
+ maintainer: { type: 'string' },
74
125
  },
75
126
  });
127
+ const os = values.os ?? (platform === 'linux' ? 'linux' : 'macos');
128
+ if (os !== 'macos' && os !== 'linux') {
129
+ throw new UsageError(`--os takes macos or linux, not "${os}".`);
130
+ }
131
+ const arch = /** @type {'x64' | 'arm64' | 'all'} */ (values.arch);
132
+ if (!ARCHES.includes(arch)) {
133
+ throw new UsageError(`--arch takes x64, arm64 or all, not "${arch}".`);
134
+ }
135
+ const { formats, output: defaultOutput } = PACKAGE_OSES[os];
76
136
  const format = values.format;
77
- if (!FORMATS.includes(format)) {
78
- throw new UsageError(`--format takes app, dmg or mas, not "${format}".`);
137
+ if (!formats.includes(format)) {
138
+ throw new UsageError(
139
+ `--format takes ${formats.slice(0, -1).join(', ')} or ${formats.at(-1)} for ${os}, not "${format}".`,
140
+ );
79
141
  }
80
- const feedUrl = values['feed-url'];
81
- if (feedUrl !== undefined) {
82
- if (format !== 'dmg') {
83
- throw new UsageError(
84
- `--feed-url is for --format dmg only: ${format === 'mas' ? 'the Mac App Store updates a mas build itself' : 'an app build has no updater'}.`,
85
- );
86
- }
87
- if (!/^https:\/\/[^\s/]+/.test(feedUrl)) {
88
- throw new UsageError(
89
- `--feed-url takes the https URL of a Sparkle appcast, not "${feedUrl}".`,
90
- );
91
- }
142
+ const common = {
143
+ command: /** @type {const} */ ('package'),
144
+ arch,
145
+ output: values.output ?? defaultOutput,
146
+ };
147
+ return os === 'linux' ? parseLinuxFlags(values, common) : parseMacFlags(values, common);
148
+ }
149
+
150
+ /**
151
+ * The flags of a Linux package, refusing macOS's.
152
+ *
153
+ * @param {PackageFlags} values
154
+ * @param {{ command: 'package', arch: 'x64' | 'arm64' | 'all', output: string }} common
155
+ * @returns {LinuxCommand}
156
+ */
157
+ function parseLinuxFlags(values, common) {
158
+ const macOnly = /** @type {const} */ (['feed-url', 'sparkle-key', 'skip-notarize']).find(
159
+ (flag) => values[flag],
160
+ );
161
+ if (macOnly) {
162
+ throw new UsageError(
163
+ `--${macOnly} is for --os macos only: Linux packages have no Sparkle or notarisation.`,
164
+ );
165
+ }
166
+ checkLinuxFlags(values);
167
+ const given = LINUX_FLAGS.filter((flag) => values[flag] !== undefined);
168
+ return {
169
+ ...common,
170
+ os: 'linux',
171
+ format: /** @type {import('./package-linux.mjs').LinuxFormat} */ (values.format),
172
+ ...Object.fromEntries(given.map((flag) => [flag, values[flag]])),
173
+ };
174
+ }
175
+
176
+ /**
177
+ * The flags of a macOS package, refusing Linux's.
178
+ *
179
+ * @param {PackageFlags} values
180
+ * @param {{ command: 'package', arch: 'x64' | 'arm64' | 'all', output: string }} common
181
+ * @returns {MacPackageCommand}
182
+ */
183
+ function parseMacFlags(values, common) {
184
+ const format = /** @type {'app' | 'dmg' | 'mas'} */ (values.format);
185
+ const linuxOnly = LINUX_FLAGS.find((flag) => values[flag] !== undefined);
186
+ if (linuxOnly) {
187
+ throw new UsageError(
188
+ `--${linuxOnly} is for --os linux only: a macOS app takes its details from app.json.`,
189
+ );
92
190
  }
191
+ const feedUrl = values['feed-url'];
192
+ if (feedUrl !== undefined) checkFeedUrl(feedUrl, format);
93
193
  const sparkleKey = values['sparkle-key'];
94
194
  if (sparkleKey !== undefined && feedUrl === undefined) {
95
195
  throw new UsageError(
@@ -102,14 +202,22 @@ export function parsePackage(args) {
102
202
  `--skip-notarize is for --format dmg only: ${format === 'mas' ? 'the Mac App Store notarises a mas build itself' : 'an app build is never notarised'}.`,
103
203
  );
104
204
  }
105
- return {
106
- command: 'package',
107
- format: /** @type {'app' | 'dmg' | 'mas'} */ (format),
108
- output: values.output,
109
- feedUrl,
110
- sparkleKey,
111
- skipNotarize,
112
- };
205
+ return { ...common, os: 'macos', format, feedUrl, sparkleKey, skipNotarize };
206
+ }
207
+
208
+ /**
209
+ * @param {string} feedUrl
210
+ * @param {'app' | 'dmg' | 'mas'} format
211
+ */
212
+ function checkFeedUrl(feedUrl, format) {
213
+ if (format !== 'dmg') {
214
+ throw new UsageError(
215
+ `--feed-url is for --format dmg only: ${format === 'mas' ? 'the Mac App Store updates a mas build itself' : 'an app build has no updater'}.`,
216
+ );
217
+ }
218
+ if (!/^https:\/\/[^\s/]+/.test(feedUrl)) {
219
+ throw new UsageError(`--feed-url takes the https URL of a Sparkle appcast, not "${feedUrl}".`);
220
+ }
113
221
  }
114
222
 
115
223
  /**
@@ -211,7 +319,7 @@ const DMG_SIGN_IN = ['NGN_SIGN_IDENTITY', 'NGN_PROVISIONING_PROFILE', 'APPLE_TEA
211
319
  * `dmg` with `--skip-notarize` needs none: it signs with `NGN_SIGN_IDENTITY` when that is set and
212
320
  * ad hoc (`-`) when not, and never asks Apple.
213
321
  *
214
- * @param {PackageCommand} options
322
+ * @param {MacPackageCommand} options
215
323
  * @param {Record<string, string | undefined>} env
216
324
  */
217
325
  function credentials({ format, skipNotarize, feedUrl }, env) {
@@ -597,7 +705,7 @@ function notarise(sys, file, notary, staple = file) {
597
705
  * Sparkle's public EdDSA key for a package with a feed: `--sparkle-key`, else
598
706
  * `NGN_SPARKLE_PUBLIC_KEY`. Without one Sparkle would refuse every update, so it stops first.
599
707
  *
600
- * @param {PackageCommand} options
708
+ * @param {MacPackageCommand} options
601
709
  * @param {Record<string, string | undefined>} env
602
710
  */
603
711
  function sparkleKeyFor(options, env) {
@@ -676,6 +784,25 @@ function copyDocumentIcons(sys, cwd, config, resources) {
676
784
  }
677
785
  }
678
786
 
787
+ /**
788
+ * Strips the executable's local symbols, which nothing resolves at run time (the exported ones
789
+ * stay), then keeps only the architecture `--arch` asks for of the universal build.
790
+ *
791
+ * @param {System} sys
792
+ * @param {string} executable
793
+ * @param {{ arch: 'x64' | 'arm64' | 'all', staging: string }} options
794
+ */
795
+ function stripExecutable(sys, executable, { arch, staging }) {
796
+ expectSuccess(sys.run('strip', ['-x', executable]), `strip could not strip ${executable}.`);
797
+ if (arch === 'all') return;
798
+ const thin = path.join(staging, 'thin');
799
+ expectSuccess(
800
+ sys.run('lipo', [executable, '-thin', arch === 'x64' ? 'x86_64' : 'arm64', '-output', thin]),
801
+ `lipo could not take ${arch} out of ${executable}.`,
802
+ );
803
+ sys.copy(thin, executable);
804
+ }
805
+
679
806
  /**
680
807
  * Builds the app and makes the package `options.format` asks for. Returns the exit status.
681
808
  *
@@ -683,6 +810,16 @@ function copyDocumentIcons(sys, cwd, config, resources) {
683
810
  * @param {System} sys
684
811
  */
685
812
  export async function packageApp(options, sys) {
813
+ return options.os === 'linux' ? packageLinux(options, sys) : packageMac(options, sys);
814
+ }
815
+
816
+ /**
817
+ * Builds the macOS app and makes the package `options.format` asks for. Returns the exit status.
818
+ *
819
+ * @param {MacPackageCommand} options
820
+ * @param {System} sys
821
+ */
822
+ async function packageMac(options, sys) {
686
823
  if (sys.platform !== 'darwin') {
687
824
  throw new UsageError('Packaging for macOS runs on macOS only.');
688
825
  }
@@ -727,8 +864,7 @@ export async function packageApp(options, sys) {
727
864
  sys.copy(bytecode, path.join(resources, 'main.jsbundle'));
728
865
  const executable = path.join(contents, 'MacOS', config.name);
729
866
  sys.copy(path.join(buildDir, 'appkit', 'ngn-macos'), executable);
730
- // Local symbols only, which nothing resolves at run time; the exported ones stay.
731
- expectSuccess(sys.run('strip', ['-x', executable]), `strip could not strip ${executable}.`);
867
+ stripExecutable(sys, executable, { arch: options.arch, staging });
732
868
  const hermes = embedHermes(sys, buildDir, contents);
733
869
  const iconName = config.icon
734
870
  ? compileIcon(sys, path.resolve(cwd, config.icon), resources, staging)
@@ -849,7 +985,7 @@ function embedSparkle(sys, buildDir, contents) {
849
985
  * only a real identity can get.
850
986
  *
851
987
  * @param {System} sys
852
- * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: PackageCommand, signIn: boolean, push: boolean, hermes: string | null }} build
988
+ * @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: MacPackageCommand, signIn: boolean, push: boolean, hermes: string | null }} build
853
989
  * @returns {string[]} the files made beside the app
854
990
  */
855
991
  function shipDmg(
package/bin/plist.mjs CHANGED
@@ -62,7 +62,11 @@ function value(item, indent) {
62
62
  throw new Error(`plist: cannot write ${String(item)}`);
63
63
  }
64
64
 
65
- /** @param {string} text */
66
- function escape(text) {
65
+ /**
66
+ * `text` as XML character data.
67
+ *
68
+ * @param {string} text
69
+ */
70
+ export function escape(text) {
67
71
  return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
68
72
  }
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Scales a PNG app icon to the hicolor theme's sizes, in JavaScript, so a Linux package's icons come
3
+ * out the same from a Mac as from Linux with no image tool. It reads the PNGs an icon is saved as
4
+ * (1 to 16 bits a sample; grey, RGB, palette, with alpha or not; not interlaced, with a `tRNS` colour
5
+ * key or palette alpha) and writes 8-bit RGBA, averaging each output pixel's area with its colour
6
+ * weighted by alpha.
7
+ */
8
+ import { crc32, deflateSync, inflateSync } from 'node:zlib';
9
+
10
+ const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
11
+
12
+ /** Samples a pixel has, by PNG colour type. */
13
+ const CHANNELS = /** @type {Record<number, number>} */ ({ 0: 1, 2: 3, 3: 1, 4: 2, 6: 4 });
14
+
15
+ /**
16
+ * @typedef {{ width: number, height: number, rgba: Uint8Array }} Image
17
+ */
18
+
19
+ /**
20
+ * @param {number} a
21
+ * @param {number} b
22
+ * @param {number} c
23
+ */
24
+ function paeth(a, b, c) {
25
+ const p = a + b - c;
26
+ const pa = Math.abs(p - a);
27
+ const pb = Math.abs(p - b);
28
+ const pc = Math.abs(p - c);
29
+ if (pa <= pb && pa <= pc) return a;
30
+ return pb <= pc ? b : c;
31
+ }
32
+
33
+ /**
34
+ * @typedef {{ width: number, height: number, depth: number, type: number, palette: Buffer | null, transparency: Buffer | null, data: Buffer[] }} PngChunks
35
+ */
36
+
37
+ /**
38
+ * The chunks of a PNG file this reads: the header's fields, the palette and its alpha, and the
39
+ * image data.
40
+ *
41
+ * @param {Buffer} file
42
+ * @returns {PngChunks}
43
+ */
44
+ function readChunks(file) {
45
+ /** @type {PngChunks} */
46
+ const png = {
47
+ width: 0,
48
+ height: 0,
49
+ depth: 0,
50
+ type: 0,
51
+ palette: null,
52
+ transparency: null,
53
+ data: [],
54
+ };
55
+ for (let at = 8; at + 8 <= file.length;) {
56
+ const length = file.readUInt32BE(at);
57
+ const kind = file.toString('ascii', at + 4, at + 8);
58
+ const body = file.subarray(at + 8, at + 8 + length);
59
+ at += 12 + length;
60
+ if (kind === 'IEND') break;
61
+ if (kind === 'IHDR') readHeader(png, body);
62
+ else if (kind === 'PLTE') png.palette = body;
63
+ else if (kind === 'tRNS') png.transparency = body;
64
+ else if (kind === 'IDAT') png.data.push(body);
65
+ }
66
+ return png;
67
+ }
68
+
69
+ /**
70
+ * @param {PngChunks} png
71
+ * @param {Buffer} body
72
+ */
73
+ function readHeader(png, body) {
74
+ png.width = body.readUInt32BE(0);
75
+ png.height = body.readUInt32BE(4);
76
+ png.depth = body[8] ?? 0;
77
+ png.type = body[9] ?? 0;
78
+ if (png.width > MAX_SIDE || png.height > MAX_SIDE) {
79
+ throw new Error(
80
+ `it is ${png.width} by ${png.height}; save it at ${MAX_SIDE} pixels a side or fewer`,
81
+ );
82
+ }
83
+ if (body[12] !== 0) throw new Error('it is interlaced; save it without interlacing');
84
+ }
85
+
86
+ /**
87
+ * A byte with its row's filter undone, from the bytes to its left, above, and above-left.
88
+ *
89
+ * @param {number} filter
90
+ * @param {number} value
91
+ * @param {number} left
92
+ * @param {number} up
93
+ * @param {number} corner
94
+ */
95
+ function unfilter(filter, value, left, up, corner) {
96
+ const predictors = [0, left, up, (left + up) >> 1, paeth(left, up, corner)];
97
+ const predicted = predictors[filter];
98
+ if (predicted === undefined)
99
+ throw new Error(`a row has filter ${filter}, which PNG does not define`);
100
+ return (value + predicted) & 0xff;
101
+ }
102
+
103
+ /**
104
+ * The image's rows with each row's filter undone, `stride` bytes a row.
105
+ *
106
+ * @param {Buffer} raw
107
+ * @param {{ height: number, stride: number, bytesPerPixel: number }} layout
108
+ */
109
+ function unfilterRows(raw, { height, stride, bytesPerPixel }) {
110
+ if (raw.length < (stride + 1) * height) throw new Error('its image data is cut short');
111
+ const rows = Buffer.alloc(stride * height);
112
+ const at = (/** @type {number} */ index) => (index >= 0 ? (rows[index] ?? 0) : 0);
113
+ for (let y = 0; y < height; y++) {
114
+ const filter = raw[y * (stride + 1)] ?? 0;
115
+ const out = y * stride;
116
+ for (let x = 0; x < stride; x++) {
117
+ const left = x >= bytesPerPixel ? at(out + x - bytesPerPixel) : 0;
118
+ const corner = x >= bytesPerPixel ? at(out + x - stride - bytesPerPixel) : 0;
119
+ const value = raw[y * (stride + 1) + 1 + x] ?? 0;
120
+ rows[out + x] = unfilter(filter, value, left, at(out + x - stride), corner);
121
+ }
122
+ }
123
+ return rows;
124
+ }
125
+
126
+ /**
127
+ * One pixel as RGBA, from its samples as stored (`raw`, at the image's own depth) and, for a palette
128
+ * image, the palette and its alpha. A grey or RGB image's one transparent colour (its `tRNS` key) is
129
+ * compared with the stored samples, before they are reduced to 8 bits.
130
+ *
131
+ * @param {PngChunks} png
132
+ * @param {(channel: number) => number} raw
133
+ * @returns {[number, number, number, number]}
134
+ */
135
+ function pixelColour({ type, depth, palette, transparency }, raw) {
136
+ const to8 = (/** @type {number} */ channel) => {
137
+ const value = raw(channel);
138
+ if (depth === 8) return value;
139
+ return depth === 16 ? value >> 8 : Math.round((value * 255) / ((1 << depth) - 1));
140
+ };
141
+ /** @param {number} channels */
142
+ const keyed = (channels) =>
143
+ transparency !== null &&
144
+ transparency.length >= channels * 2 &&
145
+ Array.from({ length: channels }, (_, channel) => channel).every(
146
+ (channel) => raw(channel) === transparency.readUInt16BE(channel * 2),
147
+ );
148
+ if (type === 0) return [to8(0), to8(0), to8(0), keyed(1) ? 0 : 255];
149
+ if (type === 4) return [to8(0), to8(0), to8(0), to8(1)];
150
+ if (type === 2) return [to8(0), to8(1), to8(2), keyed(3) ? 0 : 255];
151
+ if (type === 6) return [to8(0), to8(1), to8(2), to8(3)];
152
+ const index = raw(0);
153
+ const colours = /** @type {Buffer} */ (palette);
154
+ const alpha = transparency?.[index] ?? 255;
155
+ return [colours[index * 3] ?? 0, colours[index * 3 + 1] ?? 0, colours[index * 3 + 2] ?? 0, alpha];
156
+ }
157
+
158
+ /** The longest side this decodes: an icon is 1024, and a header can claim far more than it holds. */
159
+ const MAX_SIDE = 4096;
160
+
161
+ /**
162
+ * The image data inflated, which must be exactly `size` bytes: inflating stops there, so a
163
+ * stream that expands without end cannot use the memory.
164
+ *
165
+ * @param {Buffer[]} chunks
166
+ * @param {number} size
167
+ */
168
+ function inflated(chunks, size) {
169
+ let data;
170
+ try {
171
+ data = inflateSync(Buffer.concat(chunks), { maxOutputLength: size });
172
+ } catch (error) {
173
+ if (error instanceof RangeError) throw new Error('its image data is more than its header says');
174
+ throw error;
175
+ }
176
+ if (data.length !== size) throw new Error('its image data is not the size its header says');
177
+ return data;
178
+ }
179
+
180
+ /** The bit depths each colour type may have. */
181
+ const DEPTHS = /** @type {Record<number, number[]>} */ ({
182
+ 0: [1, 2, 4, 8, 16],
183
+ 2: [8, 16],
184
+ 3: [1, 2, 4, 8],
185
+ 4: [8, 16],
186
+ 6: [8, 16],
187
+ });
188
+
189
+ /**
190
+ * The image in a PNG file, as 8-bit RGBA. Throws, naming what it does not read, for anything else.
191
+ *
192
+ * @param {Uint8Array} bytes
193
+ * @returns {Image}
194
+ */
195
+ export function decodePng(bytes) {
196
+ const file = Buffer.from(bytes);
197
+ if (file.length < 8 || !file.subarray(0, 8).equals(SIGNATURE)) {
198
+ throw new Error('it is not a PNG file');
199
+ }
200
+ const png = readChunks(file);
201
+ const { width, height, depth, type } = png;
202
+ const channels = CHANNELS[type];
203
+ if (!channels || width === 0 || height === 0) throw new Error('its header is not one this reads');
204
+ if (!DEPTHS[type]?.includes(depth)) {
205
+ throw new Error(`it has ${depth} bits a channel, which PNG does not allow for its colour type`);
206
+ }
207
+ if (type === 3 && !png.palette) throw new Error('it has a palette type and no palette');
208
+ const bitsPerPixel = channels * depth;
209
+ const stride = Math.ceil((width * bitsPerPixel) / 8);
210
+ const rows = unfilterRows(inflated(png.data, (stride + 1) * height), {
211
+ height,
212
+ stride,
213
+ // A pixel narrower than a byte filters against the byte before it.
214
+ bytesPerPixel: Math.max(1, bitsPerPixel / 8),
215
+ });
216
+ const rgba = new Uint8Array(width * height * 4);
217
+ for (let pixel = 0; pixel < width * height; pixel++) {
218
+ const row = Math.floor(pixel / width) * stride;
219
+ const start = (pixel % width) * bitsPerPixel;
220
+ const raw = (/** @type {number} */ channel) => {
221
+ const bit = start + channel * depth;
222
+ const byte = row + (bit >> 3);
223
+ if (depth === 16) return ((rows[byte] ?? 0) << 8) | (rows[byte + 1] ?? 0);
224
+ if (depth === 8) return rows[byte] ?? 0;
225
+ return ((rows[byte] ?? 0) >> (8 - depth - (bit & 7))) & ((1 << depth) - 1);
226
+ };
227
+ rgba.set(pixelColour(png, raw), pixel * 4);
228
+ }
229
+ return { width, height, rgba };
230
+ }
231
+
232
+ /**
233
+ * `image` scaled to `size` by `size`, each output pixel the average of the source area it covers,
234
+ * with colour weighted by alpha so transparent pixels do not darken an edge.
235
+ *
236
+ * @param {Image} image
237
+ * @param {number} size
238
+ * @returns {Image}
239
+ */
240
+ export function scaleImage({ width, height, rgba }, size) {
241
+ const out = new Uint8Array(size * size * 4);
242
+ const sx = width / size;
243
+ const sy = height / size;
244
+ for (let y = 0; y < size; y++) {
245
+ const y0 = y * sy;
246
+ const y1 = y0 + sy;
247
+ for (let x = 0; x < size; x++) {
248
+ const x0 = x * sx;
249
+ const x1 = x0 + sx;
250
+ let r = 0;
251
+ let g = 0;
252
+ let b = 0;
253
+ let a = 0;
254
+ let area = 0;
255
+ for (let py = Math.floor(y0); py < Math.ceil(y1) && py < height; py++) {
256
+ const wy = Math.min(py + 1, y1) - Math.max(py, y0);
257
+ for (let px = Math.floor(x0); px < Math.ceil(x1) && px < width; px++) {
258
+ const w = wy * (Math.min(px + 1, x1) - Math.max(px, x0));
259
+ const i = (py * width + px) * 4;
260
+ const alpha = (rgba[i + 3] ?? 0) * w;
261
+ r += (rgba[i] ?? 0) * alpha;
262
+ g += (rgba[i + 1] ?? 0) * alpha;
263
+ b += (rgba[i + 2] ?? 0) * alpha;
264
+ a += alpha;
265
+ area += w;
266
+ }
267
+ }
268
+ const o = (y * size + x) * 4;
269
+ if (a > 0) {
270
+ out[o] = Math.round(r / a);
271
+ out[o + 1] = Math.round(g / a);
272
+ out[o + 2] = Math.round(b / a);
273
+ }
274
+ out[o + 3] = Math.round(a / area);
275
+ }
276
+ }
277
+ return { width: size, height: size, rgba: out };
278
+ }
279
+
280
+ /**
281
+ * @param {string} kind
282
+ * @param {Uint8Array} body
283
+ */
284
+ function chunk(kind, body) {
285
+ const length = Buffer.alloc(4);
286
+ length.writeUInt32BE(body.length);
287
+ const named = Buffer.concat([Buffer.from(kind, 'ascii'), body]);
288
+ const check = Buffer.alloc(4);
289
+ check.writeUInt32BE(crc32(named));
290
+ return Buffer.concat([length, named, check]);
291
+ }
292
+
293
+ /**
294
+ * An 8-bit RGBA PNG of `image`.
295
+ *
296
+ * @param {Image} image
297
+ */
298
+ export function encodePng({ width, height, rgba }) {
299
+ const header = Buffer.alloc(13);
300
+ header.writeUInt32BE(width, 0);
301
+ header.writeUInt32BE(height, 4);
302
+ header[8] = 8;
303
+ header[9] = 6;
304
+ const stride = width * 4;
305
+ const raw = Buffer.alloc((stride + 1) * height);
306
+ for (let y = 0; y < height; y++) {
307
+ Buffer.from(rgba.buffer, rgba.byteOffset + y * stride, stride).copy(raw, y * (stride + 1) + 1);
308
+ }
309
+ return Buffer.concat([
310
+ SIGNATURE,
311
+ chunk('IHDR', header),
312
+ chunk('IDAT', deflateSync(raw, { level: 9 })),
313
+ chunk('IEND', Buffer.alloc(0)),
314
+ ]);
315
+ }