@tokamakdev/platform-ios-simulator-arm64 0.1.1-beta.44 → 0.1.1-beta.45

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.
@@ -80,6 +80,7 @@ sign_bundle() {
80
80
  if [[ "$platform" == ios ]]; then
81
81
  signing_args=(
82
82
  sign
83
+ --platform ios
83
84
  --project "$project_dir"
84
85
  --bundle "$bundle"
85
86
  --bundle-id "$identifier"
@@ -88,7 +89,15 @@ sign_bundle() {
88
89
  signing_args+=(--device-id "$(cat "$metadata/device-id")")
89
90
  fi
90
91
  "$apple_tool" "${signing_args[@]}"
92
+ elif [[ "$platform" == macos && -n "${TOKAMAK_MACOS_TEAM_ID:-}" ]]; then
93
+ "$apple_tool" sign \
94
+ --platform macos \
95
+ --project "$project_dir" \
96
+ --bundle "$bundle" \
97
+ --bundle-id "$identifier"
91
98
  else
99
+ # Ad-hoc signatures carry no provisioning profile.
100
+ rm -f "$contents/embedded.provisionprofile"
92
101
  codesign --force --timestamp=none --sign - "$bundle"
93
102
  fi
94
103
  }
@@ -111,7 +120,7 @@ if [[ -f "$metadata/input-key" ]]; then
111
120
  shasum -a 256 "$plist_path"
112
121
  fi
113
122
  env | LC_ALL=C sort | sed -n '/^TOKAMAK_/p' |
114
- sed '/^TOKAMAK_IOS_TEAM_ID=/d; /^TOKAMAK_IOS_SIGNING_IDENTITY=/d; /^TOKAMAK_IOS_PROVISIONING_PROFILE=/d; /^TOKAMAK_IOS_BUILD_NUMBER=/d; /^TOKAMAK_MACOS_BUILD_NUMBER=/d'
123
+ sed '/^TOKAMAK_IOS_TEAM_ID=/d; /^TOKAMAK_IOS_SIGNING_IDENTITY=/d; /^TOKAMAK_IOS_PROVISIONING_PROFILE=/d; /^TOKAMAK_MACOS_TEAM_ID=/d; /^TOKAMAK_IOS_BUILD_NUMBER=/d; /^TOKAMAK_MACOS_BUILD_NUMBER=/d'
115
124
  printf '%s\n' "${DEVELOPER_DIR:-}" "$PATH"
116
125
  xcodebuild -version
117
126
  } | shasum -a 256 | cut -d ' ' -f 1
@@ -213,6 +222,27 @@ for plugin in "$input/plugins"/*; do
213
222
  done
214
223
  done
215
224
 
225
+ # Simulator builds embed application-identifier and keychain-access-groups in
226
+ # __TEXT,__entitlements, where the simulator reads them.
227
+ if [[ "$platform" == ios-simulator ]]; then
228
+ simulator_entitlements=$temporary/simulator.entitlements
229
+ cat > "$simulator_entitlements" <<EOF
230
+ <?xml version="1.0" encoding="UTF-8"?>
231
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
232
+ <plist version="1.0">
233
+ <dict>
234
+ <key>application-identifier</key>
235
+ <string>$identifier</string>
236
+ <key>keychain-access-groups</key>
237
+ <array>
238
+ <string>$identifier</string>
239
+ </array>
240
+ </dict>
241
+ </plist>
242
+ EOF
243
+ swift_args+=(-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker "$simulator_entitlements")
244
+ fi
245
+
216
246
  xcrun --sdk "$sdk" swiftc "${swift_args[@]}" -o "$executable_dir/$app_slug"
217
247
  xcrun --sdk "$sdk" strip "$executable_dir/$app_slug"
218
248
 
@@ -0,0 +1,20 @@
1
+ import Foundation
2
+ import WebKit
3
+
4
+ extension URL {
5
+ /// Whether this URL is on the app origin, `https://<host>`.
6
+ func isAppOrigin(_ host: String) -> Bool {
7
+ scheme?.caseInsensitiveCompare("https") == .orderedSame
8
+ && self.host?.caseInsensitiveCompare(host) == .orderedSame
9
+ && (port == nil || port == 443)
10
+ }
11
+ }
12
+
13
+ extension WKSecurityOrigin {
14
+ /// Whether this is the app origin, `https://<host>`.
15
+ func isAppOrigin(_ host: String) -> Bool {
16
+ self.protocol.caseInsensitiveCompare("https") == .orderedSame
17
+ && self.host.caseInsensitiveCompare(host) == .orderedSame
18
+ && (port == 0 || port == 443)
19
+ }
20
+ }
@@ -91,12 +91,9 @@ final class TokamakPluginBridge: NSObject, WKScriptMessageHandler {
91
91
  _ userContentController: WKUserContentController,
92
92
  didReceive message: WKScriptMessage
93
93
  ) {
94
- let origin = message.frameInfo.securityOrigin
95
94
  guard
96
95
  message.frameInfo.isMainFrame,
97
- origin.protocol == "https",
98
- origin.host == host,
99
- origin.port == 0 || origin.port == 443,
96
+ message.frameInfo.securityOrigin.isAppOrigin(host),
100
97
  let encoded = message.body as? String,
101
98
  let data = encoded.data(using: .utf8),
102
99
  let request = try? JSONSerialization.jsonObject(with: data)
@@ -160,10 +157,21 @@ final class TokamakPluginBridge: NSObject, WKScriptMessageHandler {
160
157
  }
161
158
  }
162
159
 
160
+ /// Plugins reply from any thread; delivery happens on the main thread.
163
161
  private func send(
164
162
  key: RequestKey,
165
163
  result: Result<Any?, TokamakPluginError>,
166
164
  done: Bool
165
+ ) {
166
+ DispatchQueue.main.async { [weak self] in
167
+ self?.deliver(key: key, result: result, done: done)
168
+ }
169
+ }
170
+
171
+ private func deliver(
172
+ key: RequestKey,
173
+ result: Result<Any?, TokamakPluginError>,
174
+ done: Bool
167
175
  ) {
168
176
  if done {
169
177
  cancellations.removeValue(forKey: key)?()
@@ -182,23 +190,12 @@ final class TokamakPluginBridge: NSObject, WKScriptMessageHandler {
182
190
  guard
183
191
  JSONSerialization.isValidJSONObject(response),
184
192
  let data = try? JSONSerialization.data(withJSONObject: response),
185
- let json = String(data: data, encoding: .utf8)
193
+ let json = String(data: data, encoding: .utf8),
194
+ webView?.url?.isAppOrigin(host) == true
186
195
  else {
187
196
  return
188
197
  }
189
- DispatchQueue.main.async { [weak self] in
190
- guard
191
- let self,
192
- self.webView?.url?.scheme == "https",
193
- self.webView?.url?.host == self.host,
194
- self.webView?.url?.port == nil || self.webView?.url?.port == 443
195
- else {
196
- return
197
- }
198
- self.webView?.evaluateJavaScript(
199
- "globalThis.__tokamakReceive?.(\(json))"
200
- )
201
- }
198
+ webView?.evaluateJavaScript("globalThis.__tokamakReceive?.(\(json))")
202
199
  }
203
200
 
204
201
  private static func bootstrap(host: String) -> String {
@@ -239,7 +239,7 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
239
239
  return
240
240
  }
241
241
 
242
- if isAppOrigin(url) {
242
+ if url.isAppOrigin(runtime.host) {
243
243
  if navigationAction.targetFrame == nil {
244
244
  webView.load(navigationAction.request)
245
245
  decisionHandler(.cancel)
@@ -266,7 +266,7 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
266
266
  return
267
267
  }
268
268
 
269
- if isAppOrigin(url) {
269
+ if url.isAppOrigin(runtime.host) {
270
270
  decisionHandler(.allow)
271
271
  } else {
272
272
  openExternal(url)
@@ -282,7 +282,7 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
282
282
  ) -> WKWebView? {
283
283
  _ = (configuration, windowFeatures)
284
284
  guard let url = navigationAction.request.url else { return nil }
285
- if isAppOrigin(url) {
285
+ if url.isAppOrigin(runtime.host) {
286
286
  webView.load(navigationAction.request)
287
287
  } else {
288
288
  openExternal(url)
@@ -290,6 +290,18 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
290
290
  return nil
291
291
  }
292
292
 
293
+ /// The app's own usage descriptions cover its origin; other origins keep
294
+ /// WebKit's prompt.
295
+ func webView(
296
+ _ webView: WKWebView,
297
+ requestMediaCapturePermissionFor origin: WKSecurityOrigin,
298
+ initiatedByFrame frame: WKFrameInfo,
299
+ type: WKMediaCaptureType,
300
+ decisionHandler: @escaping (WKPermissionDecision) -> Void
301
+ ) {
302
+ decisionHandler(origin.isAppOrigin(runtime.host) ? .grant : .prompt)
303
+ }
304
+
293
305
  func webView(
294
306
  _ webView: WKWebView,
295
307
  didReceive challenge: URLAuthenticationChallenge,
@@ -328,16 +340,6 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
328
340
  print("tokamak WebView navigation failed: \(error)")
329
341
  }
330
342
 
331
- private func isAppOrigin(_ url: URL) -> Bool {
332
- guard
333
- url.scheme?.caseInsensitiveCompare("https") == .orderedSame,
334
- url.host?.caseInsensitiveCompare(runtime.host) == .orderedSame
335
- else {
336
- return false
337
- }
338
- return url.port == nil || url.port == 443
339
- }
340
-
341
343
  private func openExternal(_ url: URL) {
342
344
  #if os(iOS)
343
345
  UIApplication.shared.open(url)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-ios-simulator-arm64",
3
- "version": "0.1.1-beta.44",
3
+ "version": "0.1.1-beta.45",
4
4
  "description": "The tokamak platform pack for ios-simulator-arm64",
5
5
  "repository": {
6
6
  "type": "git",