@tokamakdev/platform-macos-x64 0.1.1-beta.140 → 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.
- package/macos-x64/frameworks/TokamakRuntime.framework/Headers/TokamakRuntime.h +2 -0
- package/macos-x64/frameworks/TokamakRuntime.framework/TokamakRuntime +0 -0
- package/macos-x64/native-shell/TokamakApp.swift +7 -0
- package/macos-x64/native-shell/TokamakShell.swift +32 -6
- package/macos-x64/tools/tokamak-swift-describe +1 -1
- package/package.json +1 -1
|
@@ -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);
|
|
Binary file
|
|
@@ -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
|
|
242
|
+
guard let runtime else { return }
|
|
239
243
|
do {
|
|
240
|
-
|
|
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-x64/tools/tokamak-swift-describe
|
|
3
3
|
size: 34569672 bytes
|
|
4
|
-
sha256:
|
|
4
|
+
sha256: 396abdf0db6c9f228219776a0818c4fb3e4c4a3dbc718668646487b3f80a894c
|