@ng-native/desktop 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/package.mjs +65 -9
- package/bin/prebuilt.mjs +25 -4
- package/native/CMakeLists.txt +7 -2
- package/native/appkit/CMakeLists.txt +39 -5
- package/native/appkit/appkit-backend.mm +28 -3
- package/native/appkit/camera-sheet.h +59 -0
- package/native/appkit/camera-sheet.mm +344 -0
- package/native/appkit/camera-view.mm +5 -1
- package/native/appkit/camera.h +22 -0
- package/native/appkit/camera.mm +203 -69
- package/native/appkit/cg-canvas.h +8 -1
- package/native/appkit/cg-canvas.mm +166 -21
- package/native/appkit/header-toolbar.mm +4 -1
- package/native/appkit/host-view.mm +29 -1
- package/native/appkit/image-view.mm +31 -2
- package/native/appkit/main.mm +29 -69
- package/native/appkit/photo-library.mm +6 -6
- package/native/appkit/scroll-view.mm +57 -16
- package/native/appkit/scrollers.h +22 -2
- package/native/appkit/scrollers.mm +221 -2
- package/native/appkit/split-view.h +4 -0
- package/native/appkit/split-view.mm +57 -3
- package/native/appkit/surface-view.mm +5 -1
- package/native/appkit/svg-view.h +2 -1
- package/native/appkit/svg-view.mm +49 -3
- package/native/appkit/tab-walk.h +31 -0
- package/native/appkit/tab-walk.mm +64 -0
- package/native/appkit/text-input-field.h +5 -0
- package/native/appkit/text-input-field.mm +101 -20
- package/native/appkit/text-layout.h +7 -1
- package/native/appkit/text-layout.mm +161 -30
- package/native/appkit/web-view-component.h +4 -3
- package/native/appkit/web-view-component.mm +8 -2
- package/native/appkit/web-view.mm +7 -0
- package/native/cmake/react-native.cmake +9 -0
- package/native/cmake/runtime-dependencies.cmake +21 -0
- package/native/core/include/ngn/app-menus.h +8 -3
- package/native/core/include/ngn/back-swipe.h +16 -7
- package/native/core/include/ngn/camera.h +103 -9
- package/native/core/include/ngn/core-modules.h +3 -0
- package/native/core/include/ngn/dom-web-view.h +53 -0
- package/native/core/include/ngn/photo-library.h +7 -3
- package/native/core/include/ngn/runtime.h +10 -8
- package/native/core/include/ngn/safe-areas.h +5 -0
- package/native/core/include/ngn/scrollers.h +5 -0
- package/native/core/include/ngn/surface-metrics.h +51 -0
- package/native/core/include/ngn/svg.h +49 -8
- package/native/core/include/ngn/text-input.h +9 -0
- package/native/core/include/ngn/text-measurer.h +11 -0
- package/native/core/include/ngn/web-view.h +6 -2
- package/native/core/src/app-menus.cpp +10 -3
- package/native/core/src/back-swipe.cpp +12 -5
- package/native/core/src/dom-web-view.cpp +45 -0
- package/native/core/src/libraries/rnsvg.cpp +13 -0
- package/native/core/src/modules/app-modules.cpp +24 -15
- package/native/core/src/modules/camera.cpp +203 -23
- package/native/core/src/modules/photo-library.cpp +22 -8
- package/native/core/src/mounting-manager.cpp +4 -0
- package/native/core/src/runtime.cpp +6 -8
- package/native/core/src/safe-areas.cpp +7 -0
- package/native/core/src/scrollers.cpp +11 -0
- package/native/core/src/svg.cpp +324 -17
- package/native/core/src/text-input.cpp +13 -0
- package/native/core/src/text-layout-manager.cpp +13 -0
- package/native/core/src/web-view.cpp +1 -1
- package/native/scripts/build.sh +12 -2
- package/native/scripts/fetch-hermes.sh +70 -0
- package/native/scripts/launch-probe.sh +60 -0
- package/native/scripts/make-prebuilt.mjs +13 -6
- package/native/scripts/prebuilt-host-cache.mjs +1 -1
- package/native/shim/text-platform/react/renderer/textlayoutmanager/TextLayoutManager.h +52 -0
- package/package.json +2 -2
- package/prebuilt.json +6 -6
package/bin/package.mjs
CHANGED
|
@@ -29,6 +29,7 @@ export const MINIMUM_MACOS = '14.0';
|
|
|
29
29
|
export const DEFAULT_OUTPUT = 'dist/macos';
|
|
30
30
|
|
|
31
31
|
const FORMATS = ['app', 'dmg', 'mas'];
|
|
32
|
+
const HERMES_FRAMEWORK = 'hermesvm.framework';
|
|
32
33
|
|
|
33
34
|
export const PACKAGE_USAGE = `Usage: ng-native-desktop package [--format app|dmg|mas] [--output <dir>] [--feed-url <url> [--sparkle-key <key>]] [--skip-notarize]
|
|
34
35
|
|
|
@@ -439,16 +440,18 @@ function signsInWithApple(sys, expo, format) {
|
|
|
439
440
|
* network, the files the user picks, and the app's identity on the team. `appleSignIn` adds Sign
|
|
440
441
|
* in with Apple and `push` remote notifications (production APNs, which both distribution formats
|
|
441
442
|
* use), and either adds to a `dmg` the app's identity on the team, which its profile is for.
|
|
443
|
+
* `loadsAdHocFramework` turns off library validation in an ad hoc signed `dmg`, which loads its
|
|
444
|
+
* embedded Hermes framework with no team to check it against.
|
|
442
445
|
*
|
|
443
446
|
* @param {DesktopAppConfig} config
|
|
444
447
|
* @param {'app' | 'dmg' | 'mas'} format
|
|
445
|
-
* @param {{ bundleIdentifier: string, team?: string, appleSignIn?: boolean, push?: boolean }} identity
|
|
448
|
+
* @param {{ bundleIdentifier: string, team?: string, appleSignIn?: boolean, push?: boolean, loadsAdHocFramework?: boolean }} identity
|
|
446
449
|
* @returns {string | null}
|
|
447
450
|
*/
|
|
448
451
|
export function entitlements(
|
|
449
452
|
config,
|
|
450
453
|
format,
|
|
451
|
-
{ bundleIdentifier, team, appleSignIn = false, push = false },
|
|
454
|
+
{ bundleIdentifier, team, appleSignIn = false, push = false, loadsAdHocFramework = false },
|
|
452
455
|
) {
|
|
453
456
|
if (format === 'app') return null;
|
|
454
457
|
/** @type {import('./plist.mjs').PlistDict} */
|
|
@@ -458,6 +461,7 @@ export function entitlements(
|
|
|
458
461
|
if (appleSignIn) granted['com.apple.developer.applesignin'] = ['Default'];
|
|
459
462
|
if (push) granted['com.apple.developer.aps-environment'] = 'production';
|
|
460
463
|
if (format === 'dmg') {
|
|
464
|
+
if (loadsAdHocFramework) granted['com.apple.security.cs.disable-library-validation'] = true;
|
|
461
465
|
if (!appleSignIn && !push) return plist(granted);
|
|
462
466
|
return plist({
|
|
463
467
|
...granted,
|
|
@@ -716,11 +720,16 @@ export async function packageApp(options, sys) {
|
|
|
716
720
|
]),
|
|
717
721
|
'expo export:embed did not bundle the app for macos; the output above says why.',
|
|
718
722
|
);
|
|
719
|
-
|
|
723
|
+
// Compiled beside the bundle, then copied in: hermesc makes no folder, and an app with no assets
|
|
724
|
+
// has no Resources yet.
|
|
725
|
+
const bytecode = path.join(staging, 'main.jsbundle');
|
|
726
|
+
compileBytecode(sys, hermesc, javascript, bytecode);
|
|
727
|
+
sys.copy(bytecode, path.join(resources, 'main.jsbundle'));
|
|
720
728
|
const executable = path.join(contents, 'MacOS', config.name);
|
|
721
729
|
sys.copy(path.join(buildDir, 'appkit', 'ngn-macos'), executable);
|
|
722
730
|
// Local symbols only, which nothing resolves at run time; the exported ones stay.
|
|
723
731
|
expectSuccess(sys.run('strip', ['-x', executable]), `strip could not strip ${executable}.`);
|
|
732
|
+
const hermes = embedHermes(sys, buildDir, contents);
|
|
724
733
|
const iconName = config.icon
|
|
725
734
|
? compileIcon(sys, path.resolve(cwd, config.icon), resources, staging)
|
|
726
735
|
: null;
|
|
@@ -742,7 +751,7 @@ export async function packageApp(options, sys) {
|
|
|
742
751
|
|
|
743
752
|
const made = [app];
|
|
744
753
|
if (options.format === 'app') {
|
|
745
|
-
|
|
754
|
+
signAdHoc(sys, app, hermes);
|
|
746
755
|
} else if (options.format === 'dmg' && keys) {
|
|
747
756
|
made.push(
|
|
748
757
|
...shipDmg(sys, {
|
|
@@ -755,10 +764,13 @@ export async function packageApp(options, sys) {
|
|
|
755
764
|
options,
|
|
756
765
|
signIn,
|
|
757
766
|
push,
|
|
767
|
+
hermes,
|
|
758
768
|
}),
|
|
759
769
|
);
|
|
760
770
|
} else if (keys) {
|
|
761
|
-
made.push(
|
|
771
|
+
made.push(
|
|
772
|
+
shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, signIn, push, hermes }),
|
|
773
|
+
);
|
|
762
774
|
}
|
|
763
775
|
for (const file of made) console.log(path.relative(cwd, file));
|
|
764
776
|
return 0;
|
|
@@ -782,6 +794,36 @@ function fallbackIdentifier(format, expo) {
|
|
|
782
794
|
return `dev.ngnative.${slug || 'app'}`;
|
|
783
795
|
}
|
|
784
796
|
|
|
797
|
+
/**
|
|
798
|
+
* An `app` build's ad hoc signature, for this Mac: the embedded Hermes framework first, then the app.
|
|
799
|
+
*
|
|
800
|
+
* @param {System} sys
|
|
801
|
+
* @param {string} app
|
|
802
|
+
* @param {string | null} hermes
|
|
803
|
+
*/
|
|
804
|
+
function signAdHoc(sys, app, hermes) {
|
|
805
|
+
for (const target of hermes ? [hermes, app] : [app]) {
|
|
806
|
+
expectSuccess(sys.run('codesign', ['--force', '--sign', '-', target]), 'codesign failed.');
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* React Native's Hermes framework, which a host built against it links, from the host build into
|
|
812
|
+
* the app's Frameworks, where the binary's rpath finds it. Null for a host with Hermes linked in.
|
|
813
|
+
*
|
|
814
|
+
* @param {System} sys
|
|
815
|
+
* @param {string} buildDir
|
|
816
|
+
* @param {string} contents
|
|
817
|
+
* @returns {string | null} the embedded framework
|
|
818
|
+
*/
|
|
819
|
+
function embedHermes(sys, buildDir, contents) {
|
|
820
|
+
const hermes = path.join(buildDir, 'appkit', HERMES_FRAMEWORK);
|
|
821
|
+
if (!sys.exists(hermes)) return null;
|
|
822
|
+
const embedded = path.join(contents, 'Frameworks', HERMES_FRAMEWORK);
|
|
823
|
+
sys.copy(hermes, embedded);
|
|
824
|
+
return embedded;
|
|
825
|
+
}
|
|
826
|
+
|
|
785
827
|
/**
|
|
786
828
|
* Sparkle, from the host build, into the app's Frameworks.
|
|
787
829
|
*
|
|
@@ -807,12 +849,12 @@ function embedSparkle(sys, buildDir, contents) {
|
|
|
807
849
|
* only a real identity can get.
|
|
808
850
|
*
|
|
809
851
|
* @param {System} sys
|
|
810
|
-
* @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, options: PackageCommand, signIn: boolean, push: boolean }} build
|
|
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
|
|
811
853
|
* @returns {string[]} the files made beside the app
|
|
812
854
|
*/
|
|
813
855
|
function shipDmg(
|
|
814
856
|
sys,
|
|
815
|
-
{ config, app, output, staging, bundleIdentifier, keys, options, signIn, push },
|
|
857
|
+
{ config, app, output, staging, bundleIdentifier, keys, options, signIn, push, hermes },
|
|
816
858
|
) {
|
|
817
859
|
if (signIn || push) embedProfile(sys, keys, app);
|
|
818
860
|
const file = path.join(staging, 'entitlements.plist');
|
|
@@ -821,6 +863,8 @@ function shipDmg(
|
|
|
821
863
|
team: keys.team,
|
|
822
864
|
appleSignIn: signIn,
|
|
823
865
|
push,
|
|
866
|
+
// An ad hoc signature has no team for library validation to match the framework against.
|
|
867
|
+
loadsAdHocFramework: Boolean(hermes) && keys.identity === '-',
|
|
824
868
|
});
|
|
825
869
|
sys.writeFile(file, /** @type {string} */ (granted));
|
|
826
870
|
const timestamp = keys.identity === '-' ? '--timestamp=none' : '--timestamp';
|
|
@@ -839,6 +883,9 @@ function shipDmg(
|
|
|
839
883
|
]),
|
|
840
884
|
`codesign could not sign ${path.basename(target)}.`,
|
|
841
885
|
);
|
|
886
|
+
// Nested code before the app, with the app's identity: the hardened runtime loads a framework
|
|
887
|
+
// only from the app's own team.
|
|
888
|
+
if (hermes) sign(hermes);
|
|
842
889
|
if (options.feedUrl) signSparkle(path.join(app, 'Contents', 'Frameworks', 'Sparkle.framework'));
|
|
843
890
|
sign(app, ['--entitlements', file]);
|
|
844
891
|
|
|
@@ -931,9 +978,12 @@ function embedProfile(sys, keys, app) {
|
|
|
931
978
|
* Embeds the provisioning profile, signs inside the App Sandbox and makes the installer package.
|
|
932
979
|
*
|
|
933
980
|
* @param {System} sys
|
|
934
|
-
* @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, signIn: boolean, push: boolean }} build
|
|
981
|
+
* @param {{ config: DesktopAppConfig, app: string, output: string, staging: string, bundleIdentifier: string, keys: NonNullable<ReturnType<typeof credentials>>, signIn: boolean, push: boolean, hermes: string | null }} build
|
|
935
982
|
*/
|
|
936
|
-
function shipMas(
|
|
983
|
+
function shipMas(
|
|
984
|
+
sys,
|
|
985
|
+
{ config, app, output, staging, bundleIdentifier, keys, signIn, push, hermes },
|
|
986
|
+
) {
|
|
937
987
|
embedProfile(sys, keys, app);
|
|
938
988
|
const file = path.join(staging, 'entitlements.plist');
|
|
939
989
|
const granted = entitlements(config, 'mas', {
|
|
@@ -943,6 +993,12 @@ function shipMas(sys, { config, app, output, staging, bundleIdentifier, keys, si
|
|
|
943
993
|
push,
|
|
944
994
|
});
|
|
945
995
|
sys.writeFile(file, /** @type {string} */ (granted));
|
|
996
|
+
if (hermes) {
|
|
997
|
+
expectSuccess(
|
|
998
|
+
sys.run('codesign', ['--force', '--timestamp', '--sign', keys.identity, hermes]),
|
|
999
|
+
`codesign could not sign ${HERMES_FRAMEWORK}.`,
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
946
1002
|
expectSuccess(
|
|
947
1003
|
sys.run('codesign', [
|
|
948
1004
|
'--force',
|
package/bin/prebuilt.mjs
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
* `prebuilt.json` beside this package lists them, one entry per version and flavour; an entry
|
|
8
8
|
* that names no flavour is a release host. The release workflow writes each entry before
|
|
9
9
|
* the package is packed (`docs/desktop-host.md` has the steps), so the SHA-256 of each archive
|
|
10
|
-
* travels inside the npm package, not beside the archive it vouches for. An archive holds `appkit/ngn-macos`, `appkit/hermesc
|
|
11
|
-
* `appkit/Sparkle.framework`, the files a host build's `appkit` folder has, and unpacks into the
|
|
10
|
+
* travels inside the npm package, not beside the archive it vouches for. An archive holds `appkit/ngn-macos`, `appkit/hermesc`,
|
|
11
|
+
* `appkit/hermesvm.framework` and `appkit/Sparkle.framework`, the files a host build's `appkit` folder has, and unpacks into the
|
|
12
12
|
* per-user cache under its own hash, so a new archive never reuses an old one's files.
|
|
13
13
|
*
|
|
14
14
|
* `native/scripts/make-prebuilt.mjs` builds and packs one. The host is signed ad hoc unless
|
|
@@ -291,21 +291,41 @@ export function fetchPrebuilt(sys, host, cache) {
|
|
|
291
291
|
return dir;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/**
|
|
295
|
+
* The entitlements of an ad hoc signed host with the hardened runtime. Library validation loads
|
|
296
|
+
* only libraries from the process's own team, and an ad hoc signature has none, so it would refuse
|
|
297
|
+
* React Native's Hermes framework beside the binary. A real identity signs the framework too and
|
|
298
|
+
* keeps validation.
|
|
299
|
+
*/
|
|
300
|
+
export const AD_HOC_HOST_ENTITLEMENTS = `<?xml version="1.0" encoding="UTF-8"?>
|
|
301
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
302
|
+
<plist version="1.0">
|
|
303
|
+
<dict>
|
|
304
|
+
<key>com.apple.security.cs.disable-library-validation</key>
|
|
305
|
+
<true/>
|
|
306
|
+
</dict>
|
|
307
|
+
</plist>
|
|
308
|
+
`;
|
|
309
|
+
|
|
294
310
|
/**
|
|
295
311
|
* Strips each file's local symbols, then signs it with the hardened runtime: with
|
|
296
312
|
* `NGN_SIGN_IDENTITY` when that is set and not empty, ad hoc (`--sign -`, no timestamp) otherwise.
|
|
313
|
+
* `adHocEntitlements` go with an ad hoc signature only. A framework is signed as it is, unstripped.
|
|
297
314
|
* Throws when a command fails.
|
|
298
315
|
*
|
|
299
316
|
* @param {(command: string, args: string[]) => { status: number | null }} run
|
|
300
317
|
* @param {string[]} files
|
|
301
318
|
* @param {Record<string, string | undefined>} env
|
|
319
|
+
* @param {string} [adHocEntitlements]
|
|
302
320
|
*/
|
|
303
|
-
export function signPrebuiltFiles(run, files, env) {
|
|
321
|
+
export function signPrebuiltFiles(run, files, env, adHocEntitlements) {
|
|
304
322
|
const identity = env['NGN_SIGN_IDENTITY'] || '-';
|
|
323
|
+
const entitlements =
|
|
324
|
+
identity === '-' && adHocEntitlements ? ['--entitlements', adHocEntitlements] : [];
|
|
305
325
|
for (const file of files) {
|
|
306
326
|
// Before signing, which stripping would break.
|
|
307
327
|
for (const [command, args] of /** @type {[string, string[]][]} */ ([
|
|
308
|
-
['strip', ['-x', file]],
|
|
328
|
+
...(file.endsWith('.framework') ? [] : [['strip', ['-x', file]]]),
|
|
309
329
|
[
|
|
310
330
|
'codesign',
|
|
311
331
|
[
|
|
@@ -313,6 +333,7 @@ export function signPrebuiltFiles(run, files, env) {
|
|
|
313
333
|
'--options',
|
|
314
334
|
'runtime',
|
|
315
335
|
identity === '-' ? '--timestamp=none' : '--timestamp',
|
|
336
|
+
...entitlements,
|
|
316
337
|
'--sign',
|
|
317
338
|
identity,
|
|
318
339
|
file,
|
package/native/CMakeLists.txt
CHANGED
|
@@ -22,6 +22,7 @@ option(NGN_TESTS "Build the core tests" ON)
|
|
|
22
22
|
set(RN_DIR "" CACHE PATH "The installed react-native package")
|
|
23
23
|
set(NGN_SOURCES "" CACHE PATH "Sources fetched by scripts/fetch.sh (<cache>/src)")
|
|
24
24
|
set(NGN_HERMES_BUILD "" CACHE PATH "Hermes built by scripts/build-hermes.sh")
|
|
25
|
+
set(NGN_HERMES_PREBUILT "" CACHE PATH "React Native's prebuilt Hermes, from scripts/fetch-hermes.sh")
|
|
25
26
|
foreach(var RN_DIR NGN_SOURCES)
|
|
26
27
|
if(NOT IS_DIRECTORY "${${var}}")
|
|
27
28
|
message(FATAL_ERROR "${var} is not set to a directory; build through scripts/build.sh")
|
|
@@ -86,6 +87,7 @@ add_library(ngn_core STATIC
|
|
|
86
87
|
core/src/desktop-view-props.cpp
|
|
87
88
|
core/src/default-menu.cpp
|
|
88
89
|
core/src/dev-server.cpp
|
|
90
|
+
core/src/dom-web-view.cpp
|
|
89
91
|
core/src/focus-order.cpp
|
|
90
92
|
core/src/gestures.cpp
|
|
91
93
|
core/src/glass.cpp
|
|
@@ -210,7 +212,7 @@ if(NGN_TESTS)
|
|
|
210
212
|
appkit/web-view.mm appkit/tests/web-view.test.mm
|
|
211
213
|
appkit/expo-image-drawing.mm appkit/tests/expo-image.test.mm
|
|
212
214
|
appkit/expo-ui-renderer.mm appkit/tests/expo-ui.test.mm
|
|
213
|
-
appkit/camera.mm appkit/tests/camera.test.mm
|
|
215
|
+
appkit/camera.mm appkit/tests/camera.test.mm appkit/camera-sheet.mm appkit/system-access.mm appkit/tests/camera-sheet.test.mm
|
|
214
216
|
appkit/maps.mm appkit/tests/maps.test.mm
|
|
215
217
|
appkit/apple-authentication.mm appkit/tests/apple-authentication.test.mm
|
|
216
218
|
appkit/video.mm appkit/tests/video.test.mm
|
|
@@ -218,7 +220,7 @@ if(NGN_TESTS)
|
|
|
218
220
|
appkit/text-input-field.mm appkit/tests/text-input-field.test.mm
|
|
219
221
|
appkit/search-field.mm appkit/tests/search-field.test.mm
|
|
220
222
|
appkit/search-toolbar-item.mm appkit/tests/search-toolbar-item.test.mm
|
|
221
|
-
appkit/cg-canvas.mm appkit/tests/svg-effects.test.mm
|
|
223
|
+
appkit/cg-canvas.mm appkit/tests/svg-effects.test.mm appkit/tests/svg-text.test.mm
|
|
222
224
|
appkit/scrollers.mm appkit/tests/scrollers.test.mm
|
|
223
225
|
appkit/bookmarks.mm appkit/tests/bookmarks.test.mm
|
|
224
226
|
appkit/push.mm appkit/tests/push.test.mm
|
|
@@ -237,6 +239,9 @@ if(NGN_TESTS)
|
|
|
237
239
|
target_link_libraries(ngn_core_tests PRIVATE "-framework Foundation" "-framework Security" "-framework IOKit" "-framework SystemConfiguration" "-framework Network" "-framework AppKit" "-framework CoreText" "-framework ImageIO" "-framework Vision" "-framework UniformTypeIdentifiers" "-framework EventKit" "-framework AVFoundation" "-framework CoreMedia" "-framework Photos" "-framework PhotosUI" "-framework AppTrackingTransparency" "-framework AdSupport" "-framework CoreLocation" "-framework MapKit" "-framework WebKit" "-framework PDFKit" "-framework CoreImage" "-framework AuthenticationServices" "-framework AVKit" "-framework UserNotifications")
|
|
238
240
|
endif()
|
|
239
241
|
enable_testing()
|
|
242
|
+
if(NGN_HERMES_TEST_RPATH)
|
|
243
|
+
target_link_options(ngn_core_tests PRIVATE ${NGN_HERMES_TEST_RPATH})
|
|
244
|
+
endif()
|
|
240
245
|
add_test(NAME core COMMAND ngn_core_tests)
|
|
241
246
|
endif()
|
|
242
247
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# The AppKit backend and the ngn-macos binary. Everything links statically: the binary loads
|
|
2
2
|
# nothing from outside itself but the system's frameworks.
|
|
3
|
-
|
|
3
|
+
#
|
|
4
|
+
# Every source but main.mm, compiled once into objects the binary and the AppKit view tests
|
|
5
|
+
# (tests/views) both link whole.
|
|
6
|
+
add_library(ngn_appkit OBJECT
|
|
4
7
|
animation-frames.mm
|
|
5
8
|
app-info.mm
|
|
6
9
|
app-windows.mm
|
|
@@ -25,6 +28,7 @@ add_executable(ngn-macos
|
|
|
25
28
|
expo-ui-renderer.mm
|
|
26
29
|
expo-ui-view.mm
|
|
27
30
|
camera.mm
|
|
31
|
+
camera-sheet.mm
|
|
28
32
|
camera-view.mm
|
|
29
33
|
maps.mm
|
|
30
34
|
map-view.mm
|
|
@@ -47,7 +51,6 @@ add_executable(ngn-macos
|
|
|
47
51
|
symbol-view.mm
|
|
48
52
|
red-box.mm
|
|
49
53
|
share-picker.mm
|
|
50
|
-
main.mm
|
|
51
54
|
menu-bar.mm
|
|
52
55
|
glass-effect.mm
|
|
53
56
|
glass-view.mm
|
|
@@ -72,6 +75,7 @@ add_executable(ngn-macos
|
|
|
72
75
|
store-review.mm
|
|
73
76
|
system.mm
|
|
74
77
|
system-access.mm
|
|
78
|
+
tab-walk.mm
|
|
75
79
|
test-launch.mm
|
|
76
80
|
text-input-field.mm
|
|
77
81
|
text-layout.mm
|
|
@@ -80,10 +84,16 @@ add_executable(ngn-macos
|
|
|
80
84
|
updates.mm
|
|
81
85
|
web-browser.mm
|
|
82
86
|
app-updater.mm)
|
|
83
|
-
target_link_libraries(
|
|
87
|
+
target_link_libraries(ngn_appkit PUBLIC ngn_core_runtime ngn_libraries)
|
|
88
|
+
target_compile_options(ngn_appkit PUBLIC -fobjc-arc -Wall -Wno-unused-parameter)
|
|
89
|
+
set(NGN_APPKIT_FRAMEWORKS
|
|
84
90
|
"-framework AppKit" "-framework Foundation" "-framework CoreText" "-framework ImageIO" "-framework QuartzCore" "-framework Security" "-framework IOKit" "-framework UniformTypeIdentifiers" "-framework UserNotifications" "-framework LocalAuthentication" "-framework CoreLocation" "-framework CoreServices" "-framework SystemConfiguration" "-framework Network" "-framework AuthenticationServices" "-framework Vision" "-framework EventKit" "-framework StoreKit" "-framework AVFoundation" "-framework CoreMedia" "-framework Photos" "-framework PhotosUI" "-framework AppTrackingTransparency" "-framework AdSupport" "-framework MapKit" "-framework WebKit" "-framework PDFKit" "-framework CoreImage" "-framework AVKit")
|
|
91
|
+
|
|
92
|
+
add_executable(ngn-macos
|
|
93
|
+
main.mm)
|
|
94
|
+
# The autolinked code (cmake/linked-modules.cmake), which only a target linking it directly takes whole.
|
|
95
|
+
target_link_libraries(ngn-macos PRIVATE ngn_appkit ${NGN_LINKED} ${NGN_APPKIT_FRAMEWORKS})
|
|
85
96
|
ngn_link_swift(ngn-macos)
|
|
86
|
-
target_compile_options(ngn-macos PRIVATE -fobjc-arc -Wall -Wno-unused-parameter)
|
|
87
97
|
# A Release build is what a packaged app ships: the linker drops the code nothing reaches.
|
|
88
98
|
target_link_options(ngn-macos PRIVATE $<$<CONFIG:Release>:-Wl,-dead_strip>)
|
|
89
99
|
# The React Native the host is built from, which PlatformConstants reports and React Native's
|
|
@@ -95,8 +105,16 @@ target_compile_definitions(ngn-macos PRIVATE NGN_REACT_NATIVE_VERSION="${_rn_ver
|
|
|
95
105
|
# The hermesc built with the Hermes the binary links, beside it, where `package` takes it from to
|
|
96
106
|
# compile the bundle to bytecode of the version this Hermes runs.
|
|
97
107
|
add_custom_command(TARGET ngn-macos POST_BUILD
|
|
98
|
-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${
|
|
108
|
+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NGN_HERMESC} $<TARGET_FILE_DIR:ngn-macos>/hermesc
|
|
99
109
|
VERBATIM)
|
|
110
|
+
# React Native's prebuilt Hermes beside the binary, which loads it from there in a build and
|
|
111
|
+
# `package` embeds in Contents/Frameworks.
|
|
112
|
+
if(NGN_HERMES_FRAMEWORK)
|
|
113
|
+
add_custom_command(TARGET ngn-macos POST_BUILD
|
|
114
|
+
COMMAND rm -rf $<TARGET_FILE_DIR:ngn-macos>/hermesvm.framework
|
|
115
|
+
COMMAND ditto ${NGN_HERMES_FRAMEWORK} $<TARGET_FILE_DIR:ngn-macos>/hermesvm.framework
|
|
116
|
+
VERBATIM)
|
|
117
|
+
endif()
|
|
100
118
|
|
|
101
119
|
# Sparkle's framework beside the binary, where `package --format dmg` takes it from to embed it.
|
|
102
120
|
# The binary never links it: it loads it at runtime in a dmg build only (app-updater.mm).
|
|
@@ -107,3 +125,19 @@ if(EXISTS ${_sparkle})
|
|
|
107
125
|
COMMAND ditto ${_sparkle} $<TARGET_FILE_DIR:ngn-macos>/Sparkle.framework
|
|
108
126
|
VERBATIM)
|
|
109
127
|
endif()
|
|
128
|
+
|
|
129
|
+
# The AppKit view tests: views mounted from Fabric mutations into an offscreen window, through the
|
|
130
|
+
# backend the binary uses. Built with the core tests, and run beside them.
|
|
131
|
+
if(NGN_TESTS)
|
|
132
|
+
add_executable(ngn_appkit_tests ../core/tests/main.cpp tests/views/accessibility.test.mm tests/views/svg-foreign-object.test.mm
|
|
133
|
+
tests/views/tab-walk.test.mm tests/views/camera-view.test.mm tests/views/text-input-alignment.test.mm
|
|
134
|
+
tests/views/image-view.test.mm tests/views/modal-beside-split.test.mm
|
|
135
|
+
tests/views/split-under-pushed-screen.test.mm)
|
|
136
|
+
target_include_directories(ngn_appkit_tests PRIVATE ../core/tests)
|
|
137
|
+
target_link_libraries(ngn_appkit_tests PRIVATE ngn_appkit doctest ${NGN_APPKIT_FRAMEWORKS})
|
|
138
|
+
if(NGN_HERMES_TEST_RPATH)
|
|
139
|
+
target_link_options(ngn_appkit_tests PRIVATE ${NGN_HERMES_TEST_RPATH})
|
|
140
|
+
endif()
|
|
141
|
+
ngn_link_swift(ngn_appkit_tests)
|
|
142
|
+
add_test(NAME appkit COMMAND ngn_appkit_tests)
|
|
143
|
+
endif()
|
|
@@ -78,7 +78,7 @@ void AppKitBackend::deleteView(SurfaceId, Tag tag) {
|
|
|
78
78
|
[sourceLists_ removeObjectForKey:@(tag)];
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
void AppKitBackend::insertChild(SurfaceId, Tag parent, Tag child, int index) {
|
|
81
|
+
void AppKitBackend::insertChild(SurfaceId surfaceId, Tag parent, Tag child, int index) {
|
|
82
82
|
NGNView *parentView = views_[@(parent)];
|
|
83
83
|
NGNView *childView = views_[@(child)];
|
|
84
84
|
if (parentView == nil || childView == nil) {
|
|
@@ -86,7 +86,16 @@ void AppKitBackend::insertChild(SurfaceId, Tag parent, Tag child, int index) {
|
|
|
86
86
|
}
|
|
87
87
|
// The index counts Fabric children only: a TextInput holds an NSTextField of its own.
|
|
88
88
|
if ([childView isKindOfClass:NGNModalHostView.class] && ![childView isKindOfClass:NGNPresentedScreenView.class]) {
|
|
89
|
-
|
|
89
|
+
// A view beside a split view at the root has no window: the split view's controller took the
|
|
90
|
+
// window's content, surface and all. The modal goes over the surface's window all the same.
|
|
91
|
+
NSView *over = parentView;
|
|
92
|
+
if (over.window == nil) {
|
|
93
|
+
// A surface already removed (a mount queued before it went) has no window to give.
|
|
94
|
+
NGNSurfaceView *surface = surfaces_[@(surfaceId)];
|
|
95
|
+
NSView *content = surface != nil ? NGNWindowOfSplit(surface).contentView : nil;
|
|
96
|
+
over = content != nil ? content : parentView;
|
|
97
|
+
}
|
|
98
|
+
[(NGNModalHostView *)childView presentOver:over];
|
|
90
99
|
return;
|
|
91
100
|
}
|
|
92
101
|
if ([parentView conformsToProtocol:@protocol(NGNMountsChildren)]) {
|
|
@@ -155,7 +164,23 @@ void AppKitBackend::dispatchCommand(Tag tag, const std::string &name, const foll
|
|
|
155
164
|
}
|
|
156
165
|
|
|
157
166
|
void AppKitBackend::setCovered(SurfaceId, Tag tag, bool covered) {
|
|
158
|
-
views_[@(tag)]
|
|
167
|
+
NGNView *screen = views_[@(tag)];
|
|
168
|
+
if (screen == nil) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
screen.covered = covered;
|
|
172
|
+
// A window's split view on the covered screen gives the window back to the screen in front.
|
|
173
|
+
// ponytail: walks the screen's views on each push and pop; keep a registry if that shows up.
|
|
174
|
+
NSMutableArray<NSView *> *queue = [NSMutableArray arrayWithObject:screen];
|
|
175
|
+
while (queue.count > 0) {
|
|
176
|
+
NSView *view = queue.firstObject;
|
|
177
|
+
[queue removeObjectAtIndex:0];
|
|
178
|
+
if ([view isKindOfClass:NGNSplitView.class]) {
|
|
179
|
+
[(NGNSplitView *)view setScreenCovered:covered];
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
[queue addObjectsFromArray:view.subviews];
|
|
183
|
+
}
|
|
159
184
|
}
|
|
160
185
|
|
|
161
186
|
NGNHeaderToolbar *AppKitBackend::toolbarFor(SurfaceId surfaceId) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The host's camera for NgNativeImagePicker's launchCameraAsync (the core's CameraSheet): macOS has
|
|
2
|
+
// no system camera screen, so a sheet on the key window shows the camera's preview, mirrored as
|
|
3
|
+
// Photo Booth and FaceTime show it, with Cancel (Escape) and the shutter (Return) below it. The
|
|
4
|
+
// photo or movie itself is not mirrored, as on iOS. The sheet is a picker's size (pickerSheet).
|
|
5
|
+
//
|
|
6
|
+
// In photo mode the shutter is Take Photo. In video mode it is Record, then Stop, with the time
|
|
7
|
+
// recorded beside it; the recording also stops at the request's limit. A request for both shows a
|
|
8
|
+
// Photo and Video switch, in photo mode first, as iOS's camera opens; it is fixed while recording.
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#include "ngn/camera.h"
|
|
12
|
+
|
|
13
|
+
#include <memory>
|
|
14
|
+
|
|
15
|
+
namespace ngn::appkit {
|
|
16
|
+
|
|
17
|
+
std::shared_ptr<CameraSheet> makeCameraSheet();
|
|
18
|
+
|
|
19
|
+
} // namespace ngn::appkit
|
|
20
|
+
|
|
21
|
+
#ifdef __OBJC__
|
|
22
|
+
#import <AVFoundation/AVFoundation.h>
|
|
23
|
+
#import <AppKit/AppKit.h>
|
|
24
|
+
|
|
25
|
+
#import "camera.h"
|
|
26
|
+
|
|
27
|
+
namespace ngn::appkit {
|
|
28
|
+
// The window the sheet shows on: the key window, the main one, or, in an app that is not active
|
|
29
|
+
// (as just after an OS permission prompt), its front window that can hold a sheet; nil for none.
|
|
30
|
+
NSWindow *windowForSheet();
|
|
31
|
+
} // namespace ngn::appkit
|
|
32
|
+
|
|
33
|
+
// What the sheet answers: a photo written as the request asks, with its size and the camera's EXIF
|
|
34
|
+
// (nil when it has none); a movie, with its size and length; or neither, with an error or, when
|
|
35
|
+
// the user cancelled, none.
|
|
36
|
+
using CameraSheetDone = std::function<void(ngn::CameraTake take, NSDictionary *exif, const std::string &error)>;
|
|
37
|
+
|
|
38
|
+
@interface NGNCameraSheet : NSViewController
|
|
39
|
+
- (instancetype)initWithCapture:(std::shared_ptr<ngn::appkit::SessionCapture>)capture
|
|
40
|
+
request:(ngn::CameraSheetRequest)request
|
|
41
|
+
done:(CameraSheetDone)done;
|
|
42
|
+
@property(nonatomic, readonly) NSButton *shutter;
|
|
43
|
+
@property(nonatomic, readonly) NSButton *cancelButton;
|
|
44
|
+
@property(nonatomic, readonly) AVCaptureVideoPreviewLayer *preview;
|
|
45
|
+
// Photo (0) and Video (1), for a request that takes either; nil otherwise.
|
|
46
|
+
@property(nonatomic, readonly) NSSegmentedControl *modeSwitch;
|
|
47
|
+
// The time recorded, shown in video mode.
|
|
48
|
+
@property(nonatomic, readonly) NSTextField *elapsed;
|
|
49
|
+
@property(nonatomic, readonly) BOOL videoMode;
|
|
50
|
+
// The camera is running: the shutter can take a photo or start a recording.
|
|
51
|
+
- (void)cameraRunning;
|
|
52
|
+
- (void)takePhoto:(id)sender;
|
|
53
|
+
// Starts a recording, or stops the one running.
|
|
54
|
+
- (void)record:(id)sender;
|
|
55
|
+
// Switches to the mode modeSwitch shows.
|
|
56
|
+
- (void)switchMode:(id)sender;
|
|
57
|
+
- (void)cancel:(id)sender;
|
|
58
|
+
@end
|
|
59
|
+
#endif
|