@tokamakdev/platform-ios-simulator-x64 0.1.1-beta.84 → 0.1.1-beta.86

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.
@@ -50,6 +50,7 @@ bool tokamak_runtime_emit(const void *runtime, const char *name,
50
50
  const char *event, uint64_t timeout_ms,
51
51
  TokamakBytes *reply, char *error, size_t error_len);
52
52
  bool tokamak_runtime_set_foreground(const void *runtime, bool foreground);
53
+ bool tokamak_runtime_is_foreground(const void *runtime);
53
54
  void tokamak_runtime_reply(const void *runtime, uint64_t id, const char *result);
54
55
 
55
56
  int32_t tokamak_runtime_server_authority(const void *runtime, const char *host,
@@ -1,6 +1,5 @@
1
1
  import Foundation
2
2
  import TokamakRuntime
3
- import os
4
3
 
5
4
  #if os(iOS)
6
5
  import UIKit
@@ -34,8 +33,8 @@ final class TokamakApp {
34
33
  /// Delivers `resume` and `suspend` one at a time, in order.
35
34
  private let lifecycle = DispatchQueue(label: "tokamak.lifecycle")
36
35
  #if os(iOS)
37
- /// The scenes in the foreground, which plugins read on any thread.
38
- private let foregroundScenes = OSAllocatedUnfairLock(initialState: 0)
36
+ /// The scenes in the foreground.
37
+ private var foregroundScenes = 0
39
38
  #endif
40
39
 
41
40
  /// Creates the plugins. Call it before launch finishes.
@@ -173,29 +172,31 @@ final class TokamakApp {
173
172
  #if os(iOS)
174
173
  /// Delivers `resume` as the first scene enters the foreground.
175
174
  func sceneWillEnterForeground() {
176
- let first = foregroundScenes.withLock { scenes in
177
- scenes += 1
178
- return scenes == 1
179
- }
180
- if first {
175
+ foregroundScenes += 1
176
+ if foregroundScenes == 1 {
181
177
  moved(toForeground: true)
182
178
  }
183
179
  }
184
180
 
185
181
  /// Delivers `suspend` as the last scene leaves the foreground.
186
182
  func sceneDidEnterBackground() {
187
- let last = foregroundScenes.withLock { scenes in
188
- scenes -= 1
189
- return scenes == 0
190
- }
191
- if last {
183
+ foregroundScenes -= 1
184
+ if foregroundScenes == 0 {
192
185
  moved(toForeground: false)
193
186
  }
194
187
  }
195
188
 
196
- /// Whether a scene is in the foreground. Read it on any thread.
189
+ /// Whether a scene is in the foreground.
190
+ var hasForegroundScene: Bool {
191
+ foregroundScenes > 0
192
+ }
193
+
194
+ /// Whether the app is in the foreground, as the runtime records it, or
195
+ /// until the runtime has started, whether a scene is in the foreground.
196
+ /// Read it on the main thread.
197
197
  var isInForeground: Bool {
198
- foregroundScenes.withLock { $0 > 0 }
198
+ guard case .success(let runtime) = runtime else { return hasForegroundScene }
199
+ return runtime.isForeground
199
200
  }
200
201
  #endif
201
202
 
@@ -422,6 +423,11 @@ final class RuntimeHandle {
422
423
  tokamak_runtime_set_foreground(handle, foreground)
423
424
  }
424
425
 
426
+ /// Whether the app is in the foreground, as last recorded.
427
+ var isForeground: Bool {
428
+ tokamak_runtime_is_foreground(handle)
429
+ }
430
+
425
431
  /// Passes a plugin's `result`, JSON-serialisable, to the Worker's call or
426
432
  /// subscription `id`.
427
433
  func reply(_ id: UInt64, result: [String: Any]) {
@@ -28,9 +28,10 @@ final class TokamakHost {
28
28
  self.plugin = plugin
29
29
  }
30
30
 
31
- /// Throws `NeedsUIError` unless the app can show UI now: on iOS, while a
32
- /// scene is in the foreground. A hidden or minimised macOS app still shows
33
- /// system prompts. Call it where the plugin would show UI, on any thread.
31
+ /// Throws `NeedsUIError` unless the app can show UI now: on iOS, while it
32
+ /// is in the foreground. A hidden or minimised macOS app still shows system
33
+ /// prompts. Call it on the main thread, where the plugin decides to show
34
+ /// UI.
34
35
  func requireUI() throws(TokamakPluginError) {
35
36
  #if os(iOS)
36
37
  guard app.isInForeground else { throw .needsUI }
@@ -431,7 +431,7 @@ private final class TokamakController {
431
431
  didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
432
432
  ) -> Bool {
433
433
  DispatchQueue.main.async {
434
- self.app.start(foreground: self.app.isInForeground)
434
+ self.app.start(foreground: self.app.hasForegroundScene)
435
435
  }
436
436
  return true
437
437
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokamakdev/platform-ios-simulator-x64",
3
- "version": "0.1.1-beta.84",
3
+ "version": "0.1.1-beta.86",
4
4
  "description": "The tokamak platform pack for ios-simulator-x64",
5
5
  "repository": {
6
6
  "type": "git",