@tokamakdev/platform-macos-x64 0.1.1-beta.161 → 0.1.1-beta.162

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.
@@ -127,14 +127,16 @@ if [[ "$platform" == macos ]]; then
127
127
  resources_dir=$contents/Resources
128
128
  app_dir=$resources_dir/app
129
129
  icon=${TOKAMAK_MACOS_ICON:-}
130
- app_files=("${TOKAMAK_MACOS_PLIST:-}" "${TOKAMAK_MACOS_ENTITLEMENTS:-}")
130
+ splash=${TOKAMAK_MACOS_SPLASH_WIDTH:-}
131
+ app_files=("${TOKAMAK_MACOS_PLIST:-}" "${TOKAMAK_MACOS_ENTITLEMENTS:-}" "${TOKAMAK_MACOS_SPLASH_IMAGE:-}" "${TOKAMAK_MACOS_SPLASH_IMAGE_DARK:-}")
131
132
  else
132
133
  contents=$bundle
133
134
  executable_dir=$bundle
134
135
  resources_dir=$bundle
135
136
  app_dir=$bundle/app
136
137
  icon=${TOKAMAK_IOS_ICON:-}
137
- app_files=("${TOKAMAK_IOS_PLIST:-}" "${TOKAMAK_IOS_ENTITLEMENTS:-}")
138
+ splash=${TOKAMAK_IOS_SPLASH_WIDTH:-}
139
+ app_files=("${TOKAMAK_IOS_PLIST:-}" "${TOKAMAK_IOS_ENTITLEMENTS:-}" "${TOKAMAK_IOS_SPLASH_IMAGE:-}" "${TOKAMAK_IOS_SPLASH_IMAGE_DARK:-}")
138
140
  fi
139
141
  if [[ -n "$icon" && ! ( -d "$icon" && "$icon" == *.[iI][cC][oO][nN] ) ]]; then
140
142
  echo "$platform.icon must be an Icon Composer .icon package: $icon" >&2
@@ -200,23 +202,34 @@ rm -rf "$bundle"
200
202
  mkdir -p "$executable_dir" "$app_dir" "$output_parent/.tokamak"
201
203
  cp -R "$input/app/." "$app_dir/"
202
204
 
205
+ # The asset catalog holds the app icon and the splash background colour.
206
+ asset_options=()
207
+ asset_inputs=()
208
+ if [[ -n "$splash" ]]; then
209
+ "$apple_tool" splash --platform "$platform" --resources "$resources_dir" --catalog "$temporary/TokamakSplash.xcassets"
210
+ asset_inputs+=("$temporary/TokamakSplash.xcassets")
211
+ fi
203
212
  if [[ -n "$icon" ]]; then
213
+ # actool names the app icon after its package.
214
+ cp -R "$icon" "$temporary/AppIcon.icon"
215
+ asset_options+=(--app-icon AppIcon)
216
+ asset_inputs+=("$temporary/AppIcon.icon")
217
+ fi
218
+ if [[ ${#asset_inputs[@]} -gt 0 ]]; then
204
219
  if [[ "$platform" == macos ]]; then
205
- icon_targets=(--target-device mac)
220
+ asset_targets=(--target-device mac)
206
221
  else
207
- icon_targets=(--target-device iphone --target-device ipad)
222
+ asset_targets=(--target-device iphone --target-device ipad)
208
223
  fi
209
- # actool names the app icon after its package.
210
- cp -R "$icon" "$temporary/AppIcon.icon"
211
224
  xcrun --sdk "$sdk" actool \
212
225
  --compile "$resources_dir" \
213
226
  --platform "$sdk" \
214
227
  --minimum-deployment-target "$minimum" \
215
- --app-icon AppIcon \
216
- "${icon_targets[@]}" \
228
+ ${asset_options[@]+"${asset_options[@]}"} \
229
+ "${asset_targets[@]}" \
217
230
  --output-partial-info-plist "$icon_info_plist" \
218
231
  --output-format human-readable-text \
219
- "$temporary/AppIcon.icon"
232
+ "${asset_inputs[@]}"
220
233
  fi
221
234
 
222
235
  shopt -s nullglob
@@ -14,9 +14,12 @@ private let failurePage =
14
14
 
15
15
  private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDelegate {
16
16
  private let runtime: RuntimeHandle
17
+ /// Called once, when the first navigation finishes or fails.
18
+ private var firstLoad: (() -> Void)?
17
19
 
18
- init(runtime: RuntimeHandle) {
20
+ init(runtime: RuntimeHandle, firstLoad: @escaping () -> Void) {
19
21
  self.runtime = runtime
22
+ self.firstLoad = firstLoad
20
23
  }
21
24
 
22
25
  func webView(
@@ -122,12 +125,31 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
122
125
  }
123
126
  }
124
127
 
128
+ func webView(_ webView: WKWebView, didFinish navigation: WKNavigation?) {
129
+ finishFirstLoad()
130
+ }
131
+
132
+ func webView(
133
+ _ webView: WKWebView,
134
+ didFail navigation: WKNavigation?,
135
+ withError error: Error
136
+ ) {
137
+ print("tokamak WebView navigation failed: \(error)")
138
+ finishFirstLoad()
139
+ }
140
+
125
141
  func webView(
126
142
  _ webView: WKWebView,
127
143
  didFailProvisionalNavigation navigation: WKNavigation?,
128
144
  withError error: Error
129
145
  ) {
130
146
  print("tokamak WebView navigation failed: \(error)")
147
+ finishFirstLoad()
148
+ }
149
+
150
+ private func finishFirstLoad() {
151
+ firstLoad?()
152
+ firstLoad = nil
131
153
  }
132
154
 
133
155
  private func openExternal(_ url: URL) {
@@ -226,14 +248,22 @@ private final class TokamakController {
226
248
  self.app = app
227
249
  }
228
250
 
229
- func start(frame: CGRect, completion: @escaping (WKWebView) -> Void) {
251
+ /// Creates the WebView once the runtime has started, and calls `firstLoad`
252
+ /// once its first page has loaded or failed, or at once with the failure
253
+ /// page.
254
+ func start(
255
+ frame: CGRect,
256
+ firstLoad: @escaping () -> Void,
257
+ completion: @escaping (WKWebView) -> Void
258
+ ) {
230
259
  app.whenStarted { result in
231
260
  switch result {
232
261
  case .success(let runtime):
233
262
  self.runtime = runtime
234
- completion(self.webView(frame: frame, runtime: runtime))
263
+ completion(self.webView(frame: frame, runtime: runtime, firstLoad: firstLoad))
235
264
  case .failure:
236
265
  completion(self.failureWebView(frame: frame))
266
+ firstLoad()
237
267
  }
238
268
  }
239
269
  }
@@ -272,7 +302,11 @@ private final class TokamakController {
272
302
  }.start()
273
303
  }
274
304
 
275
- private func webView(frame: CGRect, runtime: RuntimeHandle) -> WKWebView {
305
+ private func webView(
306
+ frame: CGRect,
307
+ runtime: RuntimeHandle,
308
+ firstLoad: @escaping () -> Void
309
+ ) -> WKWebView {
276
310
  let configuration = WKWebViewConfiguration()
277
311
  let dataStore = WKWebsiteDataStore.default()
278
312
  let port = runtime.port
@@ -286,7 +320,7 @@ private final class TokamakController {
286
320
  #endif
287
321
  configuration.mediaTypesRequiringUserActionForPlayback = []
288
322
 
289
- let navigation = NavigationDelegate(runtime: runtime)
323
+ let navigation = NavigationDelegate(runtime: runtime, firstLoad: firstLoad)
290
324
  self.navigation = navigation
291
325
  let webView = WKWebView(frame: frame, configuration: configuration)
292
326
  #if os(iOS)
@@ -344,10 +378,19 @@ private final class TokamakController {
344
378
  observeVisibility()
345
379
 
346
380
  guard let content = window.contentView else { return }
347
- controller.start(frame: content.bounds) { webView in
348
- webView.autoresizingMask = [.width, .height]
349
- content.addSubview(webView)
381
+ let dark = window.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == .darkAqua
382
+ let splash = TokamakSplash(frame: content.bounds, dark: dark)
383
+ if let splash {
384
+ content.addSubview(splash.view)
350
385
  }
386
+ controller.start(
387
+ frame: content.bounds,
388
+ firstLoad: { splash?.remove() },
389
+ completion: { webView in
390
+ webView.autoresizingMask = [.width, .height]
391
+ content.addSubview(webView, positioned: .below, relativeTo: nil)
392
+ }
393
+ )
351
394
  }
352
395
 
353
396
  func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
@@ -498,11 +541,23 @@ private final class TokamakController {
498
541
  window.makeKeyAndVisible()
499
542
  self.window = window
500
543
 
501
- let controller = TokamakController(app: app)
502
- controller.start(frame: viewController.view.bounds) { webView in
503
- webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
504
- viewController.view.addSubview(webView)
544
+ let view: UIView = viewController.view
545
+ let splash = TokamakSplash(
546
+ frame: view.bounds,
547
+ dark: scene.traitCollection.userInterfaceStyle == .dark
548
+ )
549
+ if let splash {
550
+ view.addSubview(splash.view)
505
551
  }
552
+ let controller = TokamakController(app: app)
553
+ controller.start(
554
+ frame: view.bounds,
555
+ firstLoad: { splash?.remove() },
556
+ completion: { webView in
557
+ webView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
558
+ view.insertSubview(webView, at: 0)
559
+ }
560
+ )
506
561
  self.controller = controller
507
562
  }
508
563
 
@@ -0,0 +1,125 @@
1
+ import Foundation
2
+ import ImageIO
3
+
4
+ #if os(macOS)
5
+ import AppKit
6
+ #else
7
+ import UIKit
8
+ #endif
9
+
10
+ /// The asset catalog colour the build writes from the splash background.
11
+ private let backgroundColorName = "TokamakSplashBackground"
12
+
13
+ /// The app's splash screen: its image centred on its background colour, shown
14
+ /// over the WebView from launch until the app's first page has loaded. The
15
+ /// build names the images and width in Info.plist.
16
+ final class TokamakSplash {
17
+ #if os(macOS)
18
+ let view: NSView
19
+ #else
20
+ let view: UIView
21
+ /// Whether the image's animation stops at its next frame.
22
+ private var stopped = false
23
+ #endif
24
+
25
+ /// The width the image is drawn at, in points.
26
+ private static var width: CGFloat? {
27
+ (Bundle.main.object(forInfoDictionaryKey: "TokamakSplashWidth") as? NSNumber)
28
+ .map { CGFloat($0.doubleValue) }
29
+ }
30
+
31
+ /// The image file for the appearance, if the splash has one.
32
+ private static func imageURL(dark: Bool) -> URL? {
33
+ let key = dark ? "TokamakSplashImageDark" : "TokamakSplashImage"
34
+ return (Bundle.main.object(forInfoDictionaryKey: key) as? String)
35
+ .flatMap { Bundle.main.url(forResource: $0, withExtension: nil) }
36
+ }
37
+
38
+ /// The image's frame: `width` wide at its aspect ratio, centred in `bounds`.
39
+ private static func imageFrame(size: CGSize, width: CGFloat, in bounds: CGRect) -> CGRect {
40
+ let height = size.width > 0 ? width * size.height / size.width : 0
41
+ return CGRect(
42
+ x: bounds.midX - width / 2, y: bounds.midY - height / 2, width: width, height: height
43
+ )
44
+ }
45
+
46
+ #if os(macOS)
47
+ /// The app's splash filling `frame`, in dark mode or not, or nil when the app has none.
48
+ init?(frame: CGRect, dark: Bool) {
49
+ guard let width = Self.width else { return nil }
50
+ view = BackgroundView(frame: frame)
51
+ view.autoresizingMask = [.width, .height]
52
+ view.setAccessibilityElement(false)
53
+ guard let url = Self.imageURL(dark: dark), let image = NSImage(contentsOf: url) else {
54
+ return
55
+ }
56
+ // An image view plays an animated GIF by itself.
57
+ let imageView = NSImageView(
58
+ frame: Self.imageFrame(size: image.size, width: width, in: view.bounds)
59
+ )
60
+ imageView.image = image
61
+ imageView.imageScaling = .scaleProportionallyUpOrDown
62
+ imageView.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
63
+ imageView.setAccessibilityElement(false)
64
+ view.addSubview(imageView)
65
+ }
66
+
67
+ func remove() {
68
+ view.removeFromSuperview()
69
+ }
70
+
71
+ /// A view filled with the splash background in its appearance.
72
+ private final class BackgroundView: NSView {
73
+ override var wantsUpdateLayer: Bool { true }
74
+
75
+ override func updateLayer() {
76
+ layer?.backgroundColor = NSColor(named: backgroundColorName)?.cgColor
77
+ }
78
+ }
79
+ #else
80
+ /// The app's splash filling `frame`, in dark mode or not, or nil when the app has none.
81
+ init?(frame: CGRect, dark: Bool) {
82
+ guard let width = Self.width else { return nil }
83
+ view = UIView(frame: frame)
84
+ view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
85
+ view.backgroundColor = UIColor(named: backgroundColorName)
86
+ view.accessibilityElementsHidden = true
87
+ guard
88
+ let url = Self.imageURL(dark: dark),
89
+ let source = CGImageSourceCreateWithURL(url as CFURL, nil)
90
+ else { return }
91
+ let animated = CGImageSourceGetCount(source) > 1
92
+ // A JPEG's orientation applies through UIImage; a GIF has none.
93
+ let image =
94
+ animated
95
+ ? CGImageSourceCreateImageAtIndex(source, 0, nil).map { UIImage(cgImage: $0) }
96
+ : UIImage(contentsOfFile: url.path)
97
+ guard let image else { return }
98
+ let imageView = UIImageView(
99
+ frame: Self.imageFrame(size: image.size, width: width, in: view.bounds)
100
+ )
101
+ imageView.image = image
102
+ imageView.contentMode = .scaleAspectFit
103
+ imageView.autoresizingMask = [
104
+ .flexibleLeftMargin, .flexibleRightMargin, .flexibleTopMargin, .flexibleBottomMargin,
105
+ ]
106
+ view.addSubview(imageView)
107
+ guard animated else { return }
108
+ // An image view does not play a GIF, so each frame is shown at the
109
+ // file's timing, from the main queue.
110
+ CGAnimateImageAtURLWithBlock(url as CFURL, nil) {
111
+ [weak self, weak imageView] _, frame, stop in
112
+ guard let self, let imageView, !self.stopped else {
113
+ stop.pointee = true
114
+ return
115
+ }
116
+ imageView.image = UIImage(cgImage: frame)
117
+ }
118
+ }
119
+
120
+ func remove() {
121
+ stopped = true
122
+ view.removeFromSuperview()
123
+ }
124
+ #endif
125
+ }
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/macos-x64/tools/tokamak-swift-describe
3
3
  size: 34571400 bytes
4
- sha256: 8666d8d24119446960921ebfb3a903cdb236e8cde565f8961c70bf4cafb637db
4
+ sha256: baf549749a8e44b4ebb2dfafd38aa94b23d184566d5d692ae85b7ca2883c0fe6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-macos-x64",
3
- "version": "0.1.1-beta.161",
3
+ "version": "0.1.1-beta.162",
4
4
  "description": "The tokamak platform pack for macos-x64",
5
5
  "repository": {
6
6
  "type": "git",