@onekeyfe/react-native-device-utils 1.1.19 → 1.1.21
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/ReactNativeDeviceUtils.podspec +1 -0
- package/android/build.gradle +5 -0
- package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +153 -8
- package/ios/ReactNativeDeviceUtils.swift +109 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +22 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JGooglePlayServicesStatus.hpp +61 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +145 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +9 -0
- package/nitrogen/generated/android/c++/JLaunchOptions.hpp +62 -0
- package/nitrogen/generated/android/c++/JWebViewPackageInfo.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/GooglePlayServicesStatus.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/LaunchOptions.kt +41 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/WebViewPackageInfo.kt +44 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +48 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +305 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +81 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_GooglePlayServicesStatus.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_LaunchOptions.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_WebViewPackageInfo.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +47 -0
- package/nitrogen/generated/ios/swift/GooglePlayServicesStatus.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +9 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +163 -0
- package/nitrogen/generated/ios/swift/LaunchOptions.swift +66 -0
- package/nitrogen/generated/ios/swift/WebViewPackageInfo.swift +58 -0
- package/nitrogen/generated/shared/c++/GooglePlayServicesStatus.hpp +79 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +9 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +19 -0
- package/nitrogen/generated/shared/c++/LaunchOptions.hpp +80 -0
- package/nitrogen/generated/shared/c++/WebViewPackageInfo.hpp +83 -0
- package/package.json +1 -1
- package/src/ReactNativeDeviceUtils.nitro.ts +31 -0
package/android/build.gradle
CHANGED
|
@@ -133,4 +133,9 @@ dependencies {
|
|
|
133
133
|
implementation "androidx.appcompat:appcompat:1.7.1"
|
|
134
134
|
// AndroidX Preference for PreferenceManager
|
|
135
135
|
implementation "androidx.preference:preference-ktx:1.2.1"
|
|
136
|
+
|
|
137
|
+
implementation project(":onekeyfe_react-native-native-logger")
|
|
138
|
+
|
|
139
|
+
// Google Play Services for availability check
|
|
140
|
+
implementation "com.google.android.gms:play-services-base:18.5.0"
|
|
136
141
|
}
|
package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt
CHANGED
|
@@ -6,7 +6,7 @@ import android.content.pm.PackageManager
|
|
|
6
6
|
import android.graphics.Color
|
|
7
7
|
import android.graphics.Rect
|
|
8
8
|
import android.os.Build
|
|
9
|
-
import
|
|
9
|
+
import com.margelo.nitro.nativelogger.OneKeyLog
|
|
10
10
|
import androidx.preference.PreferenceManager
|
|
11
11
|
import androidx.core.content.ContextCompat
|
|
12
12
|
import androidx.core.util.Consumer
|
|
@@ -38,6 +38,15 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
38
38
|
companion object {
|
|
39
39
|
private const val PREF_KEY_FOLDABLE = "1k_fold"
|
|
40
40
|
private const val PREF_KEY_UI_STYLE = "1k_user_interface_style"
|
|
41
|
+
private const val PREF_KEY_DEVICE_TOKEN = "1k_device_token"
|
|
42
|
+
|
|
43
|
+
@JvmStatic
|
|
44
|
+
var staticStartupTime: Long? = null
|
|
45
|
+
|
|
46
|
+
@JvmStatic
|
|
47
|
+
fun saveStartupTimeStatic(startupTime: Long) {
|
|
48
|
+
staticStartupTime = startupTime
|
|
49
|
+
}
|
|
41
50
|
|
|
42
51
|
// Xiaomi foldable models
|
|
43
52
|
private val XIAOMI_FOLDABLE_MODELS = setOf(
|
|
@@ -216,7 +225,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
216
225
|
)
|
|
217
226
|
}
|
|
218
227
|
|
|
219
|
-
private var windowLayoutInfo: WindowLayoutInfo? = null
|
|
228
|
+
@Volatile private var windowLayoutInfo: WindowLayoutInfo? = null
|
|
220
229
|
private var isSpanning = false
|
|
221
230
|
private var layoutInfoConsumer: Consumer<WindowLayoutInfo>? = null
|
|
222
231
|
private var windowInfoTracker: WindowInfoTracker? = null
|
|
@@ -237,10 +246,14 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
237
246
|
try {
|
|
238
247
|
val context = NitroModules.applicationContext ?: return
|
|
239
248
|
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
240
|
-
val style = prefs.getString(PREF_KEY_UI_STYLE, null) ?:
|
|
249
|
+
val style = prefs.getString(PREF_KEY_UI_STYLE, null) ?: run {
|
|
250
|
+
OneKeyLog.debug("DeviceUtils", "No saved UI style found")
|
|
251
|
+
return
|
|
252
|
+
}
|
|
253
|
+
OneKeyLog.info("DeviceUtils", "Restored UI style: $style")
|
|
241
254
|
applyUserInterfaceStyle(style)
|
|
242
255
|
} catch (e: Exception) {
|
|
243
|
-
|
|
256
|
+
OneKeyLog.warn("DeviceUtils", "Failed to restore UI style: ${e.message}")
|
|
244
257
|
}
|
|
245
258
|
}
|
|
246
259
|
|
|
@@ -284,6 +297,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
284
297
|
saveFoldableStatus(true)
|
|
285
298
|
}
|
|
286
299
|
isDualScreenDeviceDetected = hasFolding
|
|
300
|
+
OneKeyLog.info("DeviceUtils", "Foldable detected: $hasFolding (${Build.MANUFACTURER} ${Build.MODEL})")
|
|
287
301
|
return isDualScreenDeviceDetected!!
|
|
288
302
|
}
|
|
289
303
|
isDualScreenDeviceDetected = false
|
|
@@ -576,7 +590,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
576
590
|
// Check device model name to determine if it's a foldable device
|
|
577
591
|
return isFoldableDeviceByName()
|
|
578
592
|
} catch (e: Exception) {
|
|
579
|
-
|
|
593
|
+
OneKeyLog.warn("DeviceUtils", "Foldable detection failed: ${e.message}")
|
|
580
594
|
return false
|
|
581
595
|
}
|
|
582
596
|
}
|
|
@@ -705,7 +719,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
705
719
|
try {
|
|
706
720
|
listener.callback(isSpanning)
|
|
707
721
|
} catch (e: Exception) {
|
|
708
|
-
|
|
722
|
+
OneKeyLog.error("DeviceUtils", "Error in spanning listener callback: ${e.message}")
|
|
709
723
|
}
|
|
710
724
|
}
|
|
711
725
|
}
|
|
@@ -754,7 +768,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
754
768
|
layoutInfoConsumer!!
|
|
755
769
|
)
|
|
756
770
|
} catch (e: Exception) {
|
|
757
|
-
|
|
771
|
+
OneKeyLog.warn("DeviceUtils", "Window tracking setup failed: ${e.message}")
|
|
758
772
|
}
|
|
759
773
|
}
|
|
760
774
|
}
|
|
@@ -787,6 +801,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
787
801
|
|
|
788
802
|
// Emit event if spanning state changed
|
|
789
803
|
if (wasSpanning != this.isSpanning) {
|
|
804
|
+
OneKeyLog.info("DeviceUtils", "Spanning state changed: $wasSpanning -> ${this.isSpanning}")
|
|
790
805
|
this.callSpanningChangedListeners(this.isSpanning)
|
|
791
806
|
}
|
|
792
807
|
}
|
|
@@ -799,6 +814,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
799
814
|
UserInterfaceStyle.DARK -> "dark"
|
|
800
815
|
UserInterfaceStyle.UNSPECIFIED -> "unspecified"
|
|
801
816
|
}
|
|
817
|
+
OneKeyLog.info("DeviceUtils", "Set UI style: $styleString")
|
|
802
818
|
try {
|
|
803
819
|
val context = NitroModules.applicationContext
|
|
804
820
|
if (context != null) {
|
|
@@ -826,7 +842,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
826
842
|
val rootView = activity.window.decorView
|
|
827
843
|
rootView.rootView.setBackgroundColor(Color.argb(alpha, red, green, blue))
|
|
828
844
|
} catch (e: Exception) {
|
|
829
|
-
e.
|
|
845
|
+
OneKeyLog.error("DeviceUtils", "Failed to change background color: ${e.message}")
|
|
830
846
|
}
|
|
831
847
|
}
|
|
832
848
|
}
|
|
@@ -842,4 +858,133 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
842
858
|
override fun onHostDestroy() {
|
|
843
859
|
stopObservingLayoutChanges()
|
|
844
860
|
}
|
|
861
|
+
|
|
862
|
+
// MARK: - LaunchOptionsManager
|
|
863
|
+
|
|
864
|
+
override fun getLaunchOptions(): Promise<LaunchOptions> {
|
|
865
|
+
return Promise.async {
|
|
866
|
+
OneKeyLog.debug("DeviceUtils", "getLaunchOptions")
|
|
867
|
+
LaunchOptions(launchType = "normal", deepLink = null)
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
override fun clearLaunchOptions(): Promise<Boolean> {
|
|
872
|
+
return Promise.async {
|
|
873
|
+
OneKeyLog.info("DeviceUtils", "clearLaunchOptions")
|
|
874
|
+
true
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
override fun getDeviceToken(): Promise<String> {
|
|
879
|
+
return Promise.async {
|
|
880
|
+
val context = NitroModules.applicationContext ?: return@async ""
|
|
881
|
+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
882
|
+
prefs.getString(PREF_KEY_DEVICE_TOKEN, "") ?: ""
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
override fun saveDeviceToken(token: String): Promise<Unit> {
|
|
887
|
+
return Promise.async {
|
|
888
|
+
val context = NitroModules.applicationContext
|
|
889
|
+
if (context != null) {
|
|
890
|
+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
891
|
+
prefs.edit().putString(PREF_KEY_DEVICE_TOKEN, token).apply()
|
|
892
|
+
}
|
|
893
|
+
OneKeyLog.info("DeviceUtils", "saveDeviceToken: token saved")
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
override fun registerDeviceToken(): Promise<Boolean> {
|
|
898
|
+
return Promise.async { true }
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
override fun getStartupTime(): Promise<Double> {
|
|
902
|
+
return Promise.async {
|
|
903
|
+
(staticStartupTime ?: 0L).toDouble()
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
// MARK: - ExitModule
|
|
908
|
+
|
|
909
|
+
override fun exitApp() {
|
|
910
|
+
OneKeyLog.info("DeviceUtils", "exitApp")
|
|
911
|
+
android.os.Process.killProcess(android.os.Process.myPid())
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// MARK: - WebView & Play Services
|
|
915
|
+
|
|
916
|
+
override fun getCurrentWebViewPackageInfo(): Promise<WebViewPackageInfo> {
|
|
917
|
+
return Promise.async {
|
|
918
|
+
val context = NitroModules.applicationContext
|
|
919
|
+
?: throw Exception("Application context unavailable")
|
|
920
|
+
|
|
921
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
922
|
+
val webViewPackage = android.webkit.WebView.getCurrentWebViewPackage()
|
|
923
|
+
if (webViewPackage != null) {
|
|
924
|
+
OneKeyLog.info(
|
|
925
|
+
"DeviceUtils",
|
|
926
|
+
"WebView: ${webViewPackage.packageName} ${webViewPackage.versionName} ${webViewPackage.versionCode}"
|
|
927
|
+
)
|
|
928
|
+
return@async WebViewPackageInfo(
|
|
929
|
+
packageName = webViewPackage.packageName,
|
|
930
|
+
versionName = webViewPackage.versionName ?: "",
|
|
931
|
+
versionCode = webViewPackage.versionCode.toLong().toDouble()
|
|
932
|
+
)
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Fallback for API < 26: try common WebView package names
|
|
937
|
+
val pm = context.packageManager
|
|
938
|
+
val candidates = listOf(
|
|
939
|
+
"com.google.android.webview",
|
|
940
|
+
"com.android.webview",
|
|
941
|
+
"com.android.chrome"
|
|
942
|
+
)
|
|
943
|
+
for (candidate in candidates) {
|
|
944
|
+
try {
|
|
945
|
+
val pInfo = pm.getPackageInfo(candidate, 0)
|
|
946
|
+
OneKeyLog.info(
|
|
947
|
+
"DeviceUtils",
|
|
948
|
+
"WebView (fallback): ${pInfo.packageName} ${pInfo.versionName} ${pInfo.versionCode}"
|
|
949
|
+
)
|
|
950
|
+
return@async WebViewPackageInfo(
|
|
951
|
+
packageName = pInfo.packageName,
|
|
952
|
+
versionName = pInfo.versionName ?: "",
|
|
953
|
+
versionCode = pInfo.versionCode.toDouble()
|
|
954
|
+
)
|
|
955
|
+
} catch (_: Exception) {
|
|
956
|
+
// Try next candidate
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
throw Exception("No WebView package found")
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
override fun isGooglePlayServicesAvailable(): Promise<GooglePlayServicesStatus> {
|
|
964
|
+
return Promise.async {
|
|
965
|
+
val context = NitroModules.applicationContext
|
|
966
|
+
?: throw Exception("Application context unavailable")
|
|
967
|
+
try {
|
|
968
|
+
val googleApiAvailability =
|
|
969
|
+
com.google.android.gms.common.GoogleApiAvailability.getInstance()
|
|
970
|
+
val status = googleApiAvailability.isGooglePlayServicesAvailable(context)
|
|
971
|
+
val isSuccess =
|
|
972
|
+
status == com.google.android.gms.common.ConnectionResult.SUCCESS
|
|
973
|
+
OneKeyLog.info(
|
|
974
|
+
"DeviceUtils",
|
|
975
|
+
"Play Services status=$status isAvailable=$isSuccess"
|
|
976
|
+
)
|
|
977
|
+
GooglePlayServicesStatus(
|
|
978
|
+
status = status.toDouble(),
|
|
979
|
+
isAvailable = isSuccess
|
|
980
|
+
)
|
|
981
|
+
} catch (e: Exception) {
|
|
982
|
+
OneKeyLog.error(
|
|
983
|
+
"DeviceUtils",
|
|
984
|
+
"Play Services check failed: ${e.message}"
|
|
985
|
+
)
|
|
986
|
+
GooglePlayServicesStatus(status = -1.0, isAvailable = false)
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
845
990
|
}
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import NitroModules
|
|
2
2
|
import UIKit
|
|
3
|
+
import ReactNativeNativeLogger
|
|
4
|
+
|
|
5
|
+
@objcMembers
|
|
6
|
+
public class LaunchOptionsStore: NSObject {
|
|
7
|
+
public static let shared = LaunchOptionsStore()
|
|
8
|
+
|
|
9
|
+
public var launchOptions: [AnyHashable: Any]?
|
|
10
|
+
public var deviceToken: Data?
|
|
11
|
+
public var startupTime: TimeInterval = 0
|
|
12
|
+
|
|
13
|
+
private static let deviceTokenKey = "1k_device_token"
|
|
14
|
+
|
|
15
|
+
public func getDeviceTokenString() -> String {
|
|
16
|
+
// Prefer the JS-saved token (persisted across launches)
|
|
17
|
+
if let saved = UserDefaults.standard.string(forKey: LaunchOptionsStore.deviceTokenKey), !saved.isEmpty {
|
|
18
|
+
return saved
|
|
19
|
+
}
|
|
20
|
+
// Fall back to the native APNs token set by AppDelegate
|
|
21
|
+
guard let token = deviceToken else { return "" }
|
|
22
|
+
return token.map { String(format: "%02.2hhx", $0) }.joined()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public func saveDeviceToken(_ token: String) {
|
|
26
|
+
UserDefaults.standard.set(token, forKey: LaunchOptionsStore.deviceTokenKey)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
3
29
|
|
|
4
30
|
class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
5
31
|
|
|
@@ -12,8 +38,10 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
12
38
|
|
|
13
39
|
private func restoreUserInterfaceStyle() {
|
|
14
40
|
guard let style = UserDefaults.standard.string(forKey: ReactNativeDeviceUtils.userInterfaceStyleKey) else {
|
|
41
|
+
OneKeyLog.debug("DeviceUtils", "No saved UI style found")
|
|
15
42
|
return
|
|
16
43
|
}
|
|
44
|
+
OneKeyLog.info("DeviceUtils", "Restored UI style: \(style)")
|
|
17
45
|
applyUserInterfaceStyle(style)
|
|
18
46
|
}
|
|
19
47
|
|
|
@@ -70,6 +98,7 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
70
98
|
|
|
71
99
|
|
|
72
100
|
public func setUserInterfaceStyle(style: UserInterfaceStyle) throws -> Void {
|
|
101
|
+
OneKeyLog.info("DeviceUtils", "Set UI style: \(style.stringValue)")
|
|
73
102
|
UserDefaults.standard.set(style.stringValue, forKey: ReactNativeDeviceUtils.userInterfaceStyleKey)
|
|
74
103
|
applyUserInterfaceStyle(style.stringValue)
|
|
75
104
|
}
|
|
@@ -91,4 +120,84 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
91
120
|
}
|
|
92
121
|
}
|
|
93
122
|
}
|
|
123
|
+
|
|
124
|
+
// MARK: - LaunchOptionsManager
|
|
125
|
+
|
|
126
|
+
func getLaunchOptions() throws -> Promise<LaunchOptions> {
|
|
127
|
+
return Promise.async {
|
|
128
|
+
let store = LaunchOptionsStore.shared
|
|
129
|
+
guard let opts = store.launchOptions else {
|
|
130
|
+
OneKeyLog.debug("DeviceUtils", "getLaunchOptions: no launch options")
|
|
131
|
+
return LaunchOptions(launchType: "normal", deepLink: nil)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if opts[UIApplication.LaunchOptionsKey.remoteNotification] != nil {
|
|
135
|
+
return LaunchOptions(launchType: "remoteNotification", deepLink: nil)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if opts[UIApplication.LaunchOptionsKey.localNotification] != nil {
|
|
139
|
+
return LaunchOptions(launchType: "localNotification", deepLink: nil)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let deepLink = (opts[UIApplication.LaunchOptionsKey.url] as? URL)?.absoluteString
|
|
143
|
+
return LaunchOptions(launchType: "normal", deepLink: deepLink)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
func clearLaunchOptions() throws -> Promise<Bool> {
|
|
148
|
+
return Promise.async {
|
|
149
|
+
LaunchOptionsStore.shared.launchOptions = nil
|
|
150
|
+
OneKeyLog.info("DeviceUtils", "Cleared launch options")
|
|
151
|
+
return true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
func getDeviceToken() throws -> Promise<String> {
|
|
156
|
+
return Promise.async {
|
|
157
|
+
return LaunchOptionsStore.shared.getDeviceTokenString()
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
func saveDeviceToken(token: String) throws -> Promise<Void> {
|
|
162
|
+
return Promise.async {
|
|
163
|
+
LaunchOptionsStore.shared.saveDeviceToken(token)
|
|
164
|
+
OneKeyLog.info("DeviceUtils", "saveDeviceToken: token saved")
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func registerDeviceToken() throws -> Promise<Bool> {
|
|
169
|
+
return Promise.async {
|
|
170
|
+
OneKeyLog.info("DeviceUtils", "registerDeviceToken")
|
|
171
|
+
return true
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func getStartupTime() throws -> Promise<Double> {
|
|
176
|
+
return Promise.async {
|
|
177
|
+
return LaunchOptionsStore.shared.startupTime * 1000.0
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// MARK: - ExitModule
|
|
182
|
+
|
|
183
|
+
func exitApp() throws {
|
|
184
|
+
// No-op on iOS: Apple prohibits programmatic app termination (App Store guideline 2.4.5).
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// MARK: - WebView & Play Services
|
|
188
|
+
|
|
189
|
+
func getCurrentWebViewPackageInfo() throws -> Promise<WebViewPackageInfo> {
|
|
190
|
+
return Promise.resolved(withResult: WebViewPackageInfo(
|
|
191
|
+
packageName: "com.apple.WebKit",
|
|
192
|
+
versionName: UIDevice.current.systemVersion,
|
|
193
|
+
versionCode: 0
|
|
194
|
+
))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
func isGooglePlayServicesAvailable() throws -> Promise<GooglePlayServicesStatus> {
|
|
198
|
+
return Promise.resolved(withResult: GooglePlayServicesStatus(
|
|
199
|
+
status: -1,
|
|
200
|
+
isAvailable: false
|
|
201
|
+
))
|
|
202
|
+
}
|
|
94
203
|
}
|
|
@@ -6,6 +6,19 @@ export interface DualScreenInfoRect {
|
|
|
6
6
|
width: number;
|
|
7
7
|
height: number;
|
|
8
8
|
}
|
|
9
|
+
export interface LaunchOptions {
|
|
10
|
+
launchType: string;
|
|
11
|
+
deepLink?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface WebViewPackageInfo {
|
|
14
|
+
packageName: string;
|
|
15
|
+
versionName: string;
|
|
16
|
+
versionCode: number;
|
|
17
|
+
}
|
|
18
|
+
export interface GooglePlayServicesStatus {
|
|
19
|
+
status: number;
|
|
20
|
+
isAvailable: boolean;
|
|
21
|
+
}
|
|
9
22
|
export interface ReactNativeDeviceUtils extends HybridObject<{
|
|
10
23
|
ios: 'swift';
|
|
11
24
|
android: 'kotlin';
|
|
@@ -19,5 +32,14 @@ export interface ReactNativeDeviceUtils extends HybridObject<{
|
|
|
19
32
|
addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
|
|
20
33
|
removeSpanningChangedListener(id: number): void;
|
|
21
34
|
setUserInterfaceStyle(style: UserInterfaceStyle): void;
|
|
35
|
+
getLaunchOptions(): Promise<LaunchOptions>;
|
|
36
|
+
clearLaunchOptions(): Promise<boolean>;
|
|
37
|
+
getDeviceToken(): Promise<string>;
|
|
38
|
+
saveDeviceToken(token: string): Promise<void>;
|
|
39
|
+
registerDeviceToken(): Promise<boolean>;
|
|
40
|
+
getStartupTime(): Promise<number>;
|
|
41
|
+
exitApp(): void;
|
|
42
|
+
getCurrentWebViewPackageInfo(): Promise<WebViewPackageInfo>;
|
|
43
|
+
isGooglePlayServicesAvailable(): Promise<GooglePlayServicesStatus>;
|
|
22
44
|
}
|
|
23
45
|
//# sourceMappingURL=ReactNativeDeviceUtils.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNativeDeviceUtils.nitro.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeDeviceUtils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,kBAAkB,IAAI,IAAI,CAAC;IAC3B,kBAAkB,IAAI,OAAO,CAAC;IAC9B,UAAU,IAAI,OAAO,CAAC;IACtB,cAAc,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAChD,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,0BAA0B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,CAAC;IAC5E,6BAA6B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"ReactNativeDeviceUtils.nitro.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeDeviceUtils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAElE,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,kBAAkB,IAAI,IAAI,CAAC;IAC3B,kBAAkB,IAAI,OAAO,CAAC;IAC9B,UAAU,IAAI,OAAO,CAAC;IACtB,cAAc,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAChD,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,0BAA0B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,CAAC;IAC5E,6BAA6B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAGvD,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAC3C,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAGlC,OAAO,IAAI,IAAI,CAAC;IAGhB,4BAA4B,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC5D,6BAA6B,IAAI,OAAO,CAAC,wBAAwB,CAAC,CAAC;CACpE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JGooglePlayServicesStatus.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "GooglePlayServicesStatus.hpp"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "GooglePlayServicesStatus" and the the Kotlin data class "GooglePlayServicesStatus".
|
|
21
|
+
*/
|
|
22
|
+
struct JGooglePlayServicesStatus final: public jni::JavaClass<JGooglePlayServicesStatus> {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/GooglePlayServicesStatus;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct GooglePlayServicesStatus by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
GooglePlayServicesStatus toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldStatus = clazz->getField<double>("status");
|
|
35
|
+
double status = this->getFieldValue(fieldStatus);
|
|
36
|
+
static const auto fieldIsAvailable = clazz->getField<jboolean>("isAvailable");
|
|
37
|
+
jboolean isAvailable = this->getFieldValue(fieldIsAvailable);
|
|
38
|
+
return GooglePlayServicesStatus(
|
|
39
|
+
status,
|
|
40
|
+
static_cast<bool>(isAvailable)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
/**
|
|
46
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
47
|
+
*/
|
|
48
|
+
[[maybe_unused]]
|
|
49
|
+
static jni::local_ref<JGooglePlayServicesStatus::javaobject> fromCpp(const GooglePlayServicesStatus& value) {
|
|
50
|
+
using JSignature = JGooglePlayServicesStatus(double, jboolean);
|
|
51
|
+
static const auto clazz = javaClassStatic();
|
|
52
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
53
|
+
return create(
|
|
54
|
+
clazz,
|
|
55
|
+
value.status,
|
|
56
|
+
value.isAvailable
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -9,6 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
// Forward declaration of `DualScreenInfoRect` to properly resolve imports.
|
|
11
11
|
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
12
|
+
// Forward declaration of `LaunchOptions` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::reactnativedeviceutils { struct LaunchOptions; }
|
|
14
|
+
// Forward declaration of `WebViewPackageInfo` to properly resolve imports.
|
|
15
|
+
namespace margelo::nitro::reactnativedeviceutils { struct WebViewPackageInfo; }
|
|
16
|
+
// Forward declaration of `GooglePlayServicesStatus` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::reactnativedeviceutils { struct GooglePlayServicesStatus; }
|
|
12
18
|
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
|
|
13
19
|
namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
|
|
14
20
|
|
|
@@ -17,6 +23,14 @@ namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle
|
|
|
17
23
|
#include <NitroModules/Promise.hpp>
|
|
18
24
|
#include <NitroModules/JPromise.hpp>
|
|
19
25
|
#include "JDualScreenInfoRect.hpp"
|
|
26
|
+
#include "LaunchOptions.hpp"
|
|
27
|
+
#include "JLaunchOptions.hpp"
|
|
28
|
+
#include <string>
|
|
29
|
+
#include <optional>
|
|
30
|
+
#include "WebViewPackageInfo.hpp"
|
|
31
|
+
#include "JWebViewPackageInfo.hpp"
|
|
32
|
+
#include "GooglePlayServicesStatus.hpp"
|
|
33
|
+
#include "JGooglePlayServicesStatus.hpp"
|
|
20
34
|
#include <functional>
|
|
21
35
|
#include "JFunc_void_bool.hpp"
|
|
22
36
|
#include <NitroModules/JNICallable.hpp>
|
|
@@ -127,5 +141,136 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
127
141
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JUserInterfaceStyle> /* style */)>("setUserInterfaceStyle");
|
|
128
142
|
method(_javaPart, JUserInterfaceStyle::fromCpp(style));
|
|
129
143
|
}
|
|
144
|
+
std::shared_ptr<Promise<LaunchOptions>> JHybridReactNativeDeviceUtilsSpec::getLaunchOptions() {
|
|
145
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getLaunchOptions");
|
|
146
|
+
auto __result = method(_javaPart);
|
|
147
|
+
return [&]() {
|
|
148
|
+
auto __promise = Promise<LaunchOptions>::create();
|
|
149
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
150
|
+
auto __result = jni::static_ref_cast<JLaunchOptions>(__boxedResult);
|
|
151
|
+
__promise->resolve(__result->toCpp());
|
|
152
|
+
});
|
|
153
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
154
|
+
jni::JniException __jniError(__throwable);
|
|
155
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
156
|
+
});
|
|
157
|
+
return __promise;
|
|
158
|
+
}();
|
|
159
|
+
}
|
|
160
|
+
std::shared_ptr<Promise<bool>> JHybridReactNativeDeviceUtilsSpec::clearLaunchOptions() {
|
|
161
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("clearLaunchOptions");
|
|
162
|
+
auto __result = method(_javaPart);
|
|
163
|
+
return [&]() {
|
|
164
|
+
auto __promise = Promise<bool>::create();
|
|
165
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
166
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
167
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
168
|
+
});
|
|
169
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
170
|
+
jni::JniException __jniError(__throwable);
|
|
171
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
172
|
+
});
|
|
173
|
+
return __promise;
|
|
174
|
+
}();
|
|
175
|
+
}
|
|
176
|
+
std::shared_ptr<Promise<std::string>> JHybridReactNativeDeviceUtilsSpec::getDeviceToken() {
|
|
177
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getDeviceToken");
|
|
178
|
+
auto __result = method(_javaPart);
|
|
179
|
+
return [&]() {
|
|
180
|
+
auto __promise = Promise<std::string>::create();
|
|
181
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
182
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
183
|
+
__promise->resolve(__result->toStdString());
|
|
184
|
+
});
|
|
185
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
186
|
+
jni::JniException __jniError(__throwable);
|
|
187
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
188
|
+
});
|
|
189
|
+
return __promise;
|
|
190
|
+
}();
|
|
191
|
+
}
|
|
192
|
+
std::shared_ptr<Promise<void>> JHybridReactNativeDeviceUtilsSpec::saveDeviceToken(const std::string& token) {
|
|
193
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* token */)>("saveDeviceToken");
|
|
194
|
+
auto __result = method(_javaPart, jni::make_jstring(token));
|
|
195
|
+
return [&]() {
|
|
196
|
+
auto __promise = Promise<void>::create();
|
|
197
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& /* unit */) {
|
|
198
|
+
__promise->resolve();
|
|
199
|
+
});
|
|
200
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
201
|
+
jni::JniException __jniError(__throwable);
|
|
202
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
203
|
+
});
|
|
204
|
+
return __promise;
|
|
205
|
+
}();
|
|
206
|
+
}
|
|
207
|
+
std::shared_ptr<Promise<bool>> JHybridReactNativeDeviceUtilsSpec::registerDeviceToken() {
|
|
208
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("registerDeviceToken");
|
|
209
|
+
auto __result = method(_javaPart);
|
|
210
|
+
return [&]() {
|
|
211
|
+
auto __promise = Promise<bool>::create();
|
|
212
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
213
|
+
auto __result = jni::static_ref_cast<jni::JBoolean>(__boxedResult);
|
|
214
|
+
__promise->resolve(static_cast<bool>(__result->value()));
|
|
215
|
+
});
|
|
216
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
217
|
+
jni::JniException __jniError(__throwable);
|
|
218
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
219
|
+
});
|
|
220
|
+
return __promise;
|
|
221
|
+
}();
|
|
222
|
+
}
|
|
223
|
+
std::shared_ptr<Promise<double>> JHybridReactNativeDeviceUtilsSpec::getStartupTime() {
|
|
224
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getStartupTime");
|
|
225
|
+
auto __result = method(_javaPart);
|
|
226
|
+
return [&]() {
|
|
227
|
+
auto __promise = Promise<double>::create();
|
|
228
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
229
|
+
auto __result = jni::static_ref_cast<jni::JDouble>(__boxedResult);
|
|
230
|
+
__promise->resolve(__result->value());
|
|
231
|
+
});
|
|
232
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
233
|
+
jni::JniException __jniError(__throwable);
|
|
234
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
235
|
+
});
|
|
236
|
+
return __promise;
|
|
237
|
+
}();
|
|
238
|
+
}
|
|
239
|
+
void JHybridReactNativeDeviceUtilsSpec::exitApp() {
|
|
240
|
+
static const auto method = javaClassStatic()->getMethod<void()>("exitApp");
|
|
241
|
+
method(_javaPart);
|
|
242
|
+
}
|
|
243
|
+
std::shared_ptr<Promise<WebViewPackageInfo>> JHybridReactNativeDeviceUtilsSpec::getCurrentWebViewPackageInfo() {
|
|
244
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getCurrentWebViewPackageInfo");
|
|
245
|
+
auto __result = method(_javaPart);
|
|
246
|
+
return [&]() {
|
|
247
|
+
auto __promise = Promise<WebViewPackageInfo>::create();
|
|
248
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
249
|
+
auto __result = jni::static_ref_cast<JWebViewPackageInfo>(__boxedResult);
|
|
250
|
+
__promise->resolve(__result->toCpp());
|
|
251
|
+
});
|
|
252
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
253
|
+
jni::JniException __jniError(__throwable);
|
|
254
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
255
|
+
});
|
|
256
|
+
return __promise;
|
|
257
|
+
}();
|
|
258
|
+
}
|
|
259
|
+
std::shared_ptr<Promise<GooglePlayServicesStatus>> JHybridReactNativeDeviceUtilsSpec::isGooglePlayServicesAvailable() {
|
|
260
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("isGooglePlayServicesAvailable");
|
|
261
|
+
auto __result = method(_javaPart);
|
|
262
|
+
return [&]() {
|
|
263
|
+
auto __promise = Promise<GooglePlayServicesStatus>::create();
|
|
264
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
265
|
+
auto __result = jni::static_ref_cast<JGooglePlayServicesStatus>(__boxedResult);
|
|
266
|
+
__promise->resolve(__result->toCpp());
|
|
267
|
+
});
|
|
268
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
269
|
+
jni::JniException __jniError(__throwable);
|
|
270
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
271
|
+
});
|
|
272
|
+
return __promise;
|
|
273
|
+
}();
|
|
274
|
+
}
|
|
130
275
|
|
|
131
276
|
} // namespace margelo::nitro::reactnativedeviceutils
|