@tokamakdev/platform-macos-arm64 0.1.1-beta.139 → 0.1.1-beta.141

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.
@@ -46,6 +46,8 @@ void *tokamak_runtime_start_development(const char *state_dir, const char *host,
46
46
  TokamakPluginHandler plugins,
47
47
  char *error, size_t error_len);
48
48
  uint16_t tokamak_runtime_port(const void *runtime);
49
+ uint16_t tokamak_runtime_await_port_change(const void *runtime, uint16_t known,
50
+ uint64_t timeout_ms);
49
51
  uint16_t tokamak_runtime_restore_gateway(const void *runtime, char *error,
50
52
  size_t error_len);
51
53
  void tokamak_runtime_stop(void *runtime);
@@ -411,6 +411,13 @@ final class RuntimeHandle {
411
411
  tokamak_runtime_port(handle)
412
412
  }
413
413
 
414
+ /// The gateway's port once it differs from `known`, or after `timeout` its
415
+ /// current port. Blocks. The port is 0 once the gateway lost its port and
416
+ /// could not bind another.
417
+ func awaitPortChange(from known: UInt16, timeout: TimeInterval) -> UInt16 {
418
+ tokamak_runtime_await_port_change(handle, known, UInt64(timeout * 1000))
419
+ }
420
+
414
421
  func restoreGateway() throws -> UInt16 {
415
422
  var error = [CChar](repeating: 0, count: 512)
416
423
  let port = error.withUnsafeMutableBufferPointer { error in
@@ -211,6 +211,10 @@ private final class NavigationDelegate: NSObject, WKNavigationDelegate, WKUIDele
211
211
  }
212
212
 
213
213
  private final class TokamakController {
214
+ /// How long each wait for the gateway to move lasts, which bounds how long
215
+ /// a wait outlives its controller.
216
+ private static let portWait: TimeInterval = 60
217
+
214
218
  private let app: TokamakApp
215
219
  private var runtime: RuntimeHandle?
216
220
  private var navigation: NavigationDelegate?
@@ -235,18 +239,39 @@ private final class TokamakController {
235
239
  }
236
240
 
237
241
  func restoreGateway() {
238
- guard let runtime, let dataStore else { return }
242
+ guard let runtime else { return }
239
243
  do {
240
- let port = try runtime.restoreGateway()
241
- guard port != proxyPort else { return }
242
- setProxy(port: port, host: runtime.appHost, dataStore: dataStore)
243
- proxyPort = port
244
- activeWebView?.reload()
244
+ use(port: try runtime.restoreGateway())
245
245
  } catch {
246
246
  print("tokamak gateway could not recover: \(error)")
247
247
  }
248
248
  }
249
249
 
250
+ /// Routes the WebView through the gateway's `port` and loads the app there
251
+ /// again, once the gateway has moved. A gateway without a port leaves the
252
+ /// route on the lost port, where only a server presenting the runtime's
253
+ /// certificate is trusted.
254
+ private func use(port: UInt16) {
255
+ guard let runtime, let dataStore, port != 0, port != proxyPort else { return }
256
+ setProxy(port: port, host: runtime.appHost, dataStore: dataStore)
257
+ proxyPort = port
258
+ activeWebView?.reload()
259
+ }
260
+
261
+ /// Follows the gateway from `port` to each port it moves to, until the
262
+ /// controller is gone.
263
+ private func followGateway(runtime: RuntimeHandle, from port: UInt16) {
264
+ Thread { [weak self] in
265
+ var port = port
266
+ while self != nil {
267
+ let moved = runtime.awaitPortChange(from: port, timeout: Self.portWait)
268
+ guard moved != port else { continue }
269
+ port = moved
270
+ DispatchQueue.main.async { self?.use(port: moved) }
271
+ }
272
+ }.start()
273
+ }
274
+
250
275
  private func webView(frame: CGRect, runtime: RuntimeHandle) -> WKWebView {
251
276
  let configuration = WKWebViewConfiguration()
252
277
  let dataStore = WKWebsiteDataStore.default()
@@ -273,6 +298,7 @@ private final class TokamakController {
273
298
  webView.navigationDelegate = navigation
274
299
  webView.uiDelegate = navigation
275
300
  webView.load(URLRequest(url: URL(string: "https://\(runtime.appHost)/")!))
301
+ followGateway(runtime: runtime, from: port)
276
302
  return webView
277
303
  }
278
304
 
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/macos-arm64/tools/tokamak-swift-describe
3
3
  size: 34569672 bytes
4
- sha256: 049b62dcb8c9b294081644a0c4285824a4bbacf39e20d268dec74362b129b78a
4
+ sha256: a3942eea7ad14c9de9134148df291e2a93cf1f0fa9518b31669622e5507b425f
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-macos-arm64",
3
- "version": "0.1.1-beta.139",
3
+ "version": "0.1.1-beta.141",
4
4
  "description": "The tokamak platform pack for macos-arm64",
5
5
  "repository": {
6
6
  "type": "git",