@blotch/angular-lynx-native 22.2.24 → 22.2.26
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/README.md +6 -4
- package/dist/android/project.d.ts +27 -3
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +83 -2
- package/dist/generate.d.ts +1 -1
- package/dist/generate.js +8 -2
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/ios/project.d.ts +20 -3
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +99 -2
- package/dist/options.d.ts +119 -0
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +143 -0
- package/dist/png.d.ts +5 -0
- package/dist/png.d.ts.map +1 -1
- package/dist/png.js +19 -5
- package/dist/splash.d.ts +70 -0
- package/dist/splash.d.ts.map +1 -0
- package/dist/splash.js +239 -0
- package/package.json +1 -1
- package/templates/android/README.md +19 -1
- package/templates/android/app/build.gradle.kts +4 -0
- package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServer.kt +6 -0
- package/templates/android/app/src/main/AndroidManifest.xml +27 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +2 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +16 -3
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +81 -4
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +10 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShortcutActivity.kt +33 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShortcutsModule.kt +72 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +15 -4
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +10 -1
- package/templates/android/app/src/main/res/values/colors.xml +3 -2
- package/templates/android/app/src/main/res/values/splash.xml +9 -0
- package/templates/android/app/src/main/res/values/themes.xml +14 -0
- package/templates/android/app/src/main/res/xml/shortcuts.xml +7 -0
- package/templates/android/app/src/release/java/dev/angularlynx/shell/DevServer.kt +2 -0
- package/templates/ios/App/AngularLynxWebGL.h +34 -6
- package/templates/ios/App/AngularLynxWebGL.m +58 -23
- package/templates/ios/App/AngularLynxWebGLContext.m +25 -21
- package/templates/ios/App/AnimationFrameRate.swift +214 -0
- package/templates/ios/App/AppDelegate.swift +2 -0
- package/templates/ios/App/AssetsModule.swift +3 -1
- package/templates/ios/App/DevServer.swift +3 -0
- package/templates/ios/App/Info.plist +12 -5
- package/templates/ios/App/LynxViewController.swift +24 -1
- package/templates/ios/App/ShellModule.swift +14 -1
- package/templates/ios/App/ShortcutsModule.swift +82 -0
- package/templates/ios/App/SplashScreen.swift +71 -0
- package/templates/ios/App/WebViewLoader.swift +95 -0
- package/templates/ios/App/XElementRegistry.swift +5 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ User documentation: [Publishing your App](../website/docs/guide/building-for-pro
|
|
|
6
6
|
|
|
7
7
|
## What it does
|
|
8
8
|
|
|
9
|
-
1. **Generates** the native project from `templates/ios` or `templates/android` into the project's folder in Angular's build cache (`.angular/cache/<Angular version>/<project>/lynx-native/<platform>`, which `ng new` already gitignores and `ng cache clean` clears), writing the app options from `angular.json` into the few files the templates mark for it. It regenerates only when a hash of its inputs changes (this package's version, the template, the options, the icon images), so Xcode and Gradle keep their incremental state.
|
|
9
|
+
1. **Generates** the native project from `templates/ios` or `templates/android` into the project's folder in Angular's build cache (`.angular/cache/<Angular version>/<project>/lynx-native/<platform>`, which `ng new` already gitignores and `ng cache clean` clears), writing the app options from `angular.json` into the few files the templates mark for it. It regenerates only when a hash of its inputs changes (this package's version, the template, the options, the icon and splash images), so Xcode and Gradle keep their incremental state.
|
|
10
10
|
2. **Copies** `dist/` (without the web bundle) into the project.
|
|
11
11
|
3. **Builds** it with `xcodebuild` or Gradle and copies the binaries to `dist/<platform>/`.
|
|
12
12
|
4. **Runs** it, with `--run` (`src/ios/run.ts`, `src/android/run.ts`): picks a simulator, emulator or phone (`--device`, else a running one, else the newest iPhone simulator or the first AVD) and starts it before step 3, so it boots while the app compiles; then installs the app and opens it. iOS uses `simctl` and shows the simulator in DeviceHub (`devices://device/open?id=<UDID>`) or, before Xcode 27.1, the Simulator app. When `--device` names a paired iPhone (`src/ios/iphone.ts`, found with `devicectl list devices`), step 3 builds a development-signed `-sdk iphoneos` app for it instead (`ios.teamId`, `-allowProvisioningUpdates`), and `devicectl` installs and opens it. Android uses the SDK's `adb` and `emulator` and opens the launcher activity by component.
|
|
@@ -19,17 +19,19 @@ An ejected project (`ios/` or `android/` with a `.angular-lynx-ejected` marker,
|
|
|
19
19
|
|
|
20
20
|
Both are one full-screen `LynxView` running `main.lynx.bundle`; Angular Router does all navigation inside it. Bundles and assets load from inside the app, so RSpeedy's default asset prefix (`/static/...`) works with no configuration. The `LynxView` fills the screen, under the status bar and the home indicator (`"edgeToEdge": false` in angular.json puts it inside the safe area instead). Lynx's own CSS `env(safe-area-inset-*)` is 0 there: Android never sets it, and the iOS shell creates its `LynxView` before the window is key, where Lynx reads it. The runtime gives every `env(safe-area-inset-*)` the insets the shell sends instead (see `safe-area-insets.ts` in the runtime), so they follow rotation. On Android the activity still pads the page for the keyboard, and the bottom inset is 0 while it's open. An `<overlay>` fills the screen too, so a bottom sheet covers the page down to the screen's edge and pads its content by the insets: on Android XElement's overlay window stops above the navigation bar, so the shell registers its own `overlay` behavior, `EdgeToEdgeOverlay.kt`, whose window draws under every bar, as the activity's does.
|
|
21
21
|
|
|
22
|
+
Both run Lynx's engine thread, where the main thread's JavaScript, and so the whole Angular app, runs with layout and Lynx's animator, off the platform's UI thread: Lynx's `MostOnTASM` thread strategy (`setThreadStrategyForRender(.mostOnTASM)`, `setThreadStrategyForRendering(ThreadStrategyForRendering.MOST_ON_TASM)`), where Lynx's default, and Lynx Explorer's, is `AllOnUI`. So change detection, a screen being built or a busy event handler doesn't freeze what UIKit and Android run themselves: a scroll view's momentum, typing in a text field, a web view. The cost is that the element tree reaches the screen a step later, after the flush crosses to the UI thread, and UI methods with it: the build plugin turns on Lynx's pending invokes (`enableElementInvokeUIMethodPendingTask`), which send a method after the flush that makes the element's UI. A `<list>` needs `enable-async-list` under this strategy, which the runtime sets on every list. The main-thread modules run on the engine thread too (below).
|
|
23
|
+
|
|
22
24
|
Both send the same global props, which the runtime's services read: `platform`, `theme` (again whenever the phone switches between light and dark), `appLocale` (the phone's language as a BCP 47 tag), `appTimeZone` (its time zone's IANA name, which the `intl` build option's `Intl.DateTimeFormat` uses), `isNotchScreen`, `edgeToEdge`, the safe-area insets `safeAreaTop`, `safeAreaBottom`, `safeAreaLeft` and `safeAreaRight` (again whenever they change), `osVersion` (which Lynx leaves out of the main thread's `SystemInfo`), and the accessibility settings `reduceMotion`, `reduceTransparency` (iOS only) and `increaseContrast`, again whenever the user changes one. Android 12 and later also send `dynamicColors`, the wallpaper's Material 3 color roles in light and dark (`DynamicColors.kt`), again when the user changes their wallpaper or colors. Lynx Explorer sends `theme` and `isNotchScreen` too, but no `appLocale`, `appTimeZone`, `osVersion` or accessibility settings. See [`templates/android/README.md`](templates/android/README.md) for the Android shell's details.
|
|
23
25
|
|
|
24
|
-
Both register the native modules the runtime's services call, which Lynx Explorer doesn't have: `AngularLynxWebAuth` (`WebAuthModule.swift`, `WebAuthModule.kt`) opens `LynxWebAuthSession`'s sign-in page, in `ASWebAuthenticationSession` on iOS and a Custom Tab on Android, and returns the URL it redirects to. `AngularLynxLocalStorage` (`LocalStorageModule.swift`, `LocalStorageModule.kt`) keeps `LynxLocalStorage`'s values in a `UserDefaults` suite and a `SharedPreferences` file of their own. `AngularLynxSecureStorage` (`SecureStorageModule.swift`, `SecureStorageModule.kt`) keeps `LynxSecureStorage`'s in the Keychain on iOS and, on Android, in `SharedPreferences`, each value encrypted with AES-GCM by an Android Keystore key, a file Auto Backup leaves out (`res/xml/backup_rules.xml`, `data_extraction_rules.xml`). `AngularLynxLinking` (`LinkingModule.swift`, `LinkingModule.kt`) opens `LynxLinking`'s links: `openURL` with `UIApplication.open` and an `ACTION_VIEW` intent, `openInApp` in `SFSafariViewController` and a Custom Tab, and `canOpenURL` with `UIApplication.canOpenURL` and `resolveActivity`, which answer only for the schemes the generator writes from angular.json's `canOpenURLSchemes` (with `http`, `https`, `mailto`, `tel` and `sms`) into Info.plist's `LSApplicationQueriesSchemes` and the manifest's `<queries>`. `AngularLynxImagePicker` (`ImagePickerModule.swift`, `ImagePickerModule.kt`) lets the person pick a photo for `LynxImagePicker`, with `PHPickerViewController` on iOS and the Photo Picker on Android, neither of which needs a permission, and calls back with it as base64, re-encoded as an upright JPEG when the app asks for a smaller one or the photo is a format such as HEIC. `AngularLynxShare` (`ShareModule.swift`, `ShareModule.kt`) opens `LynxShare`'s share sheet, `UIActivityViewController` on iOS and an `ACTION_SEND` chooser on Android, with the files written to temporary files on iOS and shared through a `FileProvider` on Android. Save Image on iOS needs `NSPhotoLibraryAddUsageDescription`, which the generator always writes (angular.json's `permissions.savePhotos`, with a default). `AngularLynxShell` (`ShellModule.swift`, `ShellModule.kt`) has `collectGarbage`, which the runtime calls once the app has released about a screen's worth of elements and settled: it reports moderate memory pressure with `LynxEnv.trimMemory`, which makes Lynx run a full collection of the main thread's JavaScript heap, freeing what PrimJS's routine collections leave behind of the screens that went. On Android it also connects the back button. Both shells report the system's memory warnings to `trimMemory` too, and leaving the screen.
|
|
26
|
+
Both register the native modules the runtime's services call, which Lynx Explorer doesn't have: `AngularLynxWebAuth` (`WebAuthModule.swift`, `WebAuthModule.kt`) opens `LynxWebAuthSession`'s sign-in page, in `ASWebAuthenticationSession` on iOS and a Custom Tab on Android, and returns the URL it redirects to. `AngularLynxLocalStorage` (`LocalStorageModule.swift`, `LocalStorageModule.kt`) keeps `LynxLocalStorage`'s values in a `UserDefaults` suite and a `SharedPreferences` file of their own. `AngularLynxSecureStorage` (`SecureStorageModule.swift`, `SecureStorageModule.kt`) keeps `LynxSecureStorage`'s in the Keychain on iOS and, on Android, in `SharedPreferences`, each value encrypted with AES-GCM by an Android Keystore key, a file Auto Backup leaves out (`res/xml/backup_rules.xml`, `data_extraction_rules.xml`). `AngularLynxLinking` (`LinkingModule.swift`, `LinkingModule.kt`) opens `LynxLinking`'s links: `openURL` with `UIApplication.open` and an `ACTION_VIEW` intent, `openInApp` in `SFSafariViewController` and a Custom Tab, and `canOpenURL` with `UIApplication.canOpenURL` and `resolveActivity`, which answer only for the schemes the generator writes from angular.json's `canOpenURLSchemes` (with `http`, `https`, `mailto`, `tel` and `sms`) into Info.plist's `LSApplicationQueriesSchemes` and the manifest's `<queries>`. `AngularLynxImagePicker` (`ImagePickerModule.swift`, `ImagePickerModule.kt`) lets the person pick a photo for `LynxImagePicker`, with `PHPickerViewController` on iOS and the Photo Picker on Android, neither of which needs a permission, and calls back with it as base64, re-encoded as an upright JPEG when the app asks for a smaller one or the photo is a format such as HEIC. `AngularLynxShare` (`ShareModule.swift`, `ShareModule.kt`) opens `LynxShare`'s share sheet, `UIActivityViewController` on iOS and an `ACTION_SEND` chooser on Android, with the files written to temporary files on iOS and shared through a `FileProvider` on Android. Save Image on iOS needs `NSPhotoLibraryAddUsageDescription`, which the generator always writes (angular.json's `permissions.savePhotos`, with a default). `AngularLynxShell` (`ShellModule.swift`, `ShellModule.kt`) has `hideSplashScreen`, which the runtime's `LynxSplashScreen` calls once the app's first screen is drawn (at Angular's first frame, or when `provideSplashScreen()` says): the phone takes a launch screen down at the app's first frame, which is the empty LynxView, so the iOS shell keeps a copy of it over the LynxView (`SplashScreen.swift`, the `LaunchBackground` color and `LaunchImage` image the generator writes from angular.json's `splash`) and Android's `MainActivity` keeps AndroidX's splash screen up (`installSplashScreen()`, `setKeepOnScreenCondition`), each fading it out when it's called, or five seconds after the app starts. It has `collectGarbage`, which the runtime calls once the app has released about a screen's worth of elements and settled: it reports moderate memory pressure with `LynxEnv.trimMemory`, which makes Lynx run a full collection of the main thread's JavaScript heap, freeing what PrimJS's routine collections leave behind of the screens that went. On Android it also connects the back button. Both shells report the system's memory warnings to `trimMemory` too, and leaving the screen. `AngularLynxShortcuts` (`ShortcutsModule.swift`, `ShortcutsModule.kt`) keeps the shortcuts the person ran until the runtime's `LynxShortcuts` takes them, with `take`, at startup and each time the shell sends the `angularLynxShortcut` global event, so the shortcut that started the app isn't lost and none is handled twice. The generator writes angular.json's `shortcuts` as App Intents on iOS (`App/AppShortcuts.swift`, with an `AppShortcutsProvider`: Xcode's App Intents step reads the titles and phrases out of the compiled code, so they have to be source), which Siri, Spotlight and the Shortcuts app run, and as static shortcuts on Android (`res/xml/shortcuts.xml`, with the titles in `res/values/shortcuts.xml`), in the menu a long press on the app's icon opens. Android starts a static shortcut's activity in a cleared task, which would end the running app, so they point at `ShortcutActivity`, which has a task of its own and passes the shortcut on to `MainActivity`.
|
|
25
27
|
|
|
26
28
|
Only the development build (`ng serve --platform`) loads from a dev server: the code is in `App/DevServer.swift` and `App/DevServerModules.swift` under `#if DEBUG`, and in the debug source set on Android (`app/src/debug`, with a no-op `DevServer` in `app/src/release`), so a release build can't be pointed anywhere else. `DevServer` reads the URL from the launch argument or intent extra and keeps it (`UserDefaults`, `SharedPreferences`), so the app opened from the home screen loads from the same server. The loaders (`BundleResourceFetcher.swift`, `ResourceFetchers.kt`) and `AngularLynxAssets` then fetch every relative URL, and on Android every URL on the address the bundle was built with, from the dev server instead of the app, uncached. When the bundle itself doesn't load, `DevServer` covers the page with a message and loads it again every two seconds. rspeedy's live reload client talks to Lynx DevTool, which the shells don't have: `NativeModules.LynxWebSocketModule` (through `@lynx-js/websocket`) for the dev server's socket and `NativeModules.LynxDevToolSetModule.invokeCdp` for a full reload (a DevTool protocol `Page.reload`). The development build registers modules under those names (`DevWebSocketModule`, `DevReloadModule`): a WebSocket with `URLSessionWebSocketTask` and OkHttp that sends the same `websocketOpen`, `websocketMessage`, `websocketClosed` and `websocketFailed` global events as Lynx DevTool's, and a `Page.reload` that loads the bundle again, as DevTool's `LynxPageReloadHelper` does. URLSession sends an empty `Sec-WebSocket-Protocol` header for an empty protocol list, which the dev server refuses, so the iOS socket passes none then. On Android, the debug build's `network_security_config.xml` allows plain HTTP to any host, since the app's own `fetch()` of an imported file goes to the address the bundle was built with; the release build's allows it to `localhost` alone.
|
|
27
29
|
|
|
28
30
|
`AngularLynxClipboard` (`ClipboardModule.swift`, `ClipboardModule.kt`) copies `LynxClipboard`'s text to `UIPasteboard.general` on iOS and `ClipboardManager` on Android, and reads it back.
|
|
29
31
|
|
|
30
|
-
Both link Lynx's XElement library, which holds `<input>`, `<textarea>`, `<overlay>`, `<svg>`, `<blur-view>`, `<viewpager>`, `<refresh>`, the `<scroll-coordinator>` family, `<webview>` and `<video>`. Lynx's core doesn't include these, and a host that doesn't register them renders nothing for those tags (on Android, nothing after them either). XElement's AnimaX and Markdown elements are left out: the runtime doesn't support them. On iOS, `<blur-view>` is XElement's with more of UIKit in it (`App/BlurView.swift`): a `blur-material` attribute for UIKit's adaptive blur materials, which the glass components draw their design before iOS 26 on (Lynx's blur-view has only the styles from before iOS 13); Liquid Glass that materializes, dissolves and eases between effects inside a `glass-container`, where Lynx's sets its effect at once; and a `glass-effect-id` attribute that pairs two glass shapes across a change so one morphs into the other (`App/GlassTransitions.swift`).
|
|
32
|
+
Both link Lynx's XElement library, which holds `<input>`, `<textarea>`, `<overlay>`, `<svg>`, `<blur-view>`, `<viewpager>`, `<refresh>`, the `<scroll-coordinator>` family, `<webview>` and `<video>`. Lynx's core doesn't include these, and a host that doesn't register them renders nothing for those tags (on Android, nothing after them either). XElement's AnimaX and Markdown elements are left out: the runtime doesn't support them. On iOS, `<blur-view>` is XElement's with more of UIKit in it (`App/BlurView.swift`): a `blur-material` attribute for UIKit's adaptive blur materials, which the glass components draw their design before iOS 26 on (Lynx's blur-view has only the styles from before iOS 13); Liquid Glass that materializes, dissolves and eases between effects inside a `glass-container`, where Lynx's sets its effect at once; and a `glass-effect-id` attribute that pairs two glass shapes across a change so one morphs into the other (`App/GlassTransitions.swift`). `<webview>` loads through XElement's loader, wrapped (`App/WebViewLoader.swift`) to take the loader off its web view's script message handlers when the element goes: XElement's loader never does, so the loader and the web view kept each other, and the web view's WebContent process, for as long as the app ran (issue #397).
|
|
31
33
|
|
|
32
|
-
Both have `<canvas>` with WebGL2 (issue #211), which Lynx doesn't: a `canvas` element (`App/AngularLynxWebGL.m`'s `AngularLynxCanvas`, a `CAMetalLayer` view; `CanvasUI.kt`, a `TextureView`) and the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to, which runs them on OpenGL ES 3.0 (`App/AngularLynxWebGLContext.m`, `WebGLContext.kt`). On iOS that's [ANGLE](https://chromium.googlesource.com/angle/angle)'s OpenGL ES, on Metal, which Safari draws WebGL with too: iOS's own OpenGL ES is deprecated, and the Simulator runs it on the CPU, at seconds a frame for a lit three.js scene (issue #238), where Metal draws on the Mac's GPU. ANGLE's `libEGL` and `libGLESv2` frameworks, and its headers, come in the Lynx frameworks zip (below). Android's OpenGL ES is the phone's, which the emulator already runs on the Mac's GPU. The runtime runs on Lynx's main thread and WebGL needs answers synchronously, so both turn on main-thread modules (`enableMTSModule`): the config's modules are then callable from main-thread JavaScript as `lynx.module(name)
|
|
34
|
+
Both have `<canvas>` with WebGL2 (issue #211), which Lynx doesn't: a `canvas` element (`App/AngularLynxWebGL.m`'s `AngularLynxCanvas`, a `CAMetalLayer` view; `CanvasUI.kt`, a `TextureView`) and the `AngularLynxWebGL` module the runtime's WebGL2 context sends its calls to, which runs them on OpenGL ES 3.0 (`App/AngularLynxWebGLContext.m`, `WebGLContext.kt`). On iOS that's [ANGLE](https://chromium.googlesource.com/angle/angle)'s OpenGL ES, on Metal, which Safari draws WebGL with too: iOS's own OpenGL ES is deprecated, and the Simulator runs it on the CPU, at seconds a frame for a lit three.js scene (issue #238), where Metal draws on the Mac's GPU. ANGLE's `libEGL` and `libGLESv2` frameworks, and its headers, come in the Lynx frameworks zip (below). Android's OpenGL ES is the phone's, which the emulator already runs on the Mac's GPU. The runtime runs on Lynx's main thread and WebGL needs answers synchronously, so both turn on main-thread modules (`enableMTSModule`): the config's modules are then callable from main-thread JavaScript as `lynx.module(name)`, and Lynx calls them on its engine thread, not the UI thread. An EGL context is current on one thread at a time, so GL runs there too, while the canvas's view lives on the UI thread. On iOS the view hands the context what it draws into, its `CAMetalLayer` and its size in pixels (`AngularLynxCanvasTarget`), through Lynx's `runOnTasmThread:`, so the contexts and the canvas registry are the engine thread's alone, and the context keeps its EGL context current there between batches; it sets the view's opacity back on the UI thread. On Android each call already makes the context current and puts back what was current before, so `WebGLContext` and `CanvasRegistry` are locked instead: the `TextureView`'s surface callbacks, on the UI thread, wait for a batch to end, which keeps the EGL surface from outliving the `SurfaceTexture` it draws to. The WebGL module's `encodeImage`, behind `canvas.toBlob()` and `toDataURL()`, reads the drawing buffer and encodes it as a PNG or JPEG with ImageIO or `Bitmap.compress`; on iOS it reads through a pixel pack buffer, since ANGLE on Metal reads straight into memory many times slower. `AngularLynxAssets` (`App/AssetsModule.swift`, `AssetsModule.kt`) reads a file the app bundles for the main thread's `fetch`, which has no page URL to resolve `/static/...` against. The command numbers the WebGL module reads (`App/AngularLynxWebGLOps.h`, `WebGLOps.kt`) are generated from the runtime's `canvas/webgl-ops.ts` with `npm run generate:webgl-ops -w packages/native`; `scripts/webgl-ops.test.ts` fails when they're stale. UIKit's module imports Apple's OpenGL ES headers into every file, so `AngularLynxWebGLContext.m` turns off their deprecation warnings, which land on ANGLE's functions of the same names; the explicit link to `libGLESv2` comes before UIKit's automatic one to OpenGLES, so those calls bind to ANGLE.
|
|
33
35
|
|
|
34
36
|
| | iOS | Android |
|
|
35
37
|
| ---------------- | ---------------------------------------------------- | -------------------------------------------------------- |
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { PlatformGenerator } from '../generate.ts';
|
|
2
|
-
import type
|
|
2
|
+
import { type ResolvedApp } from '../options.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Writes the app options into the Android template: identity goes in
|
|
5
5
|
* angular-lynx.properties (which app/build.gradle.kts reads), and permissions,
|
|
6
6
|
* deep links and the apps canOpenURL can see go between the manifest's
|
|
7
|
-
* `angular-lynx:*` markers,
|
|
8
|
-
* resources
|
|
7
|
+
* `angular-lynx:*` markers, the icon options become the launcher icon's
|
|
8
|
+
* resources, the shortcuts become the static shortcuts' resources, and the
|
|
9
|
+
* splash becomes the splash theme's color and image.
|
|
9
10
|
*/
|
|
10
11
|
export declare const androidGenerator: PlatformGenerator;
|
|
11
12
|
/**
|
|
@@ -23,6 +24,29 @@ export declare const deepLinkEntries: (app: ResolvedApp) => string;
|
|
|
23
24
|
* though startActivity() still opens one.
|
|
24
25
|
*/
|
|
25
26
|
export declare const queriesEntries: (app: ResolvedApp) => string;
|
|
27
|
+
/**
|
|
28
|
+
* res/xml/shortcuts.xml: angular.json's `shortcuts` as the app's static
|
|
29
|
+
* shortcuts, the ones in the menu a long press on the app's icon opens.
|
|
30
|
+
* They're there from the moment the app is installed, which the ones an app
|
|
31
|
+
* adds while it runs aren't.
|
|
32
|
+
*
|
|
33
|
+
* Each starts ShortcutActivity with its ID and route, which hands them to
|
|
34
|
+
* MainActivity (see ShortcutActivity.kt for why not directly). A shortcut's
|
|
35
|
+
* intent names its activity in full, with the applicationId as the package,
|
|
36
|
+
* since the manifest's placeholders don't reach other resources.
|
|
37
|
+
*/
|
|
38
|
+
export declare const shortcutsXml: (app: ResolvedApp) => string;
|
|
39
|
+
/**
|
|
40
|
+
* Text as an Android string resource. Besides XML's own characters, a
|
|
41
|
+
* resource reads `'` and `"` as quoting, a backslash as an escape, and a
|
|
42
|
+
* leading `@` or `?` as a reference to another resource.
|
|
43
|
+
*/
|
|
44
|
+
export declare const stringResource: (text: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* res/values/shortcuts.xml: each shortcut's title, which a shortcut can only
|
|
47
|
+
* take from a string resource.
|
|
48
|
+
*/
|
|
49
|
+
export declare const shortcutStringsXml: (app: ResolvedApp) => string;
|
|
26
50
|
/** The Android SDK, from the environment or the Android Studio default. */
|
|
27
51
|
export declare const findAndroidSdk: (env?: NodeJS.ProcessEnv) => string | undefined;
|
|
28
52
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/android/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/android/project.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,eAAe,CAAC;AAevB;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,iBA+B9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,WAOtC,CAAC;AAEN,eAAO,MAAM,UAAU,GAAI,KAAK,WAAW,KAAG,MAYhC,CAAC;AAEf,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,KAAG,MAiBpD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,KAAK,WAAW,KAAG,MAYjC,CAAC;AAEnB;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,WAAW,KAAG,MAUpC,CAAC;AAOf;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,WAAW,KAAG,MAgClC,CAAC;AAEf;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,MAMpB,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,WAAW,KAAG,MAWxC,CAAC;AAEf,2EAA2E;AAC3E,eAAO,MAAM,cAAc,GACzB,MAAK,MAAM,CAAC,UAAwB,KACnC,MAAM,GAAG,SAaX,CAAC"}
|
package/dist/android/project.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import os from 'node:os';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { shortcutIdentifier, } from "../options.js";
|
|
4
5
|
import { PERMISSION_MAP } from "../permissions.js";
|
|
6
|
+
import { writeAndroidSplash } from "../splash.js";
|
|
5
7
|
import { writeAndroidIcon } from "./icon.js";
|
|
6
8
|
import { escapeXml, replaceMarker } from "../xml.js";
|
|
7
9
|
const MANIFEST = 'app/src/main/AndroidManifest.xml';
|
|
10
|
+
const RESOURCES = 'app/src/main/res';
|
|
8
11
|
const SCREEN_ORIENTATIONS = {
|
|
9
12
|
portrait: 'portrait',
|
|
10
13
|
landscape: 'sensorLandscape',
|
|
@@ -14,8 +17,9 @@ const SCREEN_ORIENTATIONS = {
|
|
|
14
17
|
* Writes the app options into the Android template: identity goes in
|
|
15
18
|
* angular-lynx.properties (which app/build.gradle.kts reads), and permissions,
|
|
16
19
|
* deep links and the apps canOpenURL can see go between the manifest's
|
|
17
|
-
* `angular-lynx:*` markers,
|
|
18
|
-
* resources
|
|
20
|
+
* `angular-lynx:*` markers, the icon options become the launcher icon's
|
|
21
|
+
* resources, the shortcuts become the static shortcuts' resources, and the
|
|
22
|
+
* splash becomes the splash theme's color and image.
|
|
19
23
|
*/
|
|
20
24
|
export const androidGenerator = {
|
|
21
25
|
configure: (dir, app, projectRoot) => {
|
|
@@ -29,7 +33,14 @@ export const androidGenerator = {
|
|
|
29
33
|
manifest = replaceMarker(manifest, 'deep-links', deepLinkEntries(app));
|
|
30
34
|
manifest = replaceMarker(manifest, 'queries', queriesEntries(app));
|
|
31
35
|
writeFileSync(manifestPath, manifest);
|
|
36
|
+
// The template's shortcuts.xml is an empty list, which an app without
|
|
37
|
+
// shortcuts keeps.
|
|
38
|
+
if (app.shortcuts.length > 0) {
|
|
39
|
+
writeFileSync(path.join(dir, RESOURCES, 'xml/shortcuts.xml'), shortcutsXml(app));
|
|
40
|
+
writeFileSync(path.join(dir, RESOURCES, 'values/shortcuts.xml'), shortcutStringsXml(app));
|
|
41
|
+
}
|
|
32
42
|
writeAndroidIcon(dir, app, projectRoot);
|
|
43
|
+
writeAndroidSplash(dir, app, projectRoot);
|
|
33
44
|
},
|
|
34
45
|
bundleDir: (dir) => path.join(dir, 'app/src/main/assets'),
|
|
35
46
|
};
|
|
@@ -90,6 +101,76 @@ export const queriesEntries = (app) => [
|
|
|
90
101
|
]),
|
|
91
102
|
'</queries>',
|
|
92
103
|
].join('\n');
|
|
104
|
+
/**
|
|
105
|
+
* The string resource holding a shortcut's label.
|
|
106
|
+
*/
|
|
107
|
+
const shortcutLabel = (id) => `shortcut_${shortcutIdentifier(id)}`;
|
|
108
|
+
/**
|
|
109
|
+
* res/xml/shortcuts.xml: angular.json's `shortcuts` as the app's static
|
|
110
|
+
* shortcuts, the ones in the menu a long press on the app's icon opens.
|
|
111
|
+
* They're there from the moment the app is installed, which the ones an app
|
|
112
|
+
* adds while it runs aren't.
|
|
113
|
+
*
|
|
114
|
+
* Each starts ShortcutActivity with its ID and route, which hands them to
|
|
115
|
+
* MainActivity (see ShortcutActivity.kt for why not directly). A shortcut's
|
|
116
|
+
* intent names its activity in full, with the applicationId as the package,
|
|
117
|
+
* since the manifest's placeholders don't reach other resources.
|
|
118
|
+
*/
|
|
119
|
+
export const shortcutsXml = (app) => [
|
|
120
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
121
|
+
'<!--',
|
|
122
|
+
' Written by @blotch/angular-lynx-native from the shortcuts in',
|
|
123
|
+
" angular.json's builder options on every build. Edits here are",
|
|
124
|
+
' overwritten; change angular.json instead (or eject).',
|
|
125
|
+
'-->',
|
|
126
|
+
'<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">',
|
|
127
|
+
...app.shortcuts.flatMap((shortcut) => [
|
|
128
|
+
' <shortcut',
|
|
129
|
+
` android:shortcutId="${escapeXml(shortcut.id)}"`,
|
|
130
|
+
' android:enabled="true"',
|
|
131
|
+
// A shortcut without an icon gets an empty circle in the launcher's
|
|
132
|
+
// menu, so each takes the app's.
|
|
133
|
+
' android:icon="@mipmap/ic_launcher"',
|
|
134
|
+
` android:shortcutShortLabel="@string/${shortcutLabel(shortcut.id)}">`,
|
|
135
|
+
' <intent',
|
|
136
|
+
' android:action="android.intent.action.VIEW"',
|
|
137
|
+
` android:targetPackage="${escapeXml(app.id)}"`,
|
|
138
|
+
' android:targetClass="dev.angularlynx.shell.ShortcutActivity">',
|
|
139
|
+
` <extra android:name="angularLynxShortcutId" android:value="${escapeXml(shortcut.id)}" />`,
|
|
140
|
+
...(shortcut.route === undefined
|
|
141
|
+
? []
|
|
142
|
+
: [
|
|
143
|
+
` <extra android:name="angularLynxShortcutRoute" android:value="${escapeXml(shortcut.route)}" />`,
|
|
144
|
+
]),
|
|
145
|
+
' </intent>',
|
|
146
|
+
' </shortcut>',
|
|
147
|
+
]),
|
|
148
|
+
'</shortcuts>',
|
|
149
|
+
'',
|
|
150
|
+
].join('\n');
|
|
151
|
+
/**
|
|
152
|
+
* Text as an Android string resource. Besides XML's own characters, a
|
|
153
|
+
* resource reads `'` and `"` as quoting, a backslash as an escape, and a
|
|
154
|
+
* leading `@` or `?` as a reference to another resource.
|
|
155
|
+
*/
|
|
156
|
+
export const stringResource = (text) => text
|
|
157
|
+
.replace(/[\\'"]/g, '\\$&')
|
|
158
|
+
.replace(/^[@?]/, '\\$&')
|
|
159
|
+
.replace(/&/g, '&')
|
|
160
|
+
.replace(/</g, '<')
|
|
161
|
+
.replace(/>/g, '>');
|
|
162
|
+
/**
|
|
163
|
+
* res/values/shortcuts.xml: each shortcut's title, which a shortcut can only
|
|
164
|
+
* take from a string resource.
|
|
165
|
+
*/
|
|
166
|
+
export const shortcutStringsXml = (app) => [
|
|
167
|
+
'<?xml version="1.0" encoding="utf-8"?>',
|
|
168
|
+
"<!-- Written from angular.json's shortcuts (see xml/shortcuts.xml). -->",
|
|
169
|
+
'<resources>',
|
|
170
|
+
...app.shortcuts.map((shortcut) => ` <string name="${shortcutLabel(shortcut.id)}">${stringResource(shortcut.title)}</string>`),
|
|
171
|
+
'</resources>',
|
|
172
|
+
'',
|
|
173
|
+
].join('\n');
|
|
93
174
|
/** The Android SDK, from the environment or the Android Studio default. */
|
|
94
175
|
export const findAndroidSdk = (env = process.env) => {
|
|
95
176
|
const candidates = [
|
package/dist/generate.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type PreparedProject = {
|
|
|
36
36
|
* `<workDir>/<platform>`, or the user's ejected folder.
|
|
37
37
|
*
|
|
38
38
|
* Generation is skipped when a hash of every input (this package's version,
|
|
39
|
-
* the template files, the app options and the icon images) matches the last run, so
|
|
39
|
+
* the template files, the app options and the icon and splash images) matches the last run, so
|
|
40
40
|
* Xcode and Gradle keep their incremental state between builds. The bundle is
|
|
41
41
|
* copied in on every build, because it changes on every build.
|
|
42
42
|
*
|
package/dist/generate.js
CHANGED
|
@@ -18,7 +18,7 @@ const HASH_FILE = '.angular-lynx-hash';
|
|
|
18
18
|
* `<workDir>/<platform>`, or the user's ejected folder.
|
|
19
19
|
*
|
|
20
20
|
* Generation is skipped when a hash of every input (this package's version,
|
|
21
|
-
* the template files, the app options and the icon images) matches the last run, so
|
|
21
|
+
* the template files, the app options and the icon and splash images) matches the last run, so
|
|
22
22
|
* Xcode and Gradle keep their incremental state between builds. The bundle is
|
|
23
23
|
* copied in on every build, because it changes on every build.
|
|
24
24
|
*
|
|
@@ -104,7 +104,13 @@ const inputHash = ({ platform, app, projectRoot, packageVersion, }) => {
|
|
|
104
104
|
// replacing one with a new image of the same name regenerates the icons.
|
|
105
105
|
// A missing file is hashed as such: generation then fails and says so.
|
|
106
106
|
const { foreground, background } = (platform === 'android' && app.android.adaptiveIcon) || {};
|
|
107
|
-
for (const file of [
|
|
107
|
+
for (const file of [
|
|
108
|
+
app.icon,
|
|
109
|
+
foreground,
|
|
110
|
+
background,
|
|
111
|
+
app.splash.light.image,
|
|
112
|
+
app.splash.dark.image,
|
|
113
|
+
]) {
|
|
108
114
|
if (file && !ICON_BACKGROUND_COLOR.test(file)) {
|
|
109
115
|
const absolute = path.resolve(projectRoot, file);
|
|
110
116
|
hash.update(existsSync(absolute) ? readFileSync(absolute) : 'missing');
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type { Platform } from './generate.ts';
|
|
|
5
5
|
export { EJECT_MARKER, copyBundle, prepareProject } from './generate.ts';
|
|
6
6
|
export { renderEjectedProject } from './eject.ts';
|
|
7
7
|
export { LYNX_IOS, FRAMEWORKS_ENV } from './ios/frameworks.ts';
|
|
8
|
-
export type { AndroidOptions, IosExportMethod, IosOptions, NativeAppOptions, Orientation, Permission, ResolvedApp, } from './options.ts';
|
|
8
|
+
export type { AndroidOptions, IosExportMethod, IosOptions, NativeAppOptions, Orientation, Permission, ResolvedApp, SplashOptions, } from './options.ts';
|
|
9
9
|
export { NativeConfigError, resolveAppOptions } from './options.ts';
|
|
10
10
|
export { NativeBuildError } from './process.ts';
|
|
11
11
|
export type { DevServerOptions, RunOptions } from './run.ts';
|
|
@@ -44,6 +44,8 @@ export type BuildNativeAppOptions = {
|
|
|
44
44
|
*/
|
|
45
45
|
readonly devServer?: DevServerOptions;
|
|
46
46
|
readonly log: (message: string) => void;
|
|
47
|
+
/** Where warnings go, such as an image too wide for Android's splash. */
|
|
48
|
+
readonly warn?: (message: string) => void;
|
|
47
49
|
};
|
|
48
50
|
/**
|
|
49
51
|
* Turns a built Lynx bundle into native binaries: generates (or reuses) the
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,QAAQ,EAGd,MAAM,eAAe,CAAC;AASvB,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,cAAc,CAAC;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,KAAK,QAAQ,EAGd,MAAM,eAAe,CAAC;AASvB,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,cAAc,CAAC;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG7D,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC/D,YAAY,EACV,cAAc,EACd,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,UAAU,EACV,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAW7D,eAAO,MAAM,eAAe,EAAE,MAErB,CAAC;AAEV,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,mEAAmE;IACnE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8CAA8C;IAC9C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,mEAAmE;IACnE,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B;;;OAGG;IACH,QAAQ,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GACzB,SAAS,qBAAqB,KAC7B,OAAO,CAAC;IACT,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B,CAiJA,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ import { iosGenerator } from "./ios/project.js";
|
|
|
11
11
|
import { startIosTarget } from "./ios/run.js";
|
|
12
12
|
import { resolveAppOptions } from "./options.js";
|
|
13
13
|
import { NativeBuildError } from "./process.js";
|
|
14
|
+
import { splashWarnings } from "./splash.js";
|
|
14
15
|
export { EJECT_MARKER, copyBundle, prepareProject } from "./generate.js";
|
|
15
16
|
export { renderEjectedProject } from "./eject.js";
|
|
16
17
|
export { LYNX_IOS, FRAMEWORKS_ENV } from "./ios/frameworks.js";
|
|
@@ -88,6 +89,14 @@ export const buildNativeApp = async (options) => {
|
|
|
88
89
|
: project.regenerated
|
|
89
90
|
? `Generated the ${platform} project`
|
|
90
91
|
: `Reusing the generated ${platform} project (no config changes)`);
|
|
92
|
+
// On every build, not only when the project is generated, so a warning
|
|
93
|
+
// isn't lost once the project is reused. An ejected project draws its
|
|
94
|
+
// splash from its own files.
|
|
95
|
+
if (!project.ejected) {
|
|
96
|
+
for (const warning of splashWarnings(app, projectRoot, platform)) {
|
|
97
|
+
(options.warn ?? log)(warning);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
91
100
|
// Where the app was built for, which a development build for a simulator
|
|
92
101
|
// or a phone depends on as much as on the project.
|
|
93
102
|
const destination = target?.iPhone?.udid ?? target?.simulator?.udid ?? '';
|
package/dist/ios/project.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { PlatformGenerator } from '../generate.ts';
|
|
2
|
-
import type
|
|
2
|
+
import { type ResolvedApp } from '../options.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Writes the app options into the iOS template: build settings go in
|
|
5
|
-
* Config/App.xcconfig (which App.xcodeproj reads),
|
|
6
|
-
* between the template's `angular-lynx:info` markers
|
|
5
|
+
* Config/App.xcconfig (which App.xcodeproj reads), Info.plist entries go
|
|
6
|
+
* between the template's `angular-lynx:info` markers, the shortcuts
|
|
7
|
+
* become App/AppShortcuts.swift, and the icon and the splash go in the asset
|
|
8
|
+
* catalog.
|
|
7
9
|
*/
|
|
8
10
|
export declare const iosGenerator: PlatformGenerator;
|
|
9
11
|
export declare const xcconfig: (app: ResolvedApp) => string;
|
|
@@ -17,4 +19,19 @@ export declare const LOCAL_NETWORK_REASON = "Loads the app from ng serve on your
|
|
|
17
19
|
export declare const infoPlistEntries: (app: ResolvedApp, { development }?: {
|
|
18
20
|
readonly development?: boolean;
|
|
19
21
|
}) => string;
|
|
22
|
+
/**
|
|
23
|
+
* App/AppShortcuts.swift: angular.json's `shortcuts` as App Intents, which is
|
|
24
|
+
* how iOS offers an app's actions to Siri, Spotlight and the Shortcuts app.
|
|
25
|
+
*
|
|
26
|
+
* It's written as source, not read from a file when the app starts, because
|
|
27
|
+
* Xcode's App Intents step reads the titles and phrases out of the compiled
|
|
28
|
+
* code at build time, and takes only literals. Each intent opens the app
|
|
29
|
+
* and leaves its shortcut with ShortcutCenter (ShortcutsModule.swift), where
|
|
30
|
+
* the runtime's LynxShortcuts takes it.
|
|
31
|
+
*
|
|
32
|
+
* The intents are iOS 16's, which is when App Shortcuts arrived, and the
|
|
33
|
+
* shell runs on iOS 15, which gets none. An intent's type name is what iOS
|
|
34
|
+
* stores a saved shortcut under, so it comes from the ID alone.
|
|
35
|
+
*/
|
|
36
|
+
export declare const appShortcutsSwift: (app: ResolvedApp) => string;
|
|
20
37
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAGL,KAAK,WAAW,EAEjB,MAAM,eAAe,CAAC;AAkBvB;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,iBAwC1B,CAAC;AAQF,eAAO,MAAM,QAAQ,GAAI,KAAK,WAAW,KAAG,MAY9B,CAAC;AAEf,mFAAmF;AACnF,eAAO,MAAM,0BAA0B,uDACe,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uEACqC,CAAC;AAEvE,eAAO,MAAM,gBAAgB,GAC3B,KAAK,WAAW,EAChB,kBAAyB;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,KAC/D,MAiFF,CAAC;AAoBF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,WAAW,KAAG,MAwDpD,CAAC"}
|
package/dist/ios/project.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { copyFileSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { readPngSize } from "../png.js";
|
|
4
|
+
import { APP_NAME_PLACEHOLDER, shortcutIdentifier, } from "../options.js";
|
|
4
5
|
import { PERMISSION_MAP } from "../permissions.js";
|
|
6
|
+
import { IOS_IMAGE_SET, writeIosSplash } from "../splash.js";
|
|
5
7
|
import { escapeXml, replaceMarker } from "../xml.js";
|
|
6
8
|
const ORIENTATIONS = {
|
|
7
9
|
portrait: ['UIInterfaceOrientationPortrait'],
|
|
@@ -17,14 +19,21 @@ const ORIENTATIONS = {
|
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
19
21
|
* Writes the app options into the iOS template: build settings go in
|
|
20
|
-
* Config/App.xcconfig (which App.xcodeproj reads),
|
|
21
|
-
* between the template's `angular-lynx:info` markers
|
|
22
|
+
* Config/App.xcconfig (which App.xcodeproj reads), Info.plist entries go
|
|
23
|
+
* between the template's `angular-lynx:info` markers, the shortcuts
|
|
24
|
+
* become App/AppShortcuts.swift, and the icon and the splash go in the asset
|
|
25
|
+
* catalog.
|
|
22
26
|
*/
|
|
23
27
|
export const iosGenerator = {
|
|
24
28
|
configure: (dir, app, projectRoot, development = false) => {
|
|
25
29
|
writeFileSync(path.join(dir, 'Config/App.xcconfig'), xcconfig(app));
|
|
26
30
|
const plistPath = path.join(dir, 'App/Info.plist');
|
|
27
31
|
writeFileSync(plistPath, replaceMarker(readFileSync(plistPath, 'utf8'), 'info', infoPlistEntries(app, { development })));
|
|
32
|
+
// The project compiles every Swift file in App/, so the file only has to
|
|
33
|
+
// be there. An app without shortcuts gets none, and declares no intents.
|
|
34
|
+
if (app.shortcuts.length > 0) {
|
|
35
|
+
writeFileSync(path.join(dir, 'App/AppShortcuts.swift'), appShortcutsSwift(app));
|
|
36
|
+
}
|
|
28
37
|
if (app.icon) {
|
|
29
38
|
const icon = path.resolve(projectRoot, app.icon);
|
|
30
39
|
const size = readPngSize(icon);
|
|
@@ -33,6 +42,7 @@ export const iosGenerator = {
|
|
|
33
42
|
}
|
|
34
43
|
copyFileSync(icon, path.join(dir, 'App/Assets.xcassets/AppIcon.appiconset/AppIcon.png'));
|
|
35
44
|
}
|
|
45
|
+
writeIosSplash(dir, app, projectRoot);
|
|
36
46
|
},
|
|
37
47
|
bundleDir: (dir) => path.join(dir, 'LynxBundle'),
|
|
38
48
|
};
|
|
@@ -66,6 +76,13 @@ export const infoPlistEntries = (app, { development = false } = {}) => {
|
|
|
66
76
|
values.forEach((value) => lines.push(`\t<string>${escapeXml(value)}</string>`));
|
|
67
77
|
lines.push('</array>');
|
|
68
78
|
};
|
|
79
|
+
// The launch screen: angular.json's splash, its color (LaunchBackground,
|
|
80
|
+
// white by default) and its image, if it has one, centered on the whole
|
|
81
|
+
// screen. LynxViewController draws the same over the app until the app
|
|
82
|
+
// hides it (SplashScreen.swift).
|
|
83
|
+
lines.push('<key>UILaunchScreen</key>', '<dict>', '\t<key>UIColorName</key>', '\t<string>LaunchBackground</string>', ...(app.splash.light.image
|
|
84
|
+
? ['\t<key>UIImageName</key>', `\t<string>${IOS_IMAGE_SET}</string>`]
|
|
85
|
+
: []), '</dict>');
|
|
69
86
|
array('UISupportedInterfaceOrientations', ORIENTATIONS[app.orientation]);
|
|
70
87
|
// Read by LynxViewController, which lays the LynxView out over the whole
|
|
71
88
|
// screen or inside the safe area.
|
|
@@ -100,3 +117,83 @@ export const infoPlistEntries = (app, { development = false } = {}) => {
|
|
|
100
117
|
}
|
|
101
118
|
return lines.join('\n');
|
|
102
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Text as the inside of a Swift string literal.
|
|
122
|
+
*/
|
|
123
|
+
const swiftString = (text) => text.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
124
|
+
/**
|
|
125
|
+
* A shortcut's phrase as a Swift string literal, with the app's name as the
|
|
126
|
+
* interpolation App Intents reads it from: Siri then hears the name the
|
|
127
|
+
* person knows the app by, and the names in Info.plist's
|
|
128
|
+
* INAlternativeAppNames.
|
|
129
|
+
*/
|
|
130
|
+
const swiftPhrase = (phrase) => `"${phrase
|
|
131
|
+
.split(APP_NAME_PLACEHOLDER)
|
|
132
|
+
.map(swiftString)
|
|
133
|
+
.join('\\(.applicationName)')}"`;
|
|
134
|
+
/**
|
|
135
|
+
* App/AppShortcuts.swift: angular.json's `shortcuts` as App Intents, which is
|
|
136
|
+
* how iOS offers an app's actions to Siri, Spotlight and the Shortcuts app.
|
|
137
|
+
*
|
|
138
|
+
* It's written as source, not read from a file when the app starts, because
|
|
139
|
+
* Xcode's App Intents step reads the titles and phrases out of the compiled
|
|
140
|
+
* code at build time, and takes only literals. Each intent opens the app
|
|
141
|
+
* and leaves its shortcut with ShortcutCenter (ShortcutsModule.swift), where
|
|
142
|
+
* the runtime's LynxShortcuts takes it.
|
|
143
|
+
*
|
|
144
|
+
* The intents are iOS 16's, which is when App Shortcuts arrived, and the
|
|
145
|
+
* shell runs on iOS 15, which gets none. An intent's type name is what iOS
|
|
146
|
+
* stores a saved shortcut under, so it comes from the ID alone.
|
|
147
|
+
*/
|
|
148
|
+
export const appShortcutsSwift = (app) => {
|
|
149
|
+
const intents = app.shortcuts.map((shortcut) => {
|
|
150
|
+
const route = shortcut.route === undefined
|
|
151
|
+
? ''
|
|
152
|
+
: `, route: "${swiftString(shortcut.route)}"`;
|
|
153
|
+
return [
|
|
154
|
+
'@available(iOS 16.0, *)',
|
|
155
|
+
`struct Shortcut_${shortcutIdentifier(shortcut.id)}: AppIntent {`,
|
|
156
|
+
` static let title: LocalizedStringResource = "${swiftString(shortcut.title)}"`,
|
|
157
|
+
' // The app handles it, so it comes to the front: iOS 26 and later read',
|
|
158
|
+
' // supportedModes, and earlier ones openAppWhenRun.',
|
|
159
|
+
' static let openAppWhenRun = true',
|
|
160
|
+
' @available(iOS 26.0, *)',
|
|
161
|
+
' static var supportedModes: IntentModes { .foreground }',
|
|
162
|
+
'',
|
|
163
|
+
' func perform() async throws -> some IntentResult {',
|
|
164
|
+
` ShortcutCenter.shared.run(id: "${swiftString(shortcut.id)}"${route})`,
|
|
165
|
+
' return .result()',
|
|
166
|
+
' }',
|
|
167
|
+
'}',
|
|
168
|
+
].join('\n');
|
|
169
|
+
});
|
|
170
|
+
const shortcuts = app.shortcuts.map((shortcut) => [
|
|
171
|
+
' AppShortcut(',
|
|
172
|
+
` intent: Shortcut_${shortcutIdentifier(shortcut.id)}(),`,
|
|
173
|
+
' phrases: [',
|
|
174
|
+
...shortcut.phrases.map((phrase) => ` ${swiftPhrase(phrase)},`),
|
|
175
|
+
' ],',
|
|
176
|
+
` shortTitle: "${swiftString(shortcut.title)}"${shortcut.symbol === undefined ? '' : ','}`,
|
|
177
|
+
...(shortcut.symbol === undefined
|
|
178
|
+
? []
|
|
179
|
+
: [` systemImageName: "${shortcut.symbol}"`]),
|
|
180
|
+
' )',
|
|
181
|
+
].join('\n'));
|
|
182
|
+
return [
|
|
183
|
+
'// Written by @blotch/angular-lynx-native from the shortcuts in',
|
|
184
|
+
"// angular.json's builder options on every build. Edits here are",
|
|
185
|
+
'// overwritten; change angular.json instead (or eject).',
|
|
186
|
+
'import AppIntents',
|
|
187
|
+
'',
|
|
188
|
+
intents.join('\n\n'),
|
|
189
|
+
'',
|
|
190
|
+
"/// What iOS reads the app's shortcuts from: there is one provider per app.",
|
|
191
|
+
'@available(iOS 16.0, *)',
|
|
192
|
+
'struct AngularLynxAppShortcuts: AppShortcutsProvider {',
|
|
193
|
+
' static var appShortcuts: [AppShortcut] {',
|
|
194
|
+
shortcuts.join('\n'),
|
|
195
|
+
' }',
|
|
196
|
+
'}',
|
|
197
|
+
'',
|
|
198
|
+
].join('\n');
|
|
199
|
+
};
|