Skip to content

Commit

Permalink
Merge pull request #233 from GantMan/handle-native-module-missing
Browse files Browse the repository at this point in the history
Improve handling of missing native module
  • Loading branch information
levibuzolic authored Apr 4, 2024
2 parents 07133d3 + 9e7fc6d commit 218f676
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private static boolean canExecuteCommand(String command) {
boolean executeResult;
try {
Process process = Runtime.getRuntime().exec(command);
if(process.waitFor() == 0) {
if (process.waitFor() == 0) {
executeResult = true;
} else {
executeResult = false;
Expand Down
30 changes: 18 additions & 12 deletions jailmonkey.js
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,
};

0 comments on commit 218f676

Please sign in to comment.