craft-native 0.0.345 → 0.0.346
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.
|
@@ -16,6 +16,9 @@ import android.graphics.Bitmap
|
|
|
16
16
|
import android.graphics.BitmapFactory
|
|
17
17
|
import android.os.Build
|
|
18
18
|
import android.net.Uri
|
|
19
|
+
import android.net.ConnectivityManager
|
|
20
|
+
import android.net.Network
|
|
21
|
+
import android.net.NetworkCapabilities
|
|
19
22
|
import android.provider.MediaStore
|
|
20
23
|
import android.util.Base64
|
|
21
24
|
import androidx.core.content.ContextCompat
|
|
@@ -111,13 +114,38 @@ internal class CraftNativeCapabilities(
|
|
|
111
114
|
val videoLimit: Long = 0,
|
|
112
115
|
)
|
|
113
116
|
|
|
117
|
+
private val connectivity = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
|
118
|
+
private val networkWatch = object : ConnectivityManager.NetworkCallback() {
|
|
119
|
+
private fun changed() {
|
|
120
|
+
if (!closed.get()) CraftNativeHub.broadcast("CRAFT_EVENT", JSONObject().put("event", "craftNetworkChange").put("detail", networkStatus()))
|
|
121
|
+
}
|
|
122
|
+
override fun onAvailable(network: Network) = changed()
|
|
123
|
+
override fun onLost(network: Network) = changed()
|
|
124
|
+
override fun onCapabilitiesChanged(network: Network, capabilities: NetworkCapabilities) = changed()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
private fun networkStatus(): JSONObject {
|
|
128
|
+
val capabilities = connectivity.getNetworkCapabilities(connectivity.activeNetwork)
|
|
129
|
+
val connected = capabilities?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) == true
|
|
130
|
+
val type = when {
|
|
131
|
+
!connected -> "none"
|
|
132
|
+
capabilities?.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) == true -> "wifi"
|
|
133
|
+
capabilities?.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) == true -> "cellular"
|
|
134
|
+
capabilities?.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) == true -> "ethernet"
|
|
135
|
+
else -> "unknown"
|
|
136
|
+
}
|
|
137
|
+
return JSONObject().put("isConnected", connected).put("type", type)
|
|
138
|
+
}
|
|
139
|
+
|
|
114
140
|
init {
|
|
141
|
+
connectivity.registerDefaultNetworkCallback(networkWatch)
|
|
115
142
|
restoreNotifications()
|
|
116
143
|
sweepFiles()
|
|
117
144
|
}
|
|
118
145
|
|
|
119
146
|
fun names(): JSONArray = JSONArray().apply {
|
|
120
147
|
listOf("device", "clipboard", "haptics", "storage", "lifecycle", "fetch", "files").forEach(::put)
|
|
148
|
+
put("network")
|
|
121
149
|
put("storageCompareAndSet")
|
|
122
150
|
put("storageSetIfAbsent")
|
|
123
151
|
put("crypto")
|
|
@@ -179,7 +207,9 @@ internal class CraftNativeCapabilities(
|
|
|
179
207
|
"DeepLinks" -> complete(requestToken, deepLinks(method), completion)
|
|
180
208
|
"Notifications" -> notifications(requestToken, method, args, completion)
|
|
181
209
|
"Network" -> {
|
|
182
|
-
if (method
|
|
210
|
+
if (method == "getStatus") {
|
|
211
|
+
complete(requestToken, success(networkStatus()), completion)
|
|
212
|
+
} else if (method != "fetch") {
|
|
183
213
|
complete(requestToken, failure("UNKNOWN_ACTION", "Unsupported Network method"), completion)
|
|
184
214
|
} else networkExecutor.execute {
|
|
185
215
|
complete(requestToken, fetch(requestToken, args), completion)
|
|
@@ -207,6 +237,7 @@ internal class CraftNativeCapabilities(
|
|
|
207
237
|
|
|
208
238
|
fun close() {
|
|
209
239
|
if (!closed.compareAndSet(false, true)) return
|
|
240
|
+
runCatching { connectivity.unregisterNetworkCallback(networkWatch) }
|
|
210
241
|
cancelled.clear()
|
|
211
242
|
if (config.optBoolean("enableBluetooth")) bluetooth.disconnect()
|
|
212
243
|
databaseExecutor.shutdownNow()
|
package/dist/cli.js
CHANGED
|
@@ -3022,7 +3022,7 @@ function pinCraftNativeDependency(packagePath, craftVersion) {
|
|
|
3022
3022
|
`);
|
|
3023
3023
|
}
|
|
3024
3024
|
// package.json
|
|
3025
|
-
var version = "0.0.
|
|
3025
|
+
var version = "0.0.346";
|
|
3026
3026
|
|
|
3027
3027
|
// bin/cli.ts
|
|
3028
3028
|
var spawnedFrom = process6.env[CRAFT_CLI_SPAWN_MARKER];
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -9676,7 +9676,7 @@ final class CraftZigRuntime: NSObject {
|
|
|
9676
9676
|
enum CraftWebServices {
|
|
9677
9677
|
private static var waiting: [String: (Result<Any, CraftNativeActionError>) -> Void] = [:]
|
|
9678
9678
|
/// Coordinator events a native screen hears too.
|
|
9679
|
-
static let forwardedEvents: Set<String> = ["craftLocationUpdate", "craftLocationError", "craftHealthHeartRate", "craftHealthWorkout", "craftMusicChange", "craftHeartRate"]
|
|
9679
|
+
static let forwardedEvents: Set<String> = ["craftNetworkChange", "craftLocationUpdate", "craftLocationError", "craftHealthHeartRate", "craftHealthWorkout", "craftMusicChange", "craftHeartRate"]
|
|
9680
9680
|
static let event = Notification.Name("craftWebServicesEvent")
|
|
9681
9681
|
|
|
9682
9682
|
static var isAvailable: Bool { CraftSwiftShim.coordinator != nil }
|
|
@@ -43,6 +43,7 @@ enum CraftNativeActions {
|
|
|
43
43
|
// `speech`, `audio` (background sound) and `eventStream` (a fetch read
|
|
44
44
|
// as it arrives) need nothing the app has to declare.
|
|
45
45
|
var values = ["device", "clipboard", "haptics", "storage", "lifecycle", "fetch", "dialog", "speech", "audio", "eventStream", "linking", "badge", "animation", "viewFocus", "viewMeasure", "viewReparent", "viewNonModalPresentation", "nativePlatformControls"]
|
|
46
|
+
values.append("network")
|
|
46
47
|
values.append("nativePager")
|
|
47
48
|
values.append("storageCompareAndSet")
|
|
48
49
|
values.append("storageSetIfAbsent")
|
|
@@ -245,6 +246,9 @@ enum CraftNativeActions {
|
|
|
245
246
|
}
|
|
246
247
|
authenticate(requestToken: requestToken, args: args, completion: completion)
|
|
247
248
|
return
|
|
249
|
+
case ("Network", "getStatus"):
|
|
250
|
+
CraftWebServices.perform(action: "getNetworkStatus", body: [:]) { complete(requestToken, $0, completion) }
|
|
251
|
+
return
|
|
248
252
|
case ("Network", "fetch"):
|
|
249
253
|
fetch(requestToken: requestToken, args: args, completion: completion)
|
|
250
254
|
return
|