@tokamakdev/platform-android-arm64 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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/android-arm64/lib/TokamakRuntime/libtokamak.a
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 34943892 bytes
|
|
4
|
+
sha256: 7b9a432c222a974f34900d4051fa8e802483cc30cdc042cd3d65ff6207652ede
|
|
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager
|
|
|
7
7
|
import android.os.SystemClock
|
|
8
8
|
import android.util.Log
|
|
9
9
|
import androidx.lifecycle.DefaultLifecycleObserver
|
|
10
|
+
import androidx.lifecycle.Lifecycle
|
|
10
11
|
import androidx.lifecycle.LifecycleOwner
|
|
11
12
|
import androidx.lifecycle.ProcessLifecycleOwner
|
|
12
13
|
import java.io.File
|
|
@@ -45,9 +46,6 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
45
46
|
/** The running runtime, started on first use. Blocks while it starts. */
|
|
46
47
|
internal val runtime: TokamakRuntime by started
|
|
47
48
|
|
|
48
|
-
/** Whether the app is in the foreground, as the lifecycle last reported. Main thread only. */
|
|
49
|
-
private var foreground = false
|
|
50
|
-
|
|
51
49
|
/** The Worker's calls and subscriptions on the plugins. Main thread only. */
|
|
52
50
|
private val workerRequests by lazy {
|
|
53
51
|
TokamakPluginRequests<Long>(plugins) { id, result -> runtime.reply(id, result.toString()) }
|
|
@@ -98,7 +96,7 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
98
96
|
get() = this@TokamakApplication.activity
|
|
99
97
|
|
|
100
98
|
override val isInForeground: Boolean
|
|
101
|
-
get() =
|
|
99
|
+
get() = this@TokamakApplication.isInForeground
|
|
102
100
|
|
|
103
101
|
override fun requireForegroundActivity(): Activity =
|
|
104
102
|
this@TokamakApplication.requireForegroundActivity()
|
|
@@ -117,7 +115,14 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
117
115
|
|
|
118
116
|
/** The activity to show UI in; throws `NeedsUIError` while the app is in the background. */
|
|
119
117
|
internal fun requireForegroundActivity(): Activity =
|
|
120
|
-
activity?.takeIf {
|
|
118
|
+
activity?.takeIf { isInForeground } ?: throw TokamakPluginError.needsUI()
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Whether the app is in the foreground, as the runtime records it, or until the runtime has
|
|
122
|
+
* started, whether an activity exists to start it in the foreground.
|
|
123
|
+
*/
|
|
124
|
+
private val isInForeground: Boolean
|
|
125
|
+
get() = if (started.isInitialized()) runtime.isForeground else activity != null
|
|
121
126
|
|
|
122
127
|
/**
|
|
123
128
|
* Delivers the event [name] with the JSON [event] to the Worker's listeners and returns their
|
|
@@ -131,12 +136,11 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
131
136
|
|
|
132
137
|
/** Records the app moving into or out of the foreground, once the runtime has started. */
|
|
133
138
|
private fun moved(foreground: Boolean) {
|
|
134
|
-
|
|
135
|
-
if (started.isInitialized()) record(runtime)
|
|
139
|
+
if (started.isInitialized()) record(runtime, foreground)
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
/**
|
|
139
|
-
private fun record(runtime: TokamakRuntime) {
|
|
142
|
+
/** Records [foreground] in [runtime], delivering `resume` or `suspend` when it changed. */
|
|
143
|
+
private fun record(runtime: TokamakRuntime, foreground: Boolean) {
|
|
140
144
|
if (!runtime.setForeground(foreground)) return
|
|
141
145
|
val name = if (foreground) "resume" else "suspend"
|
|
142
146
|
lifecycle.execute {
|
|
@@ -162,7 +166,9 @@ class TokamakApplication : Application(), TokamakPlugins {
|
|
|
162
166
|
} else {
|
|
163
167
|
TokamakRuntime.start(unpackApp(), stateDir(), storageDir(), appHost, startsInForeground, workerPlugins)
|
|
164
168
|
}
|
|
165
|
-
mainExecutor.execute {
|
|
169
|
+
mainExecutor.execute {
|
|
170
|
+
record(runtime, ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED))
|
|
171
|
+
}
|
|
166
172
|
return runtime
|
|
167
173
|
}
|
|
168
174
|
|
|
@@ -36,6 +36,10 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
36
36
|
*/
|
|
37
37
|
fun setForeground(foreground: Boolean): Boolean = nativeSetForeground(handle, foreground)
|
|
38
38
|
|
|
39
|
+
/** Whether the app is in the foreground, as last recorded. */
|
|
40
|
+
val isForeground: Boolean
|
|
41
|
+
get() = nativeIsForeground(handle)
|
|
42
|
+
|
|
39
43
|
/** Passes a plugin's JSON [result] to the Worker's call or subscription [id]. */
|
|
40
44
|
fun reply(id: Long, result: String) = nativeReply(handle, id, result)
|
|
41
45
|
|
|
@@ -112,6 +116,9 @@ internal class TokamakRuntime private constructor(private val handle: Long) {
|
|
|
112
116
|
@JvmStatic
|
|
113
117
|
private external fun nativeSetForeground(handle: Long, foreground: Boolean): Boolean
|
|
114
118
|
|
|
119
|
+
@JvmStatic
|
|
120
|
+
private external fun nativeIsForeground(handle: Long): Boolean
|
|
121
|
+
|
|
115
122
|
@JvmStatic
|
|
116
123
|
private external fun nativeReply(handle: Long, id: Long, result: String)
|
|
117
124
|
|