-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from GantMan/handle-native-module-missing
Improve handling of missing native module
- Loading branch information
Showing
2 changed files
with
19 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
import { NativeModules, Platform } from "react-native"; | ||
|
||
const { JailMonkey } = NativeModules; | ||
const message = "JailMonkey native module is not available, check your native dependencies have linked correctly and ensure your app has been rebuilt"; | ||
|
||
if (JailMonkey == null) console.warn("JailMonkey is not available, check your native dependencies have linked correctly and ensure your app has been rebuilt"); | ||
if (NativeModules.JailMonkey == null) console.warn(message); | ||
|
||
function getJailMonkey() { | ||
const { JailMonkey } = NativeModules; | ||
if (JailMonkey == null) throw new Error(message) | ||
return JailMonkey; | ||
} | ||
|
||
export default { | ||
jailBrokenMessage: () => JailMonkey.jailBrokenMessage || "", | ||
isJailBroken: () => JailMonkey.isJailBroken || false, | ||
androidRootedDetectionMethods: JailMonkey.rootedDetectionMethods, | ||
hookDetected: () => JailMonkey.hookDetected || false, | ||
canMockLocation: () => JailMonkey.canMockLocation || false, | ||
jailBrokenMessage: () => getJailMonkey().jailBrokenMessage || "", | ||
isJailBroken: () => getJailMonkey().isJailBroken || false, | ||
androidRootedDetectionMethods: NativeModules.JailMonkey?.rootedDetectionMethods ?? {}, | ||
hookDetected: () => getJailMonkey().hookDetected || false, | ||
canMockLocation: () => getJailMonkey().canMockLocation || false, | ||
trustFall: () => | ||
JailMonkey.isJailBroken || JailMonkey.canMockLocation || false, | ||
isOnExternalStorage: () => JailMonkey.isOnExternalStorage || false, | ||
isDebuggedMode: () => JailMonkey.isDebuggedMode(), | ||
getJailMonkey().isJailBroken || getJailMonkey().canMockLocation || false, | ||
isOnExternalStorage: () => getJailMonkey().isOnExternalStorage || false, | ||
isDebuggedMode: () => getJailMonkey().isDebuggedMode(), | ||
isDevelopmentSettingsMode: () => { | ||
// API only available on Android, return false for all other platforms. | ||
if (Platform.OS !== "android") return Promise.resolve(false); | ||
return JailMonkey.isDevelopmentSettingsMode(); | ||
return getJailMonkey().isDevelopmentSettingsMode(); | ||
}, | ||
AdbEnabled: () => JailMonkey.AdbEnabled || false, | ||
AdbEnabled: () => getJailMonkey().AdbEnabled || false, | ||
}; |