@moku-labs/native 0.2.2 → 0.3.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/README.md +8 -5
- package/dist/index.cjs +565 -78
- package/dist/index.d.cts +94 -16
- package/dist/index.d.mts +94 -16
- package/dist/index.mjs +565 -78
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -798,6 +798,18 @@ function generateCapabilities(input) {
|
|
|
798
798
|
//#endregion
|
|
799
799
|
//#region src/plugins/project/generators/cargo.ts
|
|
800
800
|
/**
|
|
801
|
+
* The `tauri` crate floor. The `back` capability calls `exit()` and grants
|
|
802
|
+
* `core:app:allow-exit`, and both exist only since tauri 2.12.0. `tauri-build` versions
|
|
803
|
+
* on its own 2.x line, so its floor stays `"2"`.
|
|
804
|
+
*/
|
|
805
|
+
const TAURI_VERSION_FLOOR = "2.12";
|
|
806
|
+
/**
|
|
807
|
+
* The dependencies only an iOS build compiles: the safe-area hook in the generated
|
|
808
|
+
* `lib.rs` reaches WKWebView through `objc2`. A target table, written for every target,
|
|
809
|
+
* so no other target ever builds the crate and the table adds no per-target difference.
|
|
810
|
+
*/
|
|
811
|
+
const IOS_ONLY_DEPENDENCIES = [`[target.'cfg(target_os = "ios")'.dependencies]`, "objc2 = \"0.6\""];
|
|
812
|
+
/**
|
|
801
813
|
* Derives a valid Cargo package name from the app's display name — lowercased,
|
|
802
814
|
* non-alphanumeric runs collapsed to a single hyphen, and guaranteed to start with a
|
|
803
815
|
* letter (Cargo package names must match `[a-z][a-z0-9_-]*`).
|
|
@@ -833,7 +845,8 @@ function crateIdent(packageName) {
|
|
|
833
845
|
* Generates `src-tauri/Cargo.toml` — the package manifest, the `tauri` dependency with
|
|
834
846
|
* every cargo feature the composed capabilities ask for (tray's `tray-icon`; without it
|
|
835
847
|
* the tray API is not compiled in at all), plus one pinned dependency line per resolved
|
|
836
|
-
* capability that ships a real crate. Feature-only rows contribute
|
|
848
|
+
* capability that ships a real crate. Feature-only and permission-only rows contribute
|
|
849
|
+
* no dependency line. The iOS-only `objc2` table closes the file on every target.
|
|
837
850
|
*
|
|
838
851
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
839
852
|
* @returns A single-artifact array for `src-tauri/Cargo.toml`.
|
|
@@ -862,10 +875,12 @@ function generateCargo(input) {
|
|
|
862
875
|
"tauri-build = { version = \"2\", features = [] }",
|
|
863
876
|
"",
|
|
864
877
|
"[dependencies]",
|
|
865
|
-
`tauri = { version = "
|
|
878
|
+
`tauri = { version = "${TAURI_VERSION_FLOOR}", features = [${features}] }`,
|
|
866
879
|
"serde = { version = \"1\", features = [\"derive\"] }",
|
|
867
880
|
"serde_json = \"1\"",
|
|
868
881
|
...pinnedDeps,
|
|
882
|
+
"",
|
|
883
|
+
...IOS_ONLY_DEPENDENCIES,
|
|
869
884
|
""
|
|
870
885
|
].join("\n")
|
|
871
886
|
}];
|
|
@@ -983,14 +998,44 @@ function generateEntitlements(input) {
|
|
|
983
998
|
//#endregion
|
|
984
999
|
//#region src/plugins/project/generators/rust.ts
|
|
985
1000
|
/**
|
|
986
|
-
* @file project plugin generator — main.rs/lib.rs with mobile entry point
|
|
987
|
-
|
|
1001
|
+
* @file project plugin generator — main.rs/lib.rs with mobile entry point, plugin init
|
|
1002
|
+
* lines and the iOS safe-area setup hook.
|
|
1003
|
+
*/
|
|
1004
|
+
/**
|
|
1005
|
+
* `Manager` brings `get_webview_window` into scope. Only the iOS arm of the setup hook
|
|
1006
|
+
* calls it, so the import is iOS-only too: anywhere else it would be an unused import.
|
|
1007
|
+
*/
|
|
1008
|
+
const IOS_MANAGER_IMPORT = ["#[cfg(target_os = \"ios\")]", "use tauri::Manager;"];
|
|
1009
|
+
/**
|
|
1010
|
+
* The safe-area setup hook, as verified on the iOS 26.3 simulator. UIKit shrinks a
|
|
1011
|
+
* WKWebView page by the safe area while its scroll view stays on `.automatic`; `.never`
|
|
1012
|
+
* gives the page the whole screen, and CSS `env(safe-area-inset-*)` still reports the
|
|
1013
|
+
* notch. The `cfg` makes it a no-op off iOS, so `lib.rs` does not differ per target. The
|
|
1014
|
+
* window is tauri's default `main` label: the generated `app.windows` entry carries none.
|
|
1015
|
+
*/
|
|
1016
|
+
const SAFE_AREA_SETUP = [
|
|
1017
|
+
" .setup(|_app| {",
|
|
1018
|
+
" // wry leaves WKWebView's scroll view on .automatic, which shrinks the page by the",
|
|
1019
|
+
" // safe area (tauri-apps/tauri#8166). .never gives the page the full screen.",
|
|
1020
|
+
" #[cfg(target_os = \"ios\")]",
|
|
1021
|
+
" if let Some(window) = _app.get_webview_window(\"main\") {",
|
|
1022
|
+
" window.with_webview(|webview| unsafe {",
|
|
1023
|
+
" use objc2::{msg_send, runtime::AnyObject};",
|
|
1024
|
+
" let wk = &*(webview.inner() as *mut AnyObject);",
|
|
1025
|
+
" let scroll: *mut AnyObject = msg_send![wk, scrollView];",
|
|
1026
|
+
" // UIScrollViewContentInsetAdjustmentNever = 2",
|
|
1027
|
+
" let _: () = msg_send![&*scroll, setContentInsetAdjustmentBehavior: 2isize];",
|
|
1028
|
+
" })?;",
|
|
1029
|
+
" }",
|
|
1030
|
+
" Ok(())",
|
|
1031
|
+
" })"
|
|
1032
|
+
];
|
|
988
1033
|
/**
|
|
989
1034
|
* Generates `src-tauri/src/lib.rs` and `src-tauri/src/main.rs`. `lib.rs` carries the
|
|
990
1035
|
* `#[cfg_attr(mobile, tauri::mobile_entry_point)]`-annotated `run()` with one
|
|
991
1036
|
* `.plugin(...)` init line per resolved capability that has a real Rust init (rows
|
|
992
|
-
* without one, e.g. tray's cargo-feature row, contribute no line)
|
|
993
|
-
* entry point that calls into the lib crate.
|
|
1037
|
+
* without one, e.g. tray's cargo-feature row, contribute no line), then the iOS
|
|
1038
|
+
* safe-area `.setup` hook; `main.rs` is a thin entry point that calls into the lib crate.
|
|
994
1039
|
*
|
|
995
1040
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
996
1041
|
* @returns Artifacts for `src-tauri/src/lib.rs` and `src-tauri/src/main.rs`.
|
|
@@ -1001,11 +1046,15 @@ function generateEntitlements(input) {
|
|
|
1001
1046
|
*/
|
|
1002
1047
|
function generateRust(input) {
|
|
1003
1048
|
const packageIdent = crateIdent(sanitizePackageName(input.global.app.name));
|
|
1049
|
+
const pluginLines = input.capabilities.filter((capability) => Boolean(capability.rustInit)).map((capability) => ` .plugin(${capability.rustInit})`).toSorted();
|
|
1004
1050
|
const library = [
|
|
1051
|
+
...IOS_MANAGER_IMPORT,
|
|
1052
|
+
"",
|
|
1005
1053
|
"#[cfg_attr(mobile, tauri::mobile_entry_point)]",
|
|
1006
1054
|
"pub fn run() {",
|
|
1007
1055
|
" tauri::Builder::default()",
|
|
1008
|
-
...
|
|
1056
|
+
...pluginLines,
|
|
1057
|
+
...SAFE_AREA_SETUP,
|
|
1009
1058
|
" .run(tauri::generate_context!())",
|
|
1010
1059
|
" .expect(\"error while running tauri application\");",
|
|
1011
1060
|
"}",
|
|
@@ -1028,25 +1077,172 @@ function generateRust(input) {
|
|
|
1028
1077
|
}];
|
|
1029
1078
|
}
|
|
1030
1079
|
//#endregion
|
|
1080
|
+
//#region src/plugins/project/orientation.ts
|
|
1081
|
+
const PORTRAIT = "UIInterfaceOrientationPortrait";
|
|
1082
|
+
const PORTRAIT_UPSIDE_DOWN = "UIInterfaceOrientationPortraitUpsideDown";
|
|
1083
|
+
const LANDSCAPE_SIDES = ["UIInterfaceOrientationLandscapeLeft", "UIInterfaceOrientationLandscapeRight"];
|
|
1084
|
+
/**
|
|
1085
|
+
* The iOS orientation lists per lock: the iPhone key, then the `~ipad` override. An iPhone
|
|
1086
|
+
* held portrait never turns upside down; an iPad does, so its portrait list keeps both.
|
|
1087
|
+
*/
|
|
1088
|
+
const IOS_ORIENTATIONS = {
|
|
1089
|
+
portrait: {
|
|
1090
|
+
iphone: [PORTRAIT],
|
|
1091
|
+
ipad: [PORTRAIT, PORTRAIT_UPSIDE_DOWN]
|
|
1092
|
+
},
|
|
1093
|
+
landscape: {
|
|
1094
|
+
iphone: LANDSCAPE_SIDES,
|
|
1095
|
+
ipad: LANDSCAPE_SIDES
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
/**
|
|
1099
|
+
* The Android `screenOrientation` per lock, matching the iOS lists: `portrait` has no
|
|
1100
|
+
* upside-down side, `sensorLandscape` turns between both landscape sides. `any` maps to no
|
|
1101
|
+
* attribute at all, the template's default.
|
|
1102
|
+
*/
|
|
1103
|
+
const ANDROID_SCREEN_ORIENTATION = {
|
|
1104
|
+
portrait: "portrait",
|
|
1105
|
+
landscape: "sensorLandscape",
|
|
1106
|
+
any: void 0
|
|
1107
|
+
};
|
|
1108
|
+
/**
|
|
1109
|
+
* Builds the `Info.ios.plist` entries that lock the iOS orientation. A locked app also
|
|
1110
|
+
* asks for `UIRequiresFullScreen`: App Store review refuses an iPad app that restricts its
|
|
1111
|
+
* orientations without it. `any` and unset add nothing, so the template's default list
|
|
1112
|
+
* (every orientation) stays.
|
|
1113
|
+
*
|
|
1114
|
+
* @param orientation - The configured `app.orientation`, or undefined when unset.
|
|
1115
|
+
* @returns The plist entries, empty when the orientation is not locked.
|
|
1116
|
+
* @example
|
|
1117
|
+
* ```ts
|
|
1118
|
+
* orientationPlist("portrait")[0];
|
|
1119
|
+
* // { key: "UISupportedInterfaceOrientations", value: ["UIInterfaceOrientationPortrait"] }
|
|
1120
|
+
* ```
|
|
1121
|
+
*/
|
|
1122
|
+
function orientationPlist(orientation) {
|
|
1123
|
+
if (orientation === void 0 || orientation === "any") return [];
|
|
1124
|
+
const { iphone, ipad } = IOS_ORIENTATIONS[orientation];
|
|
1125
|
+
return [
|
|
1126
|
+
{
|
|
1127
|
+
key: "UISupportedInterfaceOrientations",
|
|
1128
|
+
value: iphone
|
|
1129
|
+
},
|
|
1130
|
+
{
|
|
1131
|
+
key: "UISupportedInterfaceOrientations~ipad",
|
|
1132
|
+
value: ipad
|
|
1133
|
+
},
|
|
1134
|
+
{
|
|
1135
|
+
key: "UIRequiresFullScreen",
|
|
1136
|
+
value: true
|
|
1137
|
+
}
|
|
1138
|
+
];
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Builds the Android manifest entry for the orientation lock: `android:screenOrientation`
|
|
1142
|
+
* on the main activity. `any` and unset ask for the attribute to be ABSENT rather than
|
|
1143
|
+
* adding nothing, so a lock a previous build wrote into the gen/ tree is removed again.
|
|
1144
|
+
*
|
|
1145
|
+
* @param orientation - The configured `app.orientation`, or undefined when unset.
|
|
1146
|
+
* @returns Exactly one `activity-attribute` entry.
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```ts
|
|
1149
|
+
* orientationManifest("landscape");
|
|
1150
|
+
* // [{ kind: "activity-attribute", name: "android:screenOrientation", value: "sensorLandscape" }]
|
|
1151
|
+
* ```
|
|
1152
|
+
*/
|
|
1153
|
+
function orientationManifest(orientation) {
|
|
1154
|
+
return [{
|
|
1155
|
+
kind: "activity-attribute",
|
|
1156
|
+
name: "android:screenOrientation",
|
|
1157
|
+
value: ANDROID_SCREEN_ORIENTATION[orientation ?? "any"]
|
|
1158
|
+
}];
|
|
1159
|
+
}
|
|
1160
|
+
//#endregion
|
|
1161
|
+
//#region src/plugins/project/xml.ts
|
|
1162
|
+
/**
|
|
1163
|
+
* @file project plugin — XML text escaping, shared by the two XML files this plugin writes
|
|
1164
|
+
* into: the `Info.ios.plist` sidecar and the Android manifest.
|
|
1165
|
+
*/
|
|
1166
|
+
/**
|
|
1167
|
+
* XML's five predefined entities. `&` goes first, so the ampersand of an entity written
|
|
1168
|
+
* by a later step is never escaped a second time.
|
|
1169
|
+
*/
|
|
1170
|
+
const XML_ESCAPES = [
|
|
1171
|
+
[/&/g, "&"],
|
|
1172
|
+
[/</g, "<"],
|
|
1173
|
+
[/>/g, ">"],
|
|
1174
|
+
[/"/g, """],
|
|
1175
|
+
[/'/g, "'"]
|
|
1176
|
+
];
|
|
1177
|
+
/**
|
|
1178
|
+
* Escapes text for an XML element body or a quoted attribute value. A value lands
|
|
1179
|
+
* verbatim in a generated file, where an unescaped `<` or `"` would end the element or
|
|
1180
|
+
* the attribute around it.
|
|
1181
|
+
*
|
|
1182
|
+
* @param text - The raw value.
|
|
1183
|
+
* @returns The value with `& < > " '` written as entities.
|
|
1184
|
+
* @example
|
|
1185
|
+
* ```ts
|
|
1186
|
+
* escapeXml(`Tom & "Jerry"`); // "Tom & "Jerry""
|
|
1187
|
+
* ```
|
|
1188
|
+
*/
|
|
1189
|
+
function escapeXml(text) {
|
|
1190
|
+
let escaped = text;
|
|
1191
|
+
for (const [pattern, entity] of XML_ESCAPES) escaped = escaped.replace(pattern, entity);
|
|
1192
|
+
return escaped;
|
|
1193
|
+
}
|
|
1194
|
+
//#endregion
|
|
1031
1195
|
//#region src/plugins/project/generators/sidecar.ts
|
|
1032
1196
|
/**
|
|
1033
|
-
*
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
*
|
|
1037
|
-
*
|
|
1197
|
+
* @file project plugin generator — Info.ios.plist sidecar (src-tauri root, outside gen/).
|
|
1198
|
+
*/
|
|
1199
|
+
/**
|
|
1200
|
+
* Renders one plist value as the lines that follow its `<key>`: a `<string>`, a
|
|
1201
|
+
* `<true/>`/`<false/>`, or an `<array>` of strings. Every text is XML-escaped.
|
|
1202
|
+
*
|
|
1203
|
+
* @param value - The entry value.
|
|
1204
|
+
* @returns The value's lines, indented for the top-level `<dict>`.
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```ts
|
|
1207
|
+
* renderPlistValue(["UIInterfaceOrientationPortrait"]);
|
|
1208
|
+
* // [" <array>", " <string>UIInterfaceOrientationPortrait</string>", " </array>"]
|
|
1209
|
+
* ```
|
|
1210
|
+
*/
|
|
1211
|
+
function renderPlistValue(value) {
|
|
1212
|
+
if (typeof value === "boolean") return [value ? " <true/>" : " <false/>"];
|
|
1213
|
+
if (typeof value === "string") return [` <string>${escapeXml(value)}</string>`];
|
|
1214
|
+
return [
|
|
1215
|
+
" <array>",
|
|
1216
|
+
...value.map((item) => ` <string>${escapeXml(item)}</string>`),
|
|
1217
|
+
" </array>"
|
|
1218
|
+
];
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Generates the `Info.ios.plist` SIDECAR at the src-tauri root, which Tauri merges into the
|
|
1222
|
+
* app's Info.plist on every iOS build. Its entries are every resolved capability's
|
|
1223
|
+
* `sidecarPlist`, then the orientation lock (`app.orientation`); on a duplicate key the
|
|
1224
|
+
* later entry wins, so orientation beats a capability.
|
|
1225
|
+
*
|
|
1226
|
+
* On iOS the file is ALWAYS written, as an empty `<dict>` when nothing contributes a key:
|
|
1227
|
+
* the writer never deletes a file, and a portrait lock left in a stale sidecar would keep
|
|
1228
|
+
* being merged after the app went back to `any`. Every other target gets no artifact.
|
|
1038
1229
|
*
|
|
1039
1230
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
1040
|
-
* @returns An artifact for `src-tauri/Info.ios.plist`
|
|
1041
|
-
* carries sidecar entries, otherwise an empty array.
|
|
1231
|
+
* @returns An artifact for `src-tauri/Info.ios.plist` on iOS, otherwise an empty array.
|
|
1042
1232
|
* @example
|
|
1043
1233
|
* ```ts
|
|
1044
|
-
*
|
|
1234
|
+
* // `config` is any full native Config
|
|
1235
|
+
* const global = { ...config, app: { name: "Demo", identifier: "com.acme.demo", orientation: "portrait" } };
|
|
1236
|
+
* generateSidecar({ global, target: "ios", capabilities: [] })[0]?.path; // "src-tauri/Info.ios.plist"
|
|
1237
|
+
* // its <dict>: UISupportedInterfaceOrientations, UISupportedInterfaceOrientations~ipad, UIRequiresFullScreen
|
|
1238
|
+
* generateSidecar({ global, target: "macos", capabilities: [] }); // []
|
|
1045
1239
|
* ```
|
|
1046
1240
|
*/
|
|
1047
1241
|
function generateSidecar(input) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1242
|
+
if (input.target !== "ios") return [];
|
|
1243
|
+
const entries = /* @__PURE__ */ new Map();
|
|
1244
|
+
const contributed = [...input.capabilities.flatMap((capability) => capability.sidecarPlist), ...orientationPlist(input.global.app.orientation)];
|
|
1245
|
+
for (const entry of contributed) entries.set(entry.key, entry.value);
|
|
1050
1246
|
return [{
|
|
1051
1247
|
path: "src-tauri/Info.ios.plist",
|
|
1052
1248
|
content: [
|
|
@@ -1054,7 +1250,7 @@ function generateSidecar(input) {
|
|
|
1054
1250
|
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
|
|
1055
1251
|
"<plist version=\"1.0\">",
|
|
1056
1252
|
"<dict>",
|
|
1057
|
-
entries.
|
|
1253
|
+
...[...entries].flatMap(([key, value]) => [` <key>${escapeXml(key)}</key>`, ...renderPlistValue(value)]),
|
|
1058
1254
|
"</dict>",
|
|
1059
1255
|
"</plist>",
|
|
1060
1256
|
""
|
|
@@ -1158,7 +1354,8 @@ function buildPlugins(capabilities) {
|
|
|
1158
1354
|
}
|
|
1159
1355
|
/**
|
|
1160
1356
|
* Generates `src-tauri/tauri.conf.json` — app identity, the web build/dev wiring, the
|
|
1161
|
-
*
|
|
1357
|
+
* main window (its title, plus `app.backgroundColor` when set), the bundle/signing
|
|
1358
|
+
* metadata, and a `plugins.<name>` block per CONFIGURED capability (see
|
|
1162
1359
|
* {@link buildPlugins}; this is where deep-link's scheme rides — per D-011/D-012 the whole
|
|
1163
1360
|
* v1 mobile-permission story is conf-only). Both path-shaped fields are rebased onto
|
|
1164
1361
|
* `src-tauri`, which is where Tauri resolves them from, and the before-commands carry an
|
|
@@ -1190,7 +1387,10 @@ function generateTauriConf(input) {
|
|
|
1190
1387
|
devUrl: global.web.devUrl,
|
|
1191
1388
|
frontendDist: relativeToTauriRoot(global.projectDir, node_path.default.resolve(webRoot, global.web.dist))
|
|
1192
1389
|
},
|
|
1193
|
-
app: { windows: [{
|
|
1390
|
+
app: { windows: [{
|
|
1391
|
+
title: global.app.name,
|
|
1392
|
+
...compact([["backgroundColor", global.app.backgroundColor]])
|
|
1393
|
+
}] },
|
|
1194
1394
|
bundle: buildBundle(input),
|
|
1195
1395
|
plugins: buildPlugins(capabilities)
|
|
1196
1396
|
};
|
|
@@ -1489,6 +1689,222 @@ async function writeIfChanged(filePath, content, projectDirectory) {
|
|
|
1489
1689
|
return "written";
|
|
1490
1690
|
}
|
|
1491
1691
|
//#endregion
|
|
1692
|
+
//#region src/plugins/project/mobile/manifest.ts
|
|
1693
|
+
/**
|
|
1694
|
+
* @file project plugin — the Android manifest patch. Tauri has no config key for what the
|
|
1695
|
+
* main activity carries (`android:screenOrientation` among them), so the mobile patch pass
|
|
1696
|
+
* sets those attributes on the `<activity>` of the generated
|
|
1697
|
+
* `gen/android/app/src/main/AndroidManifest.xml` itself.
|
|
1698
|
+
*
|
|
1699
|
+
* The transform is a pure text function: only the touched attribute changes, every other
|
|
1700
|
+
* byte (line endings and indentation included) survives, and a second pass is a no-op.
|
|
1701
|
+
*/
|
|
1702
|
+
/** Where `tauri android init` writes the app manifest, below `gen/android`. */
|
|
1703
|
+
const MANIFEST_PATH_SEGMENTS = [
|
|
1704
|
+
"app",
|
|
1705
|
+
"src",
|
|
1706
|
+
"main",
|
|
1707
|
+
"AndroidManifest.xml"
|
|
1708
|
+
];
|
|
1709
|
+
/** The tag name an activity start tag opens with. */
|
|
1710
|
+
const ACTIVITY_OPEN = "<activity";
|
|
1711
|
+
/** The end tag that closes an activity's body. */
|
|
1712
|
+
const ACTIVITY_CLOSE = "</activity>";
|
|
1713
|
+
/** The intent action that marks the launcher activity. */
|
|
1714
|
+
const MAIN_ACTION = "android.intent.action.MAIN";
|
|
1715
|
+
/** Where an `<activity` start tag opens — `<activity-alias` is a different element. */
|
|
1716
|
+
const ACTIVITY_OPEN_PATTERN = /<activity(?=[\s/>])/g;
|
|
1717
|
+
/**
|
|
1718
|
+
* One attribute inside a start tag, from the whitespace character before it:
|
|
1719
|
+
* ` (name)="value"`. XML allows spaces around `=`, but no generated manifest writes them.
|
|
1720
|
+
*/
|
|
1721
|
+
const ATTRIBUTE_PATTERN = /\s([\w:.-]+)=(?:"[^"]*"|'[^']*')/g;
|
|
1722
|
+
/** An XML comment — blanked before the scan, so a commented-out activity never counts. */
|
|
1723
|
+
const COMMENT_PATTERN = /<!--[\s\S]*?-->/g;
|
|
1724
|
+
/**
|
|
1725
|
+
* Builds the `[native]` error for a manifest whose main activity cannot be told apart.
|
|
1726
|
+
*
|
|
1727
|
+
* @param manifestPath - The manifest that was searched.
|
|
1728
|
+
* @returns A formatted `[native] ...` error.
|
|
1729
|
+
* @example
|
|
1730
|
+
* ```ts
|
|
1731
|
+
* throw mainActivityError("/repo/.moku/tauri/src-tauri/gen/android/app/src/main/AndroidManifest.xml");
|
|
1732
|
+
* ```
|
|
1733
|
+
*/
|
|
1734
|
+
function mainActivityError(manifestPath) {
|
|
1735
|
+
return /* @__PURE__ */ new Error(`[native] Could not find the main <activity> in ${manifestPath}.\n Re-run the mobile init pass (tauri android init) or report the manifest Tauri generated.`);
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Finds where a start tag ends. A quoted attribute value is skipped whole, so a `>` inside
|
|
1739
|
+
* one never ends the tag.
|
|
1740
|
+
*
|
|
1741
|
+
* @param text - The manifest content.
|
|
1742
|
+
* @param from - Offset just past the tag name.
|
|
1743
|
+
* @returns The offset just past the closing `>`, or undefined for a tag that never closes.
|
|
1744
|
+
* @example
|
|
1745
|
+
* ```ts
|
|
1746
|
+
* startTagEnd('<activity android:label="a > b">', 9); // 32
|
|
1747
|
+
* ```
|
|
1748
|
+
*/
|
|
1749
|
+
function startTagEnd(text, from) {
|
|
1750
|
+
let quote;
|
|
1751
|
+
for (let index = from; index < text.length; index += 1) {
|
|
1752
|
+
const character = text[index];
|
|
1753
|
+
if (quote !== void 0) {
|
|
1754
|
+
if (character === quote) quote = void 0;
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
if (character === "\"" || character === "'") {
|
|
1758
|
+
quote = character;
|
|
1759
|
+
continue;
|
|
1760
|
+
}
|
|
1761
|
+
if (character === ">") return index + 1;
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* Locates every `<activity>` start tag and records whether its body declares MAIN.
|
|
1766
|
+
* Comments are blanked out first (same length, so every offset still points into the real
|
|
1767
|
+
* text), which keeps a commented-out activity from being counted or patched. A start tag
|
|
1768
|
+
* that never closes is not counted at all.
|
|
1769
|
+
*
|
|
1770
|
+
* @param text - The manifest content.
|
|
1771
|
+
* @returns One entry per activity, in file order.
|
|
1772
|
+
* @example
|
|
1773
|
+
* ```ts
|
|
1774
|
+
* locateActivities('<activity android:name=".A" /><activity android:name=".B"><action android:name="android.intent.action.MAIN" /></activity>');
|
|
1775
|
+
* // [{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: true }]
|
|
1776
|
+
* ```
|
|
1777
|
+
*/
|
|
1778
|
+
function locateActivities(text) {
|
|
1779
|
+
const masked = text.replaceAll(COMMENT_PATTERN, (comment) => " ".repeat(comment.length));
|
|
1780
|
+
const activities = [];
|
|
1781
|
+
for (const match of masked.matchAll(ACTIVITY_OPEN_PATTERN)) {
|
|
1782
|
+
const start = match.index;
|
|
1783
|
+
const end = startTagEnd(masked, start + 9);
|
|
1784
|
+
if (end === void 0) continue;
|
|
1785
|
+
const body = masked.slice(start, end).endsWith("/>") ? "" : masked.slice(end, masked.indexOf(ACTIVITY_CLOSE, end));
|
|
1786
|
+
activities.push({
|
|
1787
|
+
start,
|
|
1788
|
+
end,
|
|
1789
|
+
isMain: body.includes(MAIN_ACTION)
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
return activities;
|
|
1793
|
+
}
|
|
1794
|
+
/**
|
|
1795
|
+
* Picks the main activity: the one whose body declares MAIN. A manifest with a single
|
|
1796
|
+
* activity and no MAIN still has an obvious one; anything else is ambiguous.
|
|
1797
|
+
*
|
|
1798
|
+
* @param activities - Every activity in the manifest.
|
|
1799
|
+
* @returns The main activity, or undefined when none or several qualify.
|
|
1800
|
+
* @example
|
|
1801
|
+
* ```ts
|
|
1802
|
+
* mainActivity([{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: true }]);
|
|
1803
|
+
* // { start: 30, end: 58, isMain: true }
|
|
1804
|
+
* mainActivity([{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: false }]); // undefined
|
|
1805
|
+
* ```
|
|
1806
|
+
*/
|
|
1807
|
+
function mainActivity(activities) {
|
|
1808
|
+
const mains = activities.filter((activity) => activity.isMain);
|
|
1809
|
+
if (mains.length === 1) return mains[0];
|
|
1810
|
+
if (mains.length === 0 && activities.length === 1) return activities[0];
|
|
1811
|
+
}
|
|
1812
|
+
/**
|
|
1813
|
+
* Applies one attribute entry to a start tag. A value replaces the attribute in place, or
|
|
1814
|
+
* is inserted right after `<activity` with the whitespace that already follows it — on the
|
|
1815
|
+
* template's one-attribute-per-line layout that is the line break plus the next
|
|
1816
|
+
* attribute's indentation, CRLF included. An `undefined` value removes the attribute
|
|
1817
|
+
* together with the whitespace before it, which on that layout is its whole line.
|
|
1818
|
+
*
|
|
1819
|
+
* @param tag - The activity start tag.
|
|
1820
|
+
* @param entry - The attribute to set or remove.
|
|
1821
|
+
* @returns The start tag with the entry applied.
|
|
1822
|
+
* @example
|
|
1823
|
+
* ```ts
|
|
1824
|
+
* applyAttribute('<activity android:name=".MainActivity">', portraitEntry);
|
|
1825
|
+
* // '<activity android:screenOrientation="portrait" android:name=".MainActivity">'
|
|
1826
|
+
* ```
|
|
1827
|
+
*/
|
|
1828
|
+
function applyAttribute(tag, entry) {
|
|
1829
|
+
const rendered = entry.value === void 0 ? void 0 : `${entry.name}="${escapeXml(entry.value)}"`;
|
|
1830
|
+
const existing = [...tag.matchAll(ATTRIBUTE_PATTERN)].find((match) => match[1] === entry.name);
|
|
1831
|
+
if (existing) {
|
|
1832
|
+
const before = tag.slice(0, existing.index).trimEnd();
|
|
1833
|
+
const separator = tag.slice(before.length, existing.index + 1);
|
|
1834
|
+
const after = tag.slice(existing.index + existing[0].length);
|
|
1835
|
+
if (rendered === void 0) return `${before}${after}`;
|
|
1836
|
+
return `${before}${separator}${rendered}${after}`;
|
|
1837
|
+
}
|
|
1838
|
+
if (rendered === void 0) return tag;
|
|
1839
|
+
const rest = tag.slice(9);
|
|
1840
|
+
const separator = rest.slice(0, rest.length - rest.trimStart().length) || " ";
|
|
1841
|
+
return `${ACTIVITY_OPEN}${separator}${rendered}${rest}`;
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Applies the `activity-attribute` entries to the main activity of a manifest. `child`
|
|
1845
|
+
* entries are not applied: no registry row carries one, and the official plugins merge
|
|
1846
|
+
* their own manifest needs through build.rs. A pass that only removes attributes leaves a
|
|
1847
|
+
* manifest without a clear main activity as it is.
|
|
1848
|
+
*
|
|
1849
|
+
* @param existing - The current manifest content.
|
|
1850
|
+
* @param entries - The manifest entries to apply, in order (a later one wins).
|
|
1851
|
+
* @param manifestPath - The manifest's path, named in the error.
|
|
1852
|
+
* @returns The manifest with every attribute entry applied.
|
|
1853
|
+
* @throws {Error} `[native]` when an attribute is to be set and the main activity cannot
|
|
1854
|
+
* be told apart.
|
|
1855
|
+
* @example
|
|
1856
|
+
* ```ts
|
|
1857
|
+
* applyManifestEntries('<activity android:name=".Main">\n</activity>', orientationManifest("portrait"), "AndroidManifest.xml");
|
|
1858
|
+
* // '<activity android:screenOrientation="portrait" android:name=".Main">\n</activity>'
|
|
1859
|
+
* ```
|
|
1860
|
+
*/
|
|
1861
|
+
function applyManifestEntries(existing, entries, manifestPath) {
|
|
1862
|
+
const attributes = entries.filter((entry) => entry.kind === "activity-attribute");
|
|
1863
|
+
if (attributes.length === 0) return existing;
|
|
1864
|
+
const activity = mainActivity(locateActivities(existing));
|
|
1865
|
+
if (!activity) {
|
|
1866
|
+
if (attributes.every((attribute) => attribute.value === void 0)) return existing;
|
|
1867
|
+
throw mainActivityError(manifestPath);
|
|
1868
|
+
}
|
|
1869
|
+
let tag = existing.slice(activity.start, activity.end);
|
|
1870
|
+
for (const attribute of attributes) tag = applyAttribute(tag, attribute);
|
|
1871
|
+
return `${existing.slice(0, activity.start)}${tag}${existing.slice(activity.end)}`;
|
|
1872
|
+
}
|
|
1873
|
+
/**
|
|
1874
|
+
* Patches the main activity of `gen/android/app/src/main/AndroidManifest.xml` with the
|
|
1875
|
+
* `activity-attribute` entries, through the write-if-changed writer. Idempotent: a second
|
|
1876
|
+
* pass reports the manifest unchanged. With no attribute entry there is nothing to apply,
|
|
1877
|
+
* and the manifest is not even read.
|
|
1878
|
+
*
|
|
1879
|
+
* @param projectDirectory - The Tauri project root.
|
|
1880
|
+
* @param genDirectory - The `src-tauri/gen/android` directory.
|
|
1881
|
+
* @param entries - The manifest entries to apply.
|
|
1882
|
+
* @returns The manifest path, patched or unchanged.
|
|
1883
|
+
* @throws {Error} `[native]` when the manifest is missing, or an attribute is to be set and
|
|
1884
|
+
* the manifest has no clear main activity.
|
|
1885
|
+
* @example
|
|
1886
|
+
* ```ts
|
|
1887
|
+
* // First pass on a manifest without the lock; a second pass lists it under `unchanged`.
|
|
1888
|
+
* await patchAndroidManifest(".moku/tauri", ".moku/tauri/src-tauri/gen/android", orientationManifest("portrait"));
|
|
1889
|
+
* // { patched: [".moku/tauri/src-tauri/gen/android/app/src/main/AndroidManifest.xml"], unchanged: [] }
|
|
1890
|
+
* ```
|
|
1891
|
+
*/
|
|
1892
|
+
async function patchAndroidManifest(projectDirectory, genDirectory, entries) {
|
|
1893
|
+
if (!entries.some((entry) => entry.kind === "activity-attribute")) return {
|
|
1894
|
+
patched: [],
|
|
1895
|
+
unchanged: []
|
|
1896
|
+
};
|
|
1897
|
+
const manifestPath = node_path.default.join(genDirectory, ...MANIFEST_PATH_SEGMENTS);
|
|
1898
|
+
if (!(0, node_fs.existsSync)(manifestPath)) throw new Error(`[native] AndroidManifest.xml not found at ${manifestPath}.\n Re-run the mobile init pass (tauri android init) before patching the manifest.`);
|
|
1899
|
+
return await writeIfChanged(manifestPath, applyManifestEntries(await (0, node_fs_promises.readFile)(manifestPath, "utf8"), entries, manifestPath), projectDirectory) === "written" ? {
|
|
1900
|
+
patched: [manifestPath],
|
|
1901
|
+
unchanged: []
|
|
1902
|
+
} : {
|
|
1903
|
+
patched: [],
|
|
1904
|
+
unchanged: [manifestPath]
|
|
1905
|
+
};
|
|
1906
|
+
}
|
|
1907
|
+
//#endregion
|
|
1492
1908
|
//#region src/plugins/project/mobile/files.ts
|
|
1493
1909
|
/**
|
|
1494
1910
|
* @file project plugin — the ONE owner of "which generated files a mobile patch pass may
|
|
@@ -1599,12 +2015,25 @@ const WORD_SEPARATOR = String.raw`[ \t]+`;
|
|
|
1599
2015
|
const WORD_BOUNDARY = String.raw`\b`;
|
|
1600
2016
|
/** The already-patched form: the `<node> <tauri.js>` pair, each word quoted. */
|
|
1601
2017
|
const ABSOLUTE_RUNNER_PAIR = `${QUOTED_RUNNER_WORD}${WORD_SEPARATOR}${QUOTED_RUNNER_WORD}`;
|
|
2018
|
+
/** Binaries Tauri may have detected the CLI behind, optionally through an absolute path. */
|
|
2019
|
+
const RUNNER_BINARIES = "node|bunx|bun|npx|yarn|pnpm|cargo";
|
|
2020
|
+
/**
|
|
2021
|
+
* The optional directory a detected runner is path-qualified with (`/opt/homebrew/bin/`).
|
|
2022
|
+
* It never contains a quote or a backslash: those belong to the string literal around the
|
|
2023
|
+
* command (`shellScript = "…`, a Kotlin `"…"`), and eating the opening quote leaves a
|
|
2024
|
+
* pbxproj Xcode refuses to open.
|
|
2025
|
+
*/
|
|
2026
|
+
const RUNNER_PATH_PREFIX = String.raw`(?:[^\s"\\]*/)?`;
|
|
1602
2027
|
/**
|
|
1603
2028
|
* Every runner shape `tauri ios|android init` bakes in: `<binary> tauri`, npm's
|
|
1604
2029
|
* `npm run tauri --` form, or a bare `tauri` — each optionally path-qualified. Longest
|
|
1605
2030
|
* alternative first, so `npm run tauri --` is never truncated to its trailing `tauri`.
|
|
1606
2031
|
*/
|
|
1607
|
-
const PACKAGE_RUNNER =
|
|
2032
|
+
const PACKAGE_RUNNER = [
|
|
2033
|
+
`${RUNNER_PATH_PREFIX}npm run tauri --`,
|
|
2034
|
+
`${RUNNER_PATH_PREFIX}(?:${RUNNER_BINARIES}) tauri`,
|
|
2035
|
+
`${RUNNER_PATH_PREFIX}tauri`
|
|
2036
|
+
].join("|");
|
|
1608
2037
|
/** Characters that would break out of the double-quoted shell word a runner path lands in. */
|
|
1609
2038
|
const SHELL_METACHARACTER_PATTERN = /[\\"$`]/g;
|
|
1610
2039
|
/** A line break inside a runner path would split the generated build phase into two commands. */
|
|
@@ -2253,7 +2682,8 @@ async function patchXcodeSettings(projectDirectory, genDirectory) {
|
|
|
2253
2682
|
/**
|
|
2254
2683
|
* @file project plugin — the post-init mobile patch pass: it decides WHICH patches a
|
|
2255
2684
|
* platform needs and in which order. The patches themselves live next door, in
|
|
2256
|
-
* `signing.ts` (the Android release-signing block), `
|
|
2685
|
+
* `signing.ts` (the Android release-signing block), `manifest.ts` (the Android main
|
|
2686
|
+
* activity's attributes, such as the orientation lock), `runner.ts` (the Xcode /
|
|
2257
2687
|
* Android-Studio runner command) and `xcode-settings.ts` (the iOS
|
|
2258
2688
|
* entitlements-modification setting that makes a REBUILD work).
|
|
2259
2689
|
*/
|
|
@@ -2278,23 +2708,26 @@ function mergePatchResults(...results) {
|
|
|
2278
2708
|
}
|
|
2279
2709
|
/**
|
|
2280
2710
|
* Deterministic, idempotent post-init patch pass over an existing complete gen/ tree.
|
|
2281
|
-
* Android gets its release signing block
|
|
2282
|
-
*
|
|
2283
|
-
*
|
|
2284
|
-
*
|
|
2285
|
-
*
|
|
2711
|
+
* Android gets, in this order, its release signing block, the main activity's manifest
|
|
2712
|
+
* attributes, then the runner command. iOS gets the Xcode entitlements-modification
|
|
2713
|
+
* setting (without it the SECOND build of the same tree fails), then the runner command.
|
|
2714
|
+
* The runner rewrite runs only when the caller supplies a `runner`. iOS takes no manifest
|
|
2715
|
+
* entries: its orientation lock and signing travel through the generated `Info.ios.plist`
|
|
2716
|
+
* sidecar and tauri.conf.json, never through the gen/ tree.
|
|
2286
2717
|
*
|
|
2287
2718
|
* @param projectDirectory - The Tauri project root.
|
|
2288
2719
|
* @param opts - The mobile platform, and optionally the absolute Node/tauri.js runner pair.
|
|
2289
2720
|
* @param signing - The full signing config (only `.android` is consulted).
|
|
2290
|
-
* @
|
|
2291
|
-
* @
|
|
2721
|
+
* @param manifest - Android manifest entries for the main activity (ignored on iOS).
|
|
2722
|
+
* @returns The paths patched vs. left unchanged, one merged report over every patch.
|
|
2723
|
+
* @throws {Error} When the Android `gen/android` tree (or its `app/build.gradle.kts`) is
|
|
2724
|
+
* missing, or manifest entries meet a missing manifest or an unclear main activity.
|
|
2292
2725
|
* @example
|
|
2293
2726
|
* ```ts
|
|
2294
|
-
* await patchMobile("/repo/.moku/tauri", { target: "
|
|
2727
|
+
* await patchMobile("/repo/.moku/tauri", { target: "android", runner }, {}, orientationManifest("portrait"));
|
|
2295
2728
|
* ```
|
|
2296
2729
|
*/
|
|
2297
|
-
async function patchMobile(projectDirectory, opts, signing) {
|
|
2730
|
+
async function patchMobile(projectDirectory, opts, signing, manifest = []) {
|
|
2298
2731
|
const genDirectory = genDirectoryPath(projectDirectory, opts.target);
|
|
2299
2732
|
if (opts.target === "ios") {
|
|
2300
2733
|
if (!(0, node_fs.existsSync)(genDirectory)) return {
|
|
@@ -2310,9 +2743,10 @@ async function patchMobile(projectDirectory, opts, signing) {
|
|
|
2310
2743
|
}
|
|
2311
2744
|
const buildGradlePath = node_path.default.join(genDirectory, "app", "build.gradle.kts");
|
|
2312
2745
|
if (!(0, node_fs.existsSync)(genDirectory) || !(0, node_fs.existsSync)(buildGradlePath)) throw new Error(`[native] Android gen/ tree not found or incomplete at ${genDirectory}.\n Run the mobile init pass (tauri android init) before patching signing state.`);
|
|
2313
|
-
const
|
|
2314
|
-
|
|
2315
|
-
|
|
2746
|
+
const signingResult = await patchAndroidSigning(projectDirectory, genDirectory, signing.android ?? {});
|
|
2747
|
+
const manifestResult = await patchAndroidManifest(projectDirectory, genDirectory, manifest);
|
|
2748
|
+
if (!opts.runner) return mergePatchResults(signingResult, manifestResult);
|
|
2749
|
+
return mergePatchResults(signingResult, manifestResult, await patchRunner(projectDirectory, genDirectory, {
|
|
2316
2750
|
target: opts.target,
|
|
2317
2751
|
runner: opts.runner
|
|
2318
2752
|
}));
|
|
@@ -2320,11 +2754,12 @@ async function patchMobile(projectDirectory, opts, signing) {
|
|
|
2320
2754
|
//#endregion
|
|
2321
2755
|
//#region src/plugins/project/registry.ts
|
|
2322
2756
|
/**
|
|
2323
|
-
* The
|
|
2324
|
-
*
|
|
2325
|
-
*
|
|
2326
|
-
*
|
|
2327
|
-
*
|
|
2757
|
+
* The seven capability registry rows (the first five spike (a), Tauri 2.9.x
|
|
2758
|
+
* source-verified 2026-07-03; `back` and `haptics` against Tauri 2.12.1). Five rows are
|
|
2759
|
+
* backed by a real official Tauri plugin (crate + npm package + Rust init). `tray` is a
|
|
2760
|
+
* core Tauri CARGO FEATURE — it carries no crate, no npm package and no Rust init, only
|
|
2761
|
+
* `cargoFeatures: ["tray-icon"]`, and its `confidence: "low"` flags that divergence.
|
|
2762
|
+
* `back` is core permissions alone: its whole API ships in `@tauri-apps/api/app`.
|
|
2328
2763
|
*/
|
|
2329
2764
|
const REGISTRY = [
|
|
2330
2765
|
{
|
|
@@ -2415,6 +2850,30 @@ const REGISTRY = [
|
|
|
2415
2850
|
"android"
|
|
2416
2851
|
],
|
|
2417
2852
|
confidence: "high"
|
|
2853
|
+
},
|
|
2854
|
+
{
|
|
2855
|
+
name: "back",
|
|
2856
|
+
cargoFeatures: [],
|
|
2857
|
+
permissions: ["core:app:allow-exit"],
|
|
2858
|
+
platforms: ["android"],
|
|
2859
|
+
confidence: "high"
|
|
2860
|
+
},
|
|
2861
|
+
{
|
|
2862
|
+
name: "haptics",
|
|
2863
|
+
npmPackage: "@tauri-apps/plugin-haptics",
|
|
2864
|
+
crate: "tauri-plugin-haptics",
|
|
2865
|
+
crateRange: "^2",
|
|
2866
|
+
npmRange: "^2",
|
|
2867
|
+
rustInit: "tauri_plugin_haptics::init()",
|
|
2868
|
+
cargoFeatures: [],
|
|
2869
|
+
permissions: [
|
|
2870
|
+
"haptics:allow-impact-feedback",
|
|
2871
|
+
"haptics:allow-notification-feedback",
|
|
2872
|
+
"haptics:allow-selection-feedback",
|
|
2873
|
+
"haptics:allow-vibrate"
|
|
2874
|
+
],
|
|
2875
|
+
platforms: ["ios", "android"],
|
|
2876
|
+
confidence: "high"
|
|
2418
2877
|
}
|
|
2419
2878
|
];
|
|
2420
2879
|
const KNOWN_NAMES = REGISTRY.map((row) => row.name);
|
|
@@ -2491,8 +2950,8 @@ function buildConfFragment(row, config) {
|
|
|
2491
2950
|
}
|
|
2492
2951
|
/**
|
|
2493
2952
|
* Typed registry lookup — resolves a capability row against optional consumer config,
|
|
2494
|
-
* producing the full packaging contribution (conf fragment + the
|
|
2495
|
-
*
|
|
2953
|
+
* producing the full packaging contribution (conf fragment + the sidecar/manifest seams,
|
|
2954
|
+
* both empty for every row today).
|
|
2496
2955
|
*
|
|
2497
2956
|
* @param name - A capability name known at compile time (`keyof CapabilityConfigMap`).
|
|
2498
2957
|
* @param config - Optional per-capability packaging parameters.
|
|
@@ -2520,7 +2979,8 @@ function resolve(name, config) {
|
|
|
2520
2979
|
* @returns A fresh copy of every registry row — callers can never mutate the registry.
|
|
2521
2980
|
* @example
|
|
2522
2981
|
* ```ts
|
|
2523
|
-
* registryRows().map(row => row.name);
|
|
2982
|
+
* registryRows().map(row => row.name);
|
|
2983
|
+
* // ["store", "notification", "clipboard-manager", "tray", "deep-link", "back", "haptics"]
|
|
2524
2984
|
* ```
|
|
2525
2985
|
*/
|
|
2526
2986
|
function registryRows() {
|
|
@@ -2556,6 +3016,25 @@ function resolveConfiguredCapabilities(global, target) {
|
|
|
2556
3016
|
return resolved;
|
|
2557
3017
|
}
|
|
2558
3018
|
/**
|
|
3019
|
+
* Collects what the Android main activity must carry: the `activity-attribute` entries of
|
|
3020
|
+
* every capability resolved for android, then the orientation lock. Orientation comes
|
|
3021
|
+
* last so it wins a clash, the same order the iOS sidecar merges in. It is always present:
|
|
3022
|
+
* an unset orientation asks for `android:screenOrientation` to be absent, which removes a
|
|
3023
|
+
* lock a previous build left in the gen/ tree.
|
|
3024
|
+
*
|
|
3025
|
+
* @param global - Frozen global framework config.
|
|
3026
|
+
* @returns The manifest entries for `patchMobile`'s Android pass.
|
|
3027
|
+
* @example
|
|
3028
|
+
* ```ts
|
|
3029
|
+
* // `config` is any full native Config; no registry row carries a manifest entry today
|
|
3030
|
+
* androidManifestEntries({ ...config, app: { name: "Demo", identifier: "com.acme.demo", orientation: "portrait" } });
|
|
3031
|
+
* // [{ kind: "activity-attribute", name: "android:screenOrientation", value: "portrait" }]
|
|
3032
|
+
* ```
|
|
3033
|
+
*/
|
|
3034
|
+
function androidManifestEntries(global) {
|
|
3035
|
+
return [...resolveConfiguredCapabilities(global, "android").flatMap((capability) => capability.manifest).filter((entry) => entry.kind === "activity-attribute"), ...orientationManifest(global.app.orientation)];
|
|
3036
|
+
}
|
|
3037
|
+
/**
|
|
2559
3038
|
* Returns the required-file set a mobile `gen/<platform>` tree must carry — the options
|
|
2560
3039
|
* object keeps every target-scoped API method reading the same way.
|
|
2561
3040
|
*
|
|
@@ -2679,20 +3158,18 @@ function createProjectApi(ctx) {
|
|
|
2679
3158
|
*/
|
|
2680
3159
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
2681
3160
|
/**
|
|
2682
|
-
*
|
|
2683
|
-
* Xcode/Android-Studio runner-command rewrite when a `runner` is supplied.
|
|
3161
|
+
* Implements {@link Api.patchMobile}: hands Android its manifest entries, then logs.
|
|
2684
3162
|
*
|
|
2685
|
-
* @param opts -
|
|
2686
|
-
* @
|
|
2687
|
-
* @param opts.runner - The absolute Node/`tauri.js` pair from `tauri.runner()`.
|
|
2688
|
-
* @returns The paths patched vs. left unchanged.
|
|
3163
|
+
* @param opts - See {@link Api.patchMobile}.
|
|
3164
|
+
* @returns See {@link Api.patchMobile}.
|
|
2689
3165
|
* @example
|
|
2690
3166
|
* ```ts
|
|
2691
|
-
* await runPatchMobile({ target: "ios",
|
|
3167
|
+
* await runPatchMobile({ target: "ios" }); // { patched: [], unchanged: [] } before `tauri ios init`
|
|
2692
3168
|
* ```
|
|
2693
3169
|
*/
|
|
2694
3170
|
const runPatchMobile = async (opts) => {
|
|
2695
|
-
const
|
|
3171
|
+
const manifest = opts.target === "android" ? androidManifestEntries(ctx.global) : [];
|
|
3172
|
+
const result = await patchMobile(ctx.global.projectDir, opts, ctx.global.signing, manifest);
|
|
2696
3173
|
ctx.log.info("project:patchMobile", {
|
|
2697
3174
|
target: opts.target,
|
|
2698
3175
|
patched: result.patched.length
|
|
@@ -2793,6 +3270,10 @@ const BUILD_NUMBER_PATTERN = /^[\w.]+$/;
|
|
|
2793
3270
|
const URL_SCHEME_PATTERN = /^[a-z][a-z\d+.-]*$/i;
|
|
2794
3271
|
/** POSIX environment variable name — lands raw inside a Kotlin `System.getenv("…")` call. */
|
|
2795
3272
|
const ENV_VAR_NAME_PATTERN = /^[a-z_][a-z\d_]*$/i;
|
|
3273
|
+
/** `#rrggbb` or `#rrggbbaa` — the hex forms Tauri parses a window colour from. */
|
|
3274
|
+
const HEX_COLOUR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
3275
|
+
/** The three `Orientation` values — plain-JS config can carry anything else. */
|
|
3276
|
+
const ORIENTATION_PATTERN = /^(?:portrait|landscape|any)$/;
|
|
2796
3277
|
/**
|
|
2797
3278
|
* Validates one free-text config value that is interpolated verbatim into a generated
|
|
2798
3279
|
* file. Every generated format (TOML, Kotlin, plist, XML) has its own escape rules, so a
|
|
@@ -2853,13 +3334,14 @@ function assertDeliveryDirectory(value) {
|
|
|
2853
3334
|
/**
|
|
2854
3335
|
* Validates the global config at composition time — throws `[native]`-formatted errors
|
|
2855
3336
|
* for missing app identity, missing web wiring, values that would break out of the
|
|
2856
|
-
* generated file they are written into, a
|
|
2857
|
-
*
|
|
2858
|
-
* composition missing its
|
|
3337
|
+
* generated file they are written into, a window colour or orientation outside its
|
|
3338
|
+
* allowed shape, a `projectDir` outside the project, an `outDir` this app must not
|
|
3339
|
+
* deliver into, unknown `config.system` names, or a `deep-link` composition missing its
|
|
3340
|
+
* scheme.
|
|
2859
3341
|
*
|
|
2860
3342
|
* @param global - Frozen global framework config.
|
|
2861
|
-
* @throws {Error} When identity, web wiring, interpolated values,
|
|
2862
|
-
* system names, or deep-link config are invalid.
|
|
3343
|
+
* @throws {Error} When identity, web wiring, interpolated values, presentation fields,
|
|
3344
|
+
* derived directories, system names, or deep-link config are invalid.
|
|
2863
3345
|
* @example
|
|
2864
3346
|
* ```ts
|
|
2865
3347
|
* validateProjectConfig(ctx.global);
|
|
@@ -2874,6 +3356,8 @@ function validateProjectConfig(global) {
|
|
|
2874
3356
|
if (!global.web.dist) throw new Error("[native] web.dist is required.\n Set config.web.dist to your web build's output directory.");
|
|
2875
3357
|
assertShape("app.version", global.app.version, VERSION_PATTERN, "semantic version", "Use a MAJOR.MINOR.PATCH version such as \"1.0.0\".");
|
|
2876
3358
|
assertShape("app.buildNumber", global.app.buildNumber, BUILD_NUMBER_PATTERN, "build number", "Use digits, letters, dots or underscores, such as \"42\" or \"1.0.3\".");
|
|
3359
|
+
assertShape("app.backgroundColor", global.app.backgroundColor, HEX_COLOUR_PATTERN, "colour", "Use a hex colour such as \"#10161d\".");
|
|
3360
|
+
assertShape("app.orientation", global.app.orientation, ORIENTATION_PATTERN, "orientation", "Use \"portrait\", \"landscape\" or \"any\".");
|
|
2877
3361
|
assertShape("signing.android.keystorePasswordEnv", global.signing.android?.keystorePasswordEnv, ENV_VAR_NAME_PATTERN, "environment variable name", "Reference the password by variable NAME, such as \"ANDROID_KEYSTORE_PASSWORD\" — never the password itself.");
|
|
2878
3362
|
assertShape("signing.android.keyPasswordEnv", global.signing.android?.keyPasswordEnv, ENV_VAR_NAME_PATTERN, "environment variable name", "Reference the password by variable NAME, such as \"ANDROID_KEY_PASSWORD\" — never the password itself.");
|
|
2879
3363
|
assertDerivedDirectory(global.projectDir);
|
|
@@ -2888,8 +3372,9 @@ function validateProjectConfig(global) {
|
|
|
2888
3372
|
//#region src/plugins/project/index.ts
|
|
2889
3373
|
/**
|
|
2890
3374
|
* Complex tier — capability registry + generators/ + write-if-changed writer + the mobile/
|
|
2891
|
-
* sub-domain (completeness gate, Android signing block,
|
|
2892
|
-
* guarded
|
|
3375
|
+
* sub-domain (completeness gate, Android signing block, Android manifest attributes,
|
|
3376
|
+
* Xcode settings, runner-command rewrite) + the build-time orientation lock + the guarded
|
|
3377
|
+
* clean.
|
|
2893
3378
|
*
|
|
2894
3379
|
* @see README.md
|
|
2895
3380
|
* @example
|
|
@@ -4122,7 +4607,7 @@ function createTauriApi(ctx) {
|
|
|
4122
4607
|
* ```
|
|
4123
4608
|
*/
|
|
4124
4609
|
async function run(cmd, hooks) {
|
|
4125
|
-
const startedAt =
|
|
4610
|
+
const startedAt = performance.now();
|
|
4126
4611
|
/**
|
|
4127
4612
|
* Scrubs one output line, forwards it to the caller's hooks, and parses
|
|
4128
4613
|
* any compile-progress tick out of it.
|
|
@@ -4145,7 +4630,7 @@ function createTauriApi(ctx) {
|
|
|
4145
4630
|
cwd: runCwd(),
|
|
4146
4631
|
onLine: handleLine
|
|
4147
4632
|
});
|
|
4148
|
-
const durationMs =
|
|
4633
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
4149
4634
|
const scrubbedStdout = scrub(result.stdout);
|
|
4150
4635
|
const scrubbedStderr = scrub(result.stderr);
|
|
4151
4636
|
if (result.code !== 0) {
|
|
@@ -4880,7 +5365,7 @@ function emitPhase(ctx, target, phase, status, extra) {
|
|
|
4880
5365
|
*/
|
|
4881
5366
|
async function runCompileAndBundle(ctx, deps, opts) {
|
|
4882
5367
|
const { target } = opts;
|
|
4883
|
-
const startedAt =
|
|
5368
|
+
const startedAt = performance.now();
|
|
4884
5369
|
let transitionAt;
|
|
4885
5370
|
emitPhase(ctx, target, "compile", "start");
|
|
4886
5371
|
try {
|
|
@@ -4919,8 +5404,8 @@ async function runCompileAndBundle(ctx, deps, opts) {
|
|
|
4919
5404
|
onOutput: (line) => {
|
|
4920
5405
|
if (transitionAt !== void 0) return;
|
|
4921
5406
|
if (!BUNDLING_TRANSITION_PATTERN.test(line)) return;
|
|
4922
|
-
transitionAt =
|
|
4923
|
-
emitPhase(ctx, target, "compile", "done", { durationMs: transitionAt - startedAt });
|
|
5407
|
+
transitionAt = performance.now();
|
|
5408
|
+
emitPhase(ctx, target, "compile", "done", { durationMs: Math.round(transitionAt - startedAt) });
|
|
4924
5409
|
emitPhase(ctx, target, "bundle", "start");
|
|
4925
5410
|
}
|
|
4926
5411
|
});
|
|
@@ -4928,14 +5413,14 @@ async function runCompileAndBundle(ctx, deps, opts) {
|
|
|
4928
5413
|
const openPhase = transitionAt === void 0 ? "compile" : "bundle";
|
|
4929
5414
|
const detail = error instanceof Error ? error.message : String(error);
|
|
4930
5415
|
emitPhase(ctx, target, openPhase, "error", {
|
|
4931
|
-
durationMs:
|
|
5416
|
+
durationMs: Math.round(performance.now() - (transitionAt ?? startedAt)),
|
|
4932
5417
|
detail
|
|
4933
5418
|
});
|
|
4934
5419
|
throw error;
|
|
4935
5420
|
}
|
|
4936
|
-
const endedAt =
|
|
5421
|
+
const endedAt = performance.now();
|
|
4937
5422
|
if (transitionAt === void 0) {
|
|
4938
|
-
const compileDurationMs = endedAt - startedAt;
|
|
5423
|
+
const compileDurationMs = Math.round(endedAt - startedAt);
|
|
4939
5424
|
emitPhase(ctx, target, "compile", "done", { durationMs: compileDurationMs });
|
|
4940
5425
|
emitPhase(ctx, target, "bundle", "start");
|
|
4941
5426
|
emitPhase(ctx, target, "bundle", "done", { durationMs: 0 });
|
|
@@ -4944,17 +5429,18 @@ async function runCompileAndBundle(ctx, deps, opts) {
|
|
|
4944
5429
|
bundleDurationMs: 0
|
|
4945
5430
|
};
|
|
4946
5431
|
}
|
|
4947
|
-
const bundleDurationMs = endedAt - transitionAt;
|
|
5432
|
+
const bundleDurationMs = Math.round(endedAt - transitionAt);
|
|
4948
5433
|
emitPhase(ctx, target, "bundle", "done", { durationMs: bundleDurationMs });
|
|
4949
5434
|
return {
|
|
4950
|
-
compileDurationMs: transitionAt - startedAt,
|
|
5435
|
+
compileDurationMs: Math.round(transitionAt - startedAt),
|
|
4951
5436
|
bundleDurationMs
|
|
4952
5437
|
};
|
|
4953
5438
|
}
|
|
4954
5439
|
/**
|
|
4955
5440
|
* Runs one phase generically: emits `native:phase` start/done/error and measures
|
|
4956
|
-
* duration, rethrowing on failure so the caller
|
|
4957
|
-
* v1) — the phase after a failing one is never
|
|
5441
|
+
* duration (monotonic clock, whole milliseconds), rethrowing on failure so the caller
|
|
5442
|
+
* stops the pipeline (no partial-continue, v1) — the phase after a failing one is never
|
|
5443
|
+
* started.
|
|
4958
5444
|
*
|
|
4959
5445
|
* @param ctx - The build pipeline's domain context.
|
|
4960
5446
|
* @param target - The packaging target the phase runs for.
|
|
@@ -4969,11 +5455,11 @@ async function runCompileAndBundle(ctx, deps, opts) {
|
|
|
4969
5455
|
* ```
|
|
4970
5456
|
*/
|
|
4971
5457
|
async function runPhase(ctx, target, phase, run, detailOf) {
|
|
4972
|
-
const startedAt =
|
|
5458
|
+
const startedAt = performance.now();
|
|
4973
5459
|
emitPhase(ctx, target, phase, "start");
|
|
4974
5460
|
try {
|
|
4975
5461
|
const result = await run();
|
|
4976
|
-
const durationMs =
|
|
5462
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
4977
5463
|
const detail = detailOf?.(result);
|
|
4978
5464
|
emitPhase(ctx, target, phase, "done", detail === void 0 ? { durationMs } : {
|
|
4979
5465
|
durationMs,
|
|
@@ -4985,7 +5471,7 @@ async function runPhase(ctx, target, phase, run, detailOf) {
|
|
|
4985
5471
|
};
|
|
4986
5472
|
} catch (error) {
|
|
4987
5473
|
emitPhase(ctx, target, phase, "error", {
|
|
4988
|
-
durationMs:
|
|
5474
|
+
durationMs: Math.round(performance.now() - startedAt),
|
|
4989
5475
|
detail: error instanceof Error ? error.message : String(error)
|
|
4990
5476
|
});
|
|
4991
5477
|
throw error;
|
|
@@ -5042,7 +5528,7 @@ async function runPrepare(ctx, deps, target) {
|
|
|
5042
5528
|
*/
|
|
5043
5529
|
async function runPipeline(ctx, deps, opts) {
|
|
5044
5530
|
const { target } = opts;
|
|
5045
|
-
const startedAt =
|
|
5531
|
+
const startedAt = performance.now();
|
|
5046
5532
|
const phases = [...await runPrepare(ctx, deps, target)];
|
|
5047
5533
|
const { compileDurationMs, bundleDurationMs } = await runCompileAndBundle(ctx, deps, opts);
|
|
5048
5534
|
phases.push({
|
|
@@ -5061,7 +5547,7 @@ async function runPipeline(ctx, deps, opts) {
|
|
|
5061
5547
|
phase: "collect",
|
|
5062
5548
|
durationMs: collect.durationMs
|
|
5063
5549
|
});
|
|
5064
|
-
const durationMs =
|
|
5550
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
5065
5551
|
const { outPath, artifacts } = collect.result;
|
|
5066
5552
|
ctx.emit("native:complete", {
|
|
5067
5553
|
target,
|
|
@@ -7033,8 +7519,9 @@ function createCliHandlers(ctx) {
|
|
|
7033
7519
|
* ```
|
|
7034
7520
|
*/
|
|
7035
7521
|
"native:phase"(payload) {
|
|
7036
|
-
if (payload.status === "start") ctx.state.progress = { startedAt:
|
|
7037
|
-
const
|
|
7522
|
+
if (payload.status === "start") ctx.state.progress = { startedAt: performance.now() };
|
|
7523
|
+
const { startedAt } = ctx.state.progress;
|
|
7524
|
+
const elapsedMs = startedAt === void 0 ? 0 : Math.round(performance.now() - startedAt);
|
|
7038
7525
|
renderPhaseEvent(ui, payload, elapsedMs);
|
|
7039
7526
|
if (payload.status === "done" || payload.status === "error") ctx.state.progress = { startedAt: void 0 };
|
|
7040
7527
|
},
|
|
@@ -7186,10 +7673,10 @@ const cliPlugin = createPlugin$1("cli", {
|
|
|
7186
7673
|
*
|
|
7187
7674
|
* | Field | Type | Default |
|
|
7188
7675
|
* |---|---|---|
|
|
7189
|
-
* | `app` | `{ name; identifier; version?; icon?; category?; buildNumber? }` | `{ name: "", identifier: "" }` — both validated non-empty at composition |
|
|
7676
|
+
* | `app` | `{ name; identifier; version?; icon?; category?; buildNumber?; orientation?; backgroundColor? }` | `{ name: "", identifier: "" }` — both validated non-empty at composition; `orientation` (`"portrait" \| "landscape" \| "any"`) is a build-time mobile lock, `backgroundColor` a hex window colour |
|
|
7190
7677
|
* | `web` | `{ build; devCommand; devUrl; dist; cwd? }` | `"bun run build"`, `"bun run dev"`, `"http://localhost:5173"`, `"dist"` |
|
|
7191
7678
|
* | `system` | `ReadonlyArray<{ name: string }>` | `[]` — the composed `@moku-labs/system` plugins |
|
|
7192
|
-
* | `capabilities` | `Partial<CapabilityConfigMap>` | `{}` |
|
|
7679
|
+
* | `capabilities` | `Partial<CapabilityConfigMap>` | `{}` — keys: `store`, `notification`, `clipboard-manager`, `tray`, `deep-link`, `back`, `haptics` |
|
|
7193
7680
|
* | `targets` | `readonly Target[]` | `hostTargets(process.platform)` — one desktop target, mobile is opt-in |
|
|
7194
7681
|
* | `projectDir` | `string` | `".moku/tauri"` — generated Tauri project (gitignored build output) |
|
|
7195
7682
|
* | `outDir` | `string` | `"dist-native"` — installer delivery root |
|