@ng-native/desktop 0.25.0 → 0.26.1
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/native/CMakeLists.txt +47 -4
- package/native/appkit/CMakeLists.txt +2 -1
- package/native/appkit/cg-canvas.h +5 -0
- package/native/appkit/cg-canvas.mm +21 -6
- package/native/appkit/desktop-expo.h +6 -0
- package/native/appkit/desktop-expo.mm +5 -0
- package/native/appkit/host-view.mm +32 -0
- package/native/appkit/image-request.h +2 -10
- package/native/appkit/image-request.mm +0 -22
- package/native/appkit/image-view.mm +94 -6
- package/native/appkit/main.mm +130 -185
- package/native/appkit/split-view.mm +3 -9
- package/native/appkit/system-access.mm +3 -0
- package/native/appkit/system.mm +33 -48
- package/native/appkit/view-effects.h +27 -0
- package/native/appkit/view-effects.mm +90 -0
- package/native/cmake/runtime-dependencies.cmake +11 -1
- package/native/core/include/ngn/app-info.h +3 -2
- package/native/core/include/ngn/app-menus.h +5 -11
- package/native/core/include/ngn/default-menu.h +16 -6
- package/native/core/include/ngn/desktop-expo.h +0 -5
- package/native/core/include/ngn/desktop-modules.h +144 -0
- package/native/core/include/ngn/dev-server.h +12 -3
- package/native/core/include/ngn/host-os.h +45 -0
- package/native/core/include/ngn/host-views.h +25 -0
- package/native/core/include/ngn/image-source.h +18 -0
- package/native/core/include/ngn/launch-settings.h +9 -7
- package/native/core/include/ngn/module-registry.h +2 -0
- package/native/core/include/ngn/notifications.h +6 -0
- package/native/core/include/ngn/runtime.h +4 -1
- package/native/core/include/ngn/spawn-rules.h +3 -2
- package/native/core/include/ngn/split-view.h +12 -0
- package/native/core/include/ngn/system.h +47 -0
- package/native/core/include/ngn/undo.h +27 -0
- package/native/core/include/ngn/updates.h +3 -2
- package/native/core/include/ngn/view-filter.h +33 -0
- package/native/core/src/app-menus.cpp +9 -11
- package/native/core/src/default-menu.cpp +6 -2
- package/native/core/src/dev-server-helper.cpp +3 -2
- package/native/core/src/dev-server.cpp +22 -5
- package/native/core/src/host-os.cpp +20 -0
- package/native/core/src/host-views.cpp +25 -0
- package/native/core/src/image-source.cpp +30 -0
- package/native/core/src/launch-settings.cpp +10 -6
- package/native/core/src/module-registry.cpp +9 -0
- package/native/core/src/modules/app-info.cpp +4 -4
- package/native/core/src/modules/desktop-expo.cpp +0 -5
- package/native/core/src/modules/desktop-modules.cpp +132 -0
- package/native/core/src/modules/notifications.cpp +4 -4
- package/native/core/src/runtime.cpp +2 -0
- package/native/core/src/spawn-rules.cpp +1 -4
- package/native/core/src/split-view.cpp +10 -0
- package/native/core/src/system.cpp +52 -0
- package/native/core/src/undo-stacks.cpp +71 -0
- package/native/core/src/view-filter.cpp +114 -0
- package/native/scripts/build-hermes.sh +19 -7
- package/native/scripts/build-icu.sh +36 -0
- package/native/scripts/build-lock.sh +21 -0
- package/native/scripts/build.sh +40 -7
- package/native/scripts/fetch.sh +24 -2
- package/native/scripts/hermes-built.sh +5 -4
- package/native/scripts/hermes-target.sh +18 -0
- package/native/scripts/icu-filter.json +22 -0
- package/native/shim/openssl/sha.h +108 -3
- package/package.json +2 -2
- package/prebuilt.json +6 -6
package/native/appkit/main.mm
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
#import "animation-frames.h"
|
|
15
15
|
#import "input-replay.h"
|
|
16
|
-
#include "ngn/
|
|
16
|
+
#include "ngn/host-views.h"
|
|
17
17
|
#include "ngn/worklet-host.h"
|
|
18
18
|
#import "notifications.h"
|
|
19
19
|
#import "undo.h"
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
#include "ngn/app-menus.h"
|
|
76
76
|
#include "ngn/back-swipe.h"
|
|
77
77
|
#include "ngn/core-modules.h"
|
|
78
|
+
#include "ngn/desktop-modules.h"
|
|
78
79
|
#include "ngn/default-menu.h"
|
|
79
80
|
#include "ngn/desktop-modal.h"
|
|
80
81
|
#include "ngn/input-dispatcher.h"
|
|
@@ -823,6 +824,8 @@ void showAppWindow() {
|
|
|
823
824
|
|
|
824
825
|
int main(int argc, const char *argv[]) {
|
|
825
826
|
@autoreleasepool {
|
|
827
|
+
// The values the core takes from the OS it runs on (host-os.h).
|
|
828
|
+
const ngn::HostOs os = ngn::macOS();
|
|
826
829
|
// What to run: argv and the environment in a dev run, and only the Info.plist in a packaged
|
|
827
830
|
// app (launch-settings.h).
|
|
828
831
|
NSDictionary *info = NSBundle.mainBundle.infoDictionary;
|
|
@@ -838,7 +841,7 @@ int main(int argc, const char *argv[]) {
|
|
|
838
841
|
return [value isKindOfClass:NSString.class] ? std::optional<std::string>(value.UTF8String) : std::nullopt;
|
|
839
842
|
},
|
|
840
843
|
.resourcePath = NSBundle.mainBundle.resourcePath != nil ? NSBundle.mainBundle.resourcePath.UTF8String : "",
|
|
841
|
-
});
|
|
844
|
+
}, os);
|
|
842
845
|
if (auto *usage = std::get_if<std::string>(&launch)) {
|
|
843
846
|
fprintf(stderr, "%s\n", usage->c_str());
|
|
844
847
|
return 2;
|
|
@@ -860,13 +863,10 @@ int main(int argc, const char *argv[]) {
|
|
|
860
863
|
app.delegate = delegate;
|
|
861
864
|
|
|
862
865
|
gHost.backend = std::make_shared<ngn::appkit::AppKitBackend>();
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
ngn::
|
|
866
|
-
|
|
867
|
-
// their timers on the main queue.
|
|
868
|
-
static auto gestures = std::make_shared<ngn::Gestures>(
|
|
869
|
-
gHost.mounting->tree(), [](double ms, std::function<void()> fn) -> std::function<void()> {
|
|
866
|
+
// The mounting manager, the input dispatcher and the gesture recognisers over the backend
|
|
867
|
+
// (host-views.h), the recognisers' timers on the main queue.
|
|
868
|
+
auto views = ngn::makeHostViews(
|
|
869
|
+
gHost.backend, gHost.backend, [](double ms, std::function<void()> fn) -> std::function<void()> {
|
|
870
870
|
auto cancelled = std::make_shared<std::atomic<bool>>(false);
|
|
871
871
|
auto shared = std::make_shared<std::function<void()>>(std::move(fn));
|
|
872
872
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, static_cast<int64_t>(ms * NSEC_PER_MSEC)), dispatch_get_main_queue(), ^{
|
|
@@ -876,13 +876,9 @@ int main(int argc, const char *argv[]) {
|
|
|
876
876
|
});
|
|
877
877
|
return [cancelled] { *cancelled = true; };
|
|
878
878
|
});
|
|
879
|
-
gHost.
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
gestures->onWorkletEvent = [](const std::string &name, Tag view, const folly::dynamic &body) {
|
|
883
|
-
ngn::workletHost().reanimatedEvent.call(name, view, body);
|
|
884
|
-
};
|
|
885
|
-
ngn::workletHost().setGestureState = [](int handlerTag, int state) { gestures->setState(handlerTag, state); };
|
|
879
|
+
gHost.mounting = views.mounting;
|
|
880
|
+
gHost.input = std::move(views.input);
|
|
881
|
+
ngn::appkit::installWorkletHost(gHost.mounting);
|
|
886
882
|
// Each commit's time, for the performance budget (pnpm bench:macos), when asked for: every
|
|
887
883
|
// frame of an animation commits, which would flood a dev run's terminal.
|
|
888
884
|
if (settings.logCommits) {
|
|
@@ -1058,7 +1054,7 @@ int main(int argc, const char *argv[]) {
|
|
|
1058
1054
|
});
|
|
1059
1055
|
},
|
|
1060
1056
|
.fakeSystemUI = settings.test && settings.test->fakeSystemUI,
|
|
1061
|
-
.gestures = gestures,
|
|
1057
|
+
.gestures = views.gestures,
|
|
1062
1058
|
.runOnUiThread = [](std::function<void()> task) {
|
|
1063
1059
|
auto shared = std::make_shared<std::function<void()>>(std::move(task));
|
|
1064
1060
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -1096,13 +1092,13 @@ int main(int argc, const char *argv[]) {
|
|
|
1096
1092
|
});
|
|
1097
1093
|
gHost.windowHost = std::make_shared<ngn::WindowHost>(gHost.windows, system);
|
|
1098
1094
|
gHost.windows->setHost(gHost.windowHost);
|
|
1099
|
-
ngn::addModule(*modules, "NgNativeWindows", [] { return ngn::makeWindowsModule(gHost.windowHost); });
|
|
1100
1095
|
|
|
1101
1096
|
gHost.menus = std::make_shared<ngn::MenuHost>(
|
|
1102
1097
|
std::make_shared<AppKitMenus>(),
|
|
1103
1098
|
ngn::DefaultMenuOptions{
|
|
1104
|
-
.appName = std::string(title.UTF8String),
|
|
1105
|
-
|
|
1099
|
+
.appName = std::string(title.UTF8String),
|
|
1100
|
+
.developer = ngn::DevServer::fromBundleUrl(bundle).has_value(),
|
|
1101
|
+
.os = os});
|
|
1106
1102
|
// Each window's history, as the app's router reports it, for its toolbar's chevrons.
|
|
1107
1103
|
gHost.menus->historyChanged = [](SurfaceId surface) {
|
|
1108
1104
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -1125,177 +1121,125 @@ int main(int argc, const char *argv[]) {
|
|
|
1125
1121
|
gHost.tray = std::make_shared<ngn::TrayHost>(std::make_shared<ngn::appkit::AppKitTray>(
|
|
1126
1122
|
[](const std::string &icon) { gHost.tray->press(icon); },
|
|
1127
1123
|
[](const std::string &icon, const std::string &id) { gHost.tray->menuSelect(icon, id); }));
|
|
1128
|
-
ngn::addModule(*modules, "NgNativeTray", [] { return ngn::makeTrayModule(gHost.tray); });
|
|
1129
1124
|
gHost.dock = std::make_shared<ngn::appkit::AppKitDock>([](const std::string &id) { gHost.dockHost->menuSelect(id); });
|
|
1130
1125
|
gHost.dockHost = std::make_shared<ngn::DockHost>(gHost.dock);
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
ngn::addModule(*modules, "NgNativeShell", [] { return ngn::makeShellModule(opener, fileAccess); });
|
|
1139
|
-
// The desktop Expo modules (DESKTOP_MODULES in @ng-native/expo).
|
|
1140
|
-
static std::shared_ptr<ngn::SecretStore> keychain = ngn::appkit::makeKeychain();
|
|
1141
|
-
static auto keychainService = appId;
|
|
1142
|
-
if (settings.test) {
|
|
1143
|
-
// The run's own items, removed as it ends, and any a crashed run left.
|
|
1144
|
-
ngn::appkit::removeStaleTestItems(*settings.test);
|
|
1145
|
-
auto prefixed = std::make_shared<ngn::PrefixedSecretStore>(keychain, settings.test->keychainPrefix());
|
|
1146
|
-
ngn::appkit::onTestLaunchEnd([prefixed] { prefixed->clear(); });
|
|
1147
|
-
keychain = prefixed;
|
|
1148
|
-
}
|
|
1149
|
-
static auto expoSystem = system;
|
|
1150
|
-
static auto awake = std::make_shared<ngn::KeepAwakeTags>(ngn::appkit::makeSleepPreventer());
|
|
1151
|
-
static auto haptics = ngn::appkit::makeHapticPlayer();
|
|
1152
|
-
ngn::addModule(*modules, "NgNativeSecureStore", [] { return ngn::makeSecureStoreModule(keychain, keychainService); });
|
|
1153
|
-
ngn::addModule(*modules, "NgNativeClipboard", [] { return ngn::makeDesktopClipboardModule(expoSystem, gHost.state); });
|
|
1154
|
-
static auto notificationEvents = std::make_shared<ngn::NotificationEvents>();
|
|
1155
|
-
static auto notifications = ngn::appkit::makeNotificationCenter(notificationEvents);
|
|
1156
|
-
static auto pushTokens = std::make_shared<ngn::PushTokens>(ngn::appkit::makePushRegistrar(), notificationEvents);
|
|
1157
|
-
gHost.push = pushTokens;
|
|
1158
|
-
gHost.notificationEvents = notificationEvents;
|
|
1159
|
-
ngn::addModule(*modules, "NgNativeNotifications", [] {
|
|
1160
|
-
return ngn::makeNotificationsModule(notifications, notificationEvents, pushTokens);
|
|
1161
|
-
});
|
|
1162
|
-
static auto undo = ngn::appkit::makeUndoManager();
|
|
1163
|
-
ngn::addModule(*modules, "NgNativeUndo", [] { return ngn::makeUndoModule(undo); });
|
|
1164
|
-
ngn::addModule(*modules, "NgNativeKeepAwake", [] { return ngn::makeKeepAwakeModule(awake); });
|
|
1165
|
-
ngn::addModule(*modules, "NgNativeHaptics", [] { return ngn::makeHapticsModule(haptics); });
|
|
1166
|
-
static auto dialogs = settings.test && settings.test->fakeSystemUI ? ngn::makeDismissedFileDialogs()
|
|
1167
|
-
: ngn::appkit::makeFileDialogs();
|
|
1168
|
-
static auto fileWatcher = ngn::appkit::makeFileWatcher();
|
|
1169
|
-
ngn::addModule(*modules, "NgNativeFileSystem", [] { return ngn::makeFileSystemModule(fileAccess, fileWatcher); });
|
|
1170
|
-
ngn::addModule(*modules, "NgNativeDocumentPicker", [] { return ngn::makeDocumentPickerModule(dialogs, caches, fileAccess); });
|
|
1171
|
-
// expo-sqlite keeps its databases in the app's documents, under SQLite; here, in its data.
|
|
1172
|
-
static auto databases = system->appDataDirectory() + "/SQLite";
|
|
1173
|
-
ngn::addModule(*modules, "NgNativeSqlite", [] { return ngn::makeSqliteModule(databases, fileAccess); });
|
|
1174
|
-
static auto location = ngn::appkit::makeLocationSource();
|
|
1175
|
-
static bool noPrompts = settings.noPrompts;
|
|
1176
|
-
static auto geocoder = ngn::appkit::makeGeocoder();
|
|
1177
|
-
ngn::addModule(*modules, "NgNativeLocation", [] { return ngn::makeLocationModule(location, noPrompts, geocoder); });
|
|
1178
|
-
static auto authenticator = ngn::appkit::makeAuthenticator(noPrompts);
|
|
1179
|
-
ngn::addModule(*modules, "NgNativeLocalAuthentication", [] { return ngn::makeLocalAuthenticationModule(authenticator); });
|
|
1180
|
-
static auto bundleFacts = ngn::appkit::mainBundleFacts();
|
|
1181
|
-
static auto appName = std::string(title.UTF8String);
|
|
1182
|
-
ngn::addModule(*modules, "NgNativeApplication", [] { return ngn::makeApplicationModule(bundleFacts, keychainService, appName); });
|
|
1183
|
-
static auto machine = ngn::appkit::machineFacts();
|
|
1184
|
-
ngn::addModule(*modules, "NgNativeDevice", [] { return ngn::makeDeviceModule(machine); });
|
|
1185
|
-
static auto pathMonitor = ngn::appkit::makePathMonitor();
|
|
1186
|
-
ngn::addModule(*modules, "NgNativeNetwork", [] { return ngn::makeNetworkModule(pathMonitor); });
|
|
1187
|
-
static auto power = ngn::appkit::makePowerSource();
|
|
1188
|
-
ngn::addModule(*modules, "NgNativeBattery", [] { return ngn::makeBatteryModule(power); });
|
|
1189
|
-
// The fonts loaded stay registered for the process, so their names outlast a reload too.
|
|
1190
|
-
static auto fontLibrary = std::make_shared<ngn::FontLibrary>();
|
|
1191
|
-
static auto fontRegistrar = ngn::appkit::makeFontRegistrar();
|
|
1192
|
-
static auto fontHttp = network.http;
|
|
1193
|
-
ngn::useFontLibrary(fontLibrary);
|
|
1194
|
-
ngn::addModule(*modules, "NgNativeFont", [] {
|
|
1195
|
-
return ngn::makeFontModule(fontRegistrar, fontLibrary, fontHttp, caches + "/fonts", fileAccess);
|
|
1196
|
-
});
|
|
1197
|
-
static auto authSession = ngn::appkit::makeAuthSession();
|
|
1198
|
-
ngn::addModule(*modules, "NgNativeWebBrowser", [] { return ngn::makeWebBrowserModule(expoSystem, authSession, noPrompts); });
|
|
1199
|
-
static auto textReader = ngn::appkit::makeTextReader();
|
|
1200
|
-
ngn::addModule(*modules, "NgNativeTextRecognition", [] { return ngn::makeTextRecognitionModule(textReader, fileAccess); });
|
|
1201
|
-
static auto calendars = ngn::appkit::makeCalendarStore();
|
|
1202
|
-
ngn::addModule(*modules, "NgNativeCalendar", [] { return ngn::makeCalendarModule(calendars, noPrompts); });
|
|
1203
|
-
// Players and recorders end with the runtime: a reload stops what the app played.
|
|
1204
|
-
static auto audioOutput = ngn::appkit::makeAudioOutput();
|
|
1205
|
-
static auto audioInput = ngn::appkit::makeAudioInput();
|
|
1206
|
-
ngn::addModule(*modules, "NgNativeAudio", [] { return ngn::makeAudioModule(audioOutput, audioInput, caches + "/Audio", noPrompts, fileAccess); });
|
|
1207
|
-
static auto videoOutput = ngn::appkit::makeVideoOutput();
|
|
1208
|
-
ngn::addModule(*modules, "NgNativeVideo", [] { return ngn::makeVideoModule(videoOutput, fileAccess); });
|
|
1209
|
-
static auto languageModel = ngn::appkit::makeLanguageModelEngine();
|
|
1210
|
-
ngn::addModule(*modules, "NgNativeLocalLlm", [] { return ngn::makeLocalLlmModule(languageModel); });
|
|
1211
|
-
ngn::addModule(*modules, "NgNativeScreenCapture", [] { return ngn::makeScreenCaptureModule(ngn::appkit::captureShield()); });
|
|
1212
|
-
ngn::addModule(*modules, "NgNativeSplashScreen", [] { return ngn::makeSplashScreenModule(gSplash); });
|
|
1213
|
-
static auto photos = ngn::appkit::makePhotoLibrary(caches);
|
|
1214
|
-
ngn::addModule(*modules, "NgNativeMediaLibrary", [] { return ngn::makeMediaLibraryModule(photos, noPrompts, fileAccess); });
|
|
1215
|
-
static auto cameraHardware = ngn::appkit::makeCameraHardware();
|
|
1216
|
-
static auto cameraSheet = ngn::appkit::makeCameraSheet();
|
|
1217
|
-
ngn::addModule(*modules, "NgNativeImagePicker", [] {
|
|
1218
|
-
return ngn::makeImagePickerModule(photos, noPrompts, ngn::PickerCamera{.hardware = cameraHardware, .microphone = audioInput, .sheet = cameraSheet, .folder = caches + "/ImagePicker"});
|
|
1219
|
-
});
|
|
1220
|
-
static auto tracking = ngn::appkit::makeTrackingAuthority();
|
|
1221
|
-
ngn::addModule(*modules, "NgNativeTrackingTransparency", [] { return ngn::makeTrackingModule(tracking, noPrompts); });
|
|
1222
|
-
static auto imageHttp = network.http;
|
|
1223
|
-
static auto addressLookup = ngn::appkit::makeAddressLookup();
|
|
1224
|
-
ngn::addModule(*modules, "NgNativeAddressSearch", [] { return ngn::makeAddressSearchModule(addressLookup); });
|
|
1225
|
-
ngn::addModule(*modules, "NgNativeAsset", [] { return ngn::makeAssetModule(imageHttp, caches, fileAccess); });
|
|
1226
|
-
static auto symbolMeasurer = ngn::appkit::makeSymbolMeasurer();
|
|
1227
|
-
ngn::addModule(*modules, "NgNativeSymbol", [] { return ngn::makeSymbolModule(symbolMeasurer); });
|
|
1228
|
-
static auto sharePicker = ngn::appkit::makeSharePicker();
|
|
1229
|
-
ngn::addModule(*modules, "NgNativeSharing", [] { return ngn::makeSharingModule(sharePicker, noPrompts, fileAccess); });
|
|
1230
|
-
static auto imageCodec = ngn::appkit::makeImageCodec();
|
|
1231
|
-
ngn::addModule(*modules, "NgNativeImageManipulator", [] {
|
|
1232
|
-
return ngn::makeImageManipulatorModule(imageCodec, imageHttp, caches + "/ImageManipulator", fileAccess);
|
|
1233
|
-
});
|
|
1234
|
-
// <expo-image>'s bytes: 64 MB of them in memory, the rest on disk in the caches.
|
|
1235
|
-
[NGNExpoImageView useHttp:imageHttp cache:std::make_shared<ngn::ImageCache>(caches + "/ExpoImage", 64 << 20)];
|
|
1236
|
-
static auto cameraViews = std::make_shared<ngn::CameraViews>();
|
|
1237
|
-
[NGNCameraView useHardware:cameraHardware views:cameraViews noPrompts:noPrompts];
|
|
1238
|
-
ngn::addModule(*modules, "NgNativeCamera", [] { return ngn::makeCameraModule(cameraHardware, cameraViews, caches + "/Camera", noPrompts); });
|
|
1239
|
-
static auto mapViews = std::make_shared<ngn::MapViews>();
|
|
1240
|
-
[NGNMapView useViews:mapViews location:location];
|
|
1241
|
-
ngn::addModule(*modules, "NgNativeMaps", [] { return ngn::makeMapsModule(mapViews); });
|
|
1242
|
-
// Sign in with Apple: available only to an app signed with its entitlement.
|
|
1243
|
-
static auto appleId = ngn::appkit::makeAppleIdProvider();
|
|
1244
|
-
ngn::addModule(*modules, "NgNativeAppleAuthentication", [] { return ngn::makeAppleAuthenticationModule(appleId, noPrompts); });
|
|
1245
|
-
static auto printSystem = ngn::appkit::makePrintSystem([](SurfaceId surface) -> NSWindow * {
|
|
1246
|
-
return surface == kAppSurface ? gHost.appWindow : gHost.windows->window(surface);
|
|
1247
|
-
});
|
|
1248
|
-
ngn::addModule(*modules, "NgNativePrint", [] { return ngn::makePrintModule(printSystem, imageHttp, caches + "/Print", fileAccess, noPrompts); });
|
|
1249
|
-
// react-native-webview's navigation answers; harmless in a host built without the library.
|
|
1250
|
-
ngn::addModule(*modules, "RNCWebViewModule", [] { return ngn::makeWebViewModule(ngn::sharedNavigationLocks()); });
|
|
1251
|
-
// A rating prompt only in a Mac App Store build: one sandboxed but shipped another way has none.
|
|
1252
|
-
static auto packaged = ngn::appkit::packagedApp();
|
|
1253
|
-
static auto reviewPrompt = ngn::appkit::makeReviewPrompt(packaged && packaged->distribution == "mas");
|
|
1254
|
-
ngn::addModule(*modules, "NgNativeStoreReview", [] { return ngn::makeStoreReviewModule(reviewPrompt, noPrompts); });
|
|
1255
|
-
static auto crypto = ngn::appkit::makeCryptoSource();
|
|
1256
|
-
ngn::addModule(*modules, "NgNativeCrypto", [] { return ngn::makeCryptoModule(crypto); });
|
|
1257
|
-
static auto locales = ngn::appkit::makeLocaleSource();
|
|
1258
|
-
ngn::addModule(*modules, "NgNativeLocalization", [] {
|
|
1259
|
-
return ngn::makeLocalizationModule(locales, ngn::appkit::systemRegionCode());
|
|
1260
|
-
});
|
|
1126
|
+
// The secrets' store: a test launch's own items, removed as it ends, and any a crashed run left.
|
|
1127
|
+
std::shared_ptr<ngn::SecretStore> keychain = ngn::appkit::makeKeychain();
|
|
1128
|
+
if (settings.test) {
|
|
1129
|
+
ngn::appkit::removeStaleTestItems(*settings.test);
|
|
1130
|
+
auto prefixed = std::make_shared<ngn::PrefixedSecretStore>(keychain, settings.test->keychainPrefix());
|
|
1131
|
+
ngn::appkit::onTestLaunchEnd([prefixed] { prefixed->clear(); });
|
|
1132
|
+
keychain = prefixed;
|
|
1261
1133
|
}
|
|
1262
|
-
|
|
1263
1134
|
// A bundle on disk runs the newest update the Expo Updates client keeps, when the app has an
|
|
1264
1135
|
// updates URL; one from a dev server never does.
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
fprintf(stderr, "[ngn] running update %s\n", running->id.c_str());
|
|
1273
|
-
}
|
|
1136
|
+
bool fromDevServer = ngn::DevServer::fromBundleUrl(bundle).has_value();
|
|
1137
|
+
gHost.updates = std::make_shared<ngn::UpdatesClient>(
|
|
1138
|
+
ngn::updatesConfigFrom(settings, os, system->appDataDirectory(), bundle), network.http, ngn::appkit::makeUpdateCrypto());
|
|
1139
|
+
if (!fromDevServer && gHost.updates->enabled()) {
|
|
1140
|
+
bundle = gHost.updates->launch();
|
|
1141
|
+
if (auto running = gHost.updates->running()) {
|
|
1142
|
+
fprintf(stderr, "[ngn] running update %s\n", running->id.c_str());
|
|
1274
1143
|
}
|
|
1275
|
-
// Sparkle starts with the app, as its own updater does: one for the process.
|
|
1276
|
-
static auto appUpdater = ngn::appkit::makeSparkleUpdater();
|
|
1277
|
-
ngn::addModule(*modules, "NgNativeUpdates", [fromDevServer] {
|
|
1278
|
-
return ngn::makeUpdatesModule(gHost.updates, fromDevServer, [](const std::string &next, std::function<void(bool)> done) {
|
|
1279
|
-
setRunningBundle(next);
|
|
1280
|
-
// The launch the module's beginReload just began.
|
|
1281
|
-
uint64_t generation = gHost.updates->launchGeneration();
|
|
1282
|
-
gHost.runtime->reload(next, [next, done, generation](bool loaded) {
|
|
1283
|
-
if (!loaded) {
|
|
1284
|
-
fprintf(stderr, "ngn-macos: the update's bundle %s did not load\n", next.c_str());
|
|
1285
|
-
}
|
|
1286
|
-
// A bundle that did not load never counts as a launch that succeeded; one that did counts
|
|
1287
|
-
// from the first frame its own instance mounts on screen.
|
|
1288
|
-
if (loaded) {
|
|
1289
|
-
uint64_t instance = gHost.mounting->instance();
|
|
1290
|
-
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1291
|
-
reloadLaunched(generation, instance);
|
|
1292
|
-
});
|
|
1293
|
-
}
|
|
1294
|
-
done(loaded);
|
|
1295
|
-
});
|
|
1296
|
-
}, appUpdater);
|
|
1297
|
-
});
|
|
1298
1144
|
}
|
|
1145
|
+
// The map and camera views reach the same location service and camera as their modules.
|
|
1146
|
+
auto location = ngn::appkit::makeLocationSource();
|
|
1147
|
+
auto cameraHardware = ngn::appkit::makeCameraHardware();
|
|
1148
|
+
// A rating prompt only in a Mac App Store build: one sandboxed but shipped another way has none.
|
|
1149
|
+
auto packaged = ngn::appkit::packagedApp();
|
|
1150
|
+
// The desktop host's own modules over AppKit's sources (desktop-modules.h).
|
|
1151
|
+
auto desktop = ngn::addDesktopModules(
|
|
1152
|
+
*modules,
|
|
1153
|
+
{.os = os,
|
|
1154
|
+
.system = system,
|
|
1155
|
+
.state = gHost.state,
|
|
1156
|
+
.http = network.http,
|
|
1157
|
+
.files = fileAccess,
|
|
1158
|
+
.appId = appId,
|
|
1159
|
+
.appName = std::string(title.UTF8String),
|
|
1160
|
+
.caches = caches,
|
|
1161
|
+
.noPrompts = settings.noPrompts,
|
|
1162
|
+
.windows = gHost.windowHost,
|
|
1163
|
+
.menus = gHost.menus,
|
|
1164
|
+
.tray = gHost.tray,
|
|
1165
|
+
.dock = gHost.dockHost,
|
|
1166
|
+
.processes = processes,
|
|
1167
|
+
.shell = ngn::appkit::makeShellOpener(),
|
|
1168
|
+
.secrets = keychain,
|
|
1169
|
+
.sleep = ngn::appkit::makeSleepPreventer(),
|
|
1170
|
+
.haptics = ngn::appkit::makeHapticPlayer(),
|
|
1171
|
+
.notifications = ngn::appkit::makeNotificationCenter,
|
|
1172
|
+
.push = ngn::appkit::makePushRegistrar(),
|
|
1173
|
+
.undo = ngn::appkit::makeUndoManager(),
|
|
1174
|
+
.fileDialogs = settings.test && settings.test->fakeSystemUI ? ngn::makeDismissedFileDialogs()
|
|
1175
|
+
: ngn::appkit::makeFileDialogs(),
|
|
1176
|
+
.fileWatcher = ngn::appkit::makeFileWatcher(),
|
|
1177
|
+
.location = location,
|
|
1178
|
+
.geocoder = ngn::appkit::makeGeocoder(),
|
|
1179
|
+
.authenticator = ngn::appkit::makeAuthenticator(settings.noPrompts),
|
|
1180
|
+
.bundle = ngn::appkit::mainBundleFacts(),
|
|
1181
|
+
.machine = ngn::appkit::machineFacts(),
|
|
1182
|
+
.pathMonitor = ngn::appkit::makePathMonitor(),
|
|
1183
|
+
.power = ngn::appkit::makePowerSource(),
|
|
1184
|
+
.fontRegistrar = ngn::appkit::makeFontRegistrar(),
|
|
1185
|
+
.authSession = ngn::appkit::makeAuthSession(),
|
|
1186
|
+
.textReader = ngn::appkit::makeTextReader(),
|
|
1187
|
+
.calendars = ngn::appkit::makeCalendarStore(),
|
|
1188
|
+
.audioOutput = ngn::appkit::makeAudioOutput(),
|
|
1189
|
+
.audioInput = ngn::appkit::makeAudioInput(),
|
|
1190
|
+
.videoOutput = ngn::appkit::makeVideoOutput(),
|
|
1191
|
+
.languageModel = ngn::appkit::makeLanguageModelEngine(),
|
|
1192
|
+
.captureShield = ngn::appkit::captureShield(),
|
|
1193
|
+
.splash = gSplash,
|
|
1194
|
+
.photos = ngn::appkit::makePhotoLibrary(caches),
|
|
1195
|
+
.cameraHardware = cameraHardware,
|
|
1196
|
+
.cameraSheet = ngn::appkit::makeCameraSheet(),
|
|
1197
|
+
.tracking = ngn::appkit::makeTrackingAuthority(),
|
|
1198
|
+
.addressLookup = ngn::appkit::makeAddressLookup(),
|
|
1199
|
+
.symbolMeasurer = ngn::appkit::makeSymbolMeasurer(),
|
|
1200
|
+
.sharePicker = ngn::appkit::makeSharePicker(),
|
|
1201
|
+
.imageCodec = ngn::appkit::makeImageCodec(),
|
|
1202
|
+
// Sign in with Apple: available only to an app signed with its entitlement.
|
|
1203
|
+
.appleId = ngn::appkit::makeAppleIdProvider(),
|
|
1204
|
+
.printSystem = ngn::appkit::makePrintSystem([](SurfaceId surface) -> NSWindow * {
|
|
1205
|
+
return surface == kAppSurface ? gHost.appWindow : gHost.windows->window(surface);
|
|
1206
|
+
}),
|
|
1207
|
+
.reviewPrompt = ngn::appkit::makeReviewPrompt(packaged && packaged->distribution == "mas"),
|
|
1208
|
+
.crypto = ngn::appkit::makeCryptoSource(),
|
|
1209
|
+
.locales = ngn::appkit::makeLocaleSource(),
|
|
1210
|
+
.regionCode = ngn::appkit::systemRegionCode,
|
|
1211
|
+
.updates = gHost.updates,
|
|
1212
|
+
.fromDevServer = fromDevServer,
|
|
1213
|
+
.reload =
|
|
1214
|
+
[](const std::string &next, std::function<void(bool)> done) {
|
|
1215
|
+
setRunningBundle(next);
|
|
1216
|
+
// The launch the module's beginReload just began.
|
|
1217
|
+
uint64_t generation = gHost.updates->launchGeneration();
|
|
1218
|
+
gHost.runtime->reload(next, [next, done, generation](bool loaded) {
|
|
1219
|
+
if (!loaded) {
|
|
1220
|
+
fprintf(stderr, "ngn-macos: the update's bundle %s did not load\n", next.c_str());
|
|
1221
|
+
}
|
|
1222
|
+
// A bundle that did not load never counts as a launch that succeeded; one that did
|
|
1223
|
+
// counts from the first frame its own instance mounts on screen.
|
|
1224
|
+
if (loaded) {
|
|
1225
|
+
uint64_t instance = gHost.mounting->instance();
|
|
1226
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1227
|
+
reloadLaunched(generation, instance);
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
done(loaded);
|
|
1231
|
+
});
|
|
1232
|
+
},
|
|
1233
|
+
// Sparkle starts with the app, as its own updater does: one for the process.
|
|
1234
|
+
.appUpdater = ngn::appkit::makeSparkleUpdater()});
|
|
1235
|
+
gHost.launcher = desktop.launcher;
|
|
1236
|
+
gHost.push = desktop.push;
|
|
1237
|
+
gHost.notificationEvents = desktop.notificationEvents;
|
|
1238
|
+
ngn::useFontLibrary(desktop.fonts);
|
|
1239
|
+
// <expo-image>'s bytes: 64 MB of them in memory, the rest on disk in the caches.
|
|
1240
|
+
[NGNExpoImageView useHttp:network.http cache:std::make_shared<ngn::ImageCache>(caches + "/ExpoImage", 64 << 20)];
|
|
1241
|
+
[NGNCameraView useHardware:cameraHardware views:desktop.cameraViews noPrompts:settings.noPrompts];
|
|
1242
|
+
[NGNMapView useViews:desktop.mapViews location:location];
|
|
1299
1243
|
|
|
1300
1244
|
setRunningBundle(bundle);
|
|
1301
1245
|
gHost.runtime = std::make_unique<ngn::Runtime>(
|
|
@@ -1305,7 +1249,8 @@ int main(int argc, const char *argv[]) {
|
|
|
1305
1249
|
modules, network, bundle,
|
|
1306
1250
|
ngn::DebuggerIdentity{
|
|
1307
1251
|
.appId = appId,
|
|
1308
|
-
.deviceName = NSHost.currentHost.localizedName ? NSHost.currentHost.localizedName.UTF8String : "Mac"
|
|
1252
|
+
.deviceName = NSHost.currentHost.localizedName ? NSHost.currentHost.localizedName.UTF8String : "Mac",
|
|
1253
|
+
.os = os.id});
|
|
1309
1254
|
// Each surface lays out the way I18nManager.isRTL says for the instance running, read again
|
|
1310
1255
|
// as a reload starts the next.
|
|
1311
1256
|
gHost.runtime->rightToLeft = [system] { return ngn::appRightToLeft(*system); };
|
|
@@ -36,10 +36,6 @@ void send(NGNView *view, const std::string &name, folly::dynamic payload) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
// The narrowest and widest a sidebar is dragged to when the app sets no bound.
|
|
40
|
-
constexpr CGFloat kSidebarMinimum = 150;
|
|
41
|
-
constexpr CGFloat kSidebarMaximum = 400;
|
|
42
|
-
|
|
43
39
|
} // namespace
|
|
44
40
|
|
|
45
41
|
#pragma mark - Sizes back into layout
|
|
@@ -320,17 +316,15 @@ NSWindow *NGNWindowOfSplit(NSView *surfaceView) {
|
|
|
320
316
|
}
|
|
321
317
|
|
|
322
318
|
- (CGFloat)minimumWidth {
|
|
323
|
-
|
|
324
|
-
return p && p->paneMinWidth > 0 ? p->paneMinWidth : kSidebarMinimum;
|
|
319
|
+
return ngn::sidebarWidths([_sidebar paneProps]).minimum;
|
|
325
320
|
}
|
|
326
321
|
|
|
327
322
|
- (CGFloat)maximumWidth {
|
|
328
|
-
|
|
329
|
-
return std::max([self minimumWidth], p && p->paneMaxWidth > 0 ? (CGFloat)p->paneMaxWidth : kSidebarMaximum);
|
|
323
|
+
return ngn::sidebarWidths([_sidebar paneProps]).maximum;
|
|
330
324
|
}
|
|
331
325
|
|
|
332
326
|
- (CGFloat)startingWidth {
|
|
333
|
-
return
|
|
327
|
+
return ngn::sidebarWidths([_sidebar paneProps]).starting;
|
|
334
328
|
}
|
|
335
329
|
|
|
336
330
|
// Whether the split view's autosave already holds its divider, which it then restores.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
#import "system-access.h"
|
|
2
2
|
|
|
3
|
+
#include "ngn/host-os.h"
|
|
4
|
+
|
|
3
5
|
#import <AppKit/AppKit.h>
|
|
4
6
|
#import <Security/Security.h>
|
|
5
7
|
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
|
|
@@ -109,6 +111,7 @@ ProcessesSetup processesSetup(const std::string &capabilitiesJson) {
|
|
|
109
111
|
setup.lookup = {
|
|
110
112
|
.isExecutable = [](const std::string &path) { return access(path.c_str(), X_OK) == 0; },
|
|
111
113
|
.isStub = isDeveloperStub,
|
|
114
|
+
.searchPath = macOS().searchPath,
|
|
112
115
|
};
|
|
113
116
|
NSDictionary *info = NSBundle.mainBundle.infoDictionary;
|
|
114
117
|
if (auto packaged = packagedApp()) {
|
package/native/appkit/system.mm
CHANGED
|
@@ -4,10 +4,7 @@
|
|
|
4
4
|
#import <AppKit/AppKit.h>
|
|
5
5
|
#import <ImageIO/ImageIO.h>
|
|
6
6
|
|
|
7
|
-
#include <
|
|
8
|
-
|
|
9
|
-
#include <atomic>
|
|
10
|
-
#include <mutex>
|
|
7
|
+
#include <memory>
|
|
11
8
|
|
|
12
9
|
namespace {
|
|
13
10
|
|
|
@@ -51,13 +48,28 @@ void postAnnouncement(const Announcement &announcement) {
|
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
// The app's defaults, which a test launch keeps in a suite of its own.
|
|
52
|
+
class DefaultsStore final : public StringStore {
|
|
55
53
|
public:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
std::optional<std::string> get(const std::string &key) override {
|
|
55
|
+
NSString *value = [appDefaults() stringForKey:ns(key)];
|
|
56
|
+
return value != nil ? std::optional(str(value)) : std::nullopt;
|
|
57
|
+
}
|
|
58
|
+
void set(const std::string &key, const std::string &value) override {
|
|
59
|
+
[appDefaults() setObject:ns(value) forKey:ns(key)];
|
|
60
60
|
}
|
|
61
|
+
void remove(const std::string &key) override {
|
|
62
|
+
[appDefaults() removeObjectForKey:ns(key)];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
class AppKitSystem final : public System {
|
|
67
|
+
public:
|
|
68
|
+
// The system's scheme is read once here on the main thread; JavaScript asks from its own.
|
|
69
|
+
explicit AppKitSystem(std::string appId)
|
|
70
|
+
: appId_(std::move(appId)),
|
|
71
|
+
scheme_(schemeOf(NSApp.effectiveAppearance)),
|
|
72
|
+
rightToLeft_(NSApp.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionRightToLeft) {}
|
|
61
73
|
|
|
62
74
|
DeviceFacts facts() override {
|
|
63
75
|
NSOperatingSystemVersion v = NSProcessInfo.processInfo.operatingSystemVersion;
|
|
@@ -99,15 +111,11 @@ class AppKitSystem final : public System {
|
|
|
99
111
|
}
|
|
100
112
|
|
|
101
113
|
std::string colorScheme() override {
|
|
102
|
-
|
|
103
|
-
return override_.value_or(systemScheme_);
|
|
114
|
+
return scheme_.current();
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
void setColorScheme(std::optional<std::string> scheme, std::function<void(std::string)> applied) override {
|
|
107
|
-
|
|
108
|
-
std::lock_guard lock(mutex_);
|
|
109
|
-
override_ = scheme;
|
|
110
|
-
}
|
|
118
|
+
scheme_.set(scheme);
|
|
111
119
|
auto told = std::make_shared<std::function<void(std::string)>>(std::move(applied));
|
|
112
120
|
onMain(^{
|
|
113
121
|
NSApp.appearance = !scheme ? nil
|
|
@@ -119,22 +127,16 @@ class AppKitSystem final : public System {
|
|
|
119
127
|
systemSchemeChanged(schemeOf(NSApp.effectiveAppearance));
|
|
120
128
|
}
|
|
121
129
|
// The scheme this change applied, not the latest override: a later change queued behind
|
|
122
|
-
// this one has set
|
|
130
|
+
// this one has set the override already, and tells its own scheme when it applies.
|
|
123
131
|
if (*told) {
|
|
124
|
-
|
|
125
|
-
{
|
|
126
|
-
std::lock_guard lock(mutex_);
|
|
127
|
-
applied = scheme.value_or(systemScheme_);
|
|
128
|
-
}
|
|
129
|
-
(*told)(applied);
|
|
132
|
+
(*told)(scheme_.applied(scheme));
|
|
130
133
|
}
|
|
131
134
|
});
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
// The system's own scheme, with no override. Main thread.
|
|
135
138
|
void systemSchemeChanged(std::string scheme) {
|
|
136
|
-
std::
|
|
137
|
-
systemScheme_ = std::move(scheme);
|
|
139
|
+
scheme_.systemChanged(std::move(scheme));
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
void showAlert(const AlertRequest &request, std::function<void(int, std::string, std::string)> done) override {
|
|
@@ -209,24 +211,11 @@ class AppKitSystem final : public System {
|
|
|
209
211
|
}
|
|
210
212
|
|
|
211
213
|
std::optional<folly::dynamic> preference(const std::string &key) override {
|
|
212
|
-
|
|
213
|
-
if (json == nil) {
|
|
214
|
-
return std::nullopt;
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
return folly::parseJson(str(json));
|
|
218
|
-
} catch (...) {
|
|
219
|
-
return std::nullopt;
|
|
220
|
-
}
|
|
214
|
+
return preferences_.get(key);
|
|
221
215
|
}
|
|
222
216
|
|
|
223
217
|
void setPreference(const std::string &key, std::optional<folly::dynamic> value) override {
|
|
224
|
-
|
|
225
|
-
if (value) {
|
|
226
|
-
[defaults setObject:ns(folly::toJson(*value)) forKey:ns(prefixed(key))];
|
|
227
|
-
} else {
|
|
228
|
-
[defaults removeObjectForKey:ns(prefixed(key))];
|
|
229
|
-
}
|
|
218
|
+
preferences_.set(key, value);
|
|
230
219
|
}
|
|
231
220
|
|
|
232
221
|
void announce(const Announcement &announcement) override {
|
|
@@ -264,16 +253,12 @@ class AppKitSystem final : public System {
|
|
|
264
253
|
}
|
|
265
254
|
|
|
266
255
|
private:
|
|
267
|
-
// A bare host binary has no bundle identifier, so every app run with it would share one
|
|
268
|
-
// defaults domain: the app's id keeps them apart.
|
|
269
|
-
std::string prefixed(const std::string &key) const {
|
|
270
|
-
return NSBundle.mainBundle.bundleIdentifier ? key : appId_ + "." + key;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
256
|
std::string appId_;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
257
|
+
ColorSchemeOverride scheme_;
|
|
258
|
+
// A bare host binary has no bundle identifier, so every app run with it shares one defaults
|
|
259
|
+
// domain: the app's id keeps them apart.
|
|
260
|
+
JsonPreferences preferences_{
|
|
261
|
+
std::make_shared<DefaultsStore>(), appId_, NSBundle.mainBundle.bundleIdentifier == nil};
|
|
277
262
|
bool rightToLeft_{false};
|
|
278
263
|
};
|
|
279
264
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// What a view's `filter` and `mix-blend-mode` become on its layer: Core Image filters and a
|
|
2
|
+
// compositing filter, which Core Animation applies to the layer and its sublayers.
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#import <CoreImage/CoreImage.h>
|
|
6
|
+
#import <Foundation/Foundation.h>
|
|
7
|
+
|
|
8
|
+
#include "ngn/view-filter.h"
|
|
9
|
+
|
|
10
|
+
#include <react/renderer/graphics/BlendMode.h>
|
|
11
|
+
|
|
12
|
+
#include <vector>
|
|
13
|
+
|
|
14
|
+
namespace ngn::appkit {
|
|
15
|
+
|
|
16
|
+
// The layer's `filters` for the steps, in their order. Core Animation runs a layer's filters in a
|
|
17
|
+
// linear working space, where a colour matrix of the Filter Effects spec (written for sRGB values)
|
|
18
|
+
// would mix the channels wrongly, so the steps sit between the conversions to sRGB and back, and a
|
|
19
|
+
// colour step is clamped as the spec does. A drop shadow draws nothing: a layer filter cannot add
|
|
20
|
+
// a copy of the view under it. Nil when no step draws anything.
|
|
21
|
+
NSArray<CIFilter *> *layerFilters(const std::vector<FilterStep> &steps);
|
|
22
|
+
|
|
23
|
+
// The layer's `compositingFilter` for `mix-blend-mode`, which blends the view with what is drawn
|
|
24
|
+
// under it as React Native iOS does (RCTViewComponentView); nil for `normal`.
|
|
25
|
+
NSString *blendFilterName(facebook::react::BlendMode mode);
|
|
26
|
+
|
|
27
|
+
} // namespace ngn::appkit
|