Skip to content

Commit

Permalink
Fixed dev features for cordova and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kober32 committed Sep 12, 2024
1 parent 701d184 commit 6c0a0dd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/Troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ PowerAuthDebug.traceNativeCodeCalls(true, true);
```

<!-- begin box warning -->
The `PowerAuthDebug` class is effective only if global `__DEV__` constant is `true`. We don't want to log the sensitive information to the console in the production application.
The `PowerAuthDebug` class is effective only when `isEnabled` is `true`. We don't want to log the sensitive information to the console in the production application.
<!-- end -->

## Dumping native objects

If `__DEV__` mode is turned on, then you can dump information about all native objects allocated and used by PowerAuth Mobile JS SDK:
If `PowerAuthDebug.isEnabled` is turned on, then you can dump information about all native objects allocated and used by PowerAuth Mobile JS SDK:

```javascript
// Dump all objects
Expand Down
1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const tmpDir = ".build";
const copyCDVSourceFiles = () =>
gulp
.src("src/**/**.ts", { base: ".", allowEmpty: true })
.pipe(replace("__DEV__", "false")) // replace reaact-native __DEV__ with false by default
.pipe(gulp.dest(CDV_tempDir));

const copyCDVPatchSourceFiles = () =>
Expand Down
1 change: 0 additions & 1 deletion other-platforms-support/cordova/src/internal/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

export class Utils {

static isDev = false // TODO: set real value
static platformOs = this.detectPlatform()

// TODO: we should probably make this more robust
Expand Down
17 changes: 12 additions & 5 deletions src/debug/PowerAuthDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,39 @@
import { PowerAuthError } from "../index";
import { NativeWrapper } from "../internal/NativeWrapper";
import { NativeObjectRegister } from "./NativeObjectRegister";
import { Utils } from "../internal/Utils";

/**
* The `PowerAuthDebug` class provides a various functionality that can
* help application develoepr with debugging the problem with React Native PowerAuth mobile SDK.
*/
export class PowerAuthDebug {

/**
* If debug features are enabled.
*
* Initial value = `__DEV__`
*/
static isEnabled = __DEV__

/**
* Enable or disable detailed log with calls to native code. Be aware that this feature is
* effective only if global __DEV__ constant is `true`.
* effective only if `isEnabled` static property is `true`.
* @param traceFailure If set to `true`, then SDK will print a detailed error if native call fails.
* @param traceEachCall If set to `true`, then SDK will print a detailed information about each call to the native code.
*/
static traceNativeCodeCalls(traceFailure: boolean, traceEachCall: boolean = false) {
if (Utils.isDev) {
if (this.isEnabled) {
NativeWrapper.setDebugFeatures(traceFailure, traceEachCall)
}
}

/**
* Function prints debug information about all native objects registered in native module. Note that the function
* is effective ony if native module is compiled in DEBUG mode and if global `__DEV__` constant is `true`.
* is effective ony if native module is compiled in DEBUG mode and if `isEnabled` static property is `true`.
* @param instanceId If provided, then prints only objects that belongs to PowerAuth instance with given identifier.
*/
static async dumpNativeObjects(instanceId: string | undefined = undefined): Promise<void> {
if (Utils.isDev) {
if (this.isEnabled) {
if (instanceId) {
console.log(`List of native objects associated with instance '${instanceId}' = [`)
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/internal/NativeWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ export class NativeWrapper {
}

/**
* Enable or disable low level debug features. The __DEV__ variable must be true.
* Enable or disable low level debug features. The `PowerAuthDebug.isEnabled` variable must be true.
* @param traceFail If true, then detailed log entry about failure will be printed to the console.
* @param traceCall If true, then each call to native code will be printed with a detailed information.
*/
static setDebugFeatures(traceFail: boolean, traceCall: boolean) {
if (Utils.isDev) {
if (PowerAuthDebug.isEnabled) {
if (traceCall || traceFail) {
this.thisTrampoline = new DebugThisCall(traceCall, traceFail)
this.staticTrampoline = new DebugStaticCall(traceCall, traceFail)
Expand Down
1 change: 0 additions & 1 deletion src/internal/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
import { Platform } from 'react-native';

export class Utils {
static isDev = __DEV__;
static platformOs = Platform.OS;
}
3 changes: 3 additions & 0 deletions testapp-cordova/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function onDeviceReady() {

// Cordova is now initialized. Have fun!

// enable debug
PowerAuthDebug.isEnabled = true;

const statusEl = document.getElementById('tests-status');
const progressEl = document.getElementById('tests-progress');
const messageEl = document.getElementById("test-message");
Expand Down

0 comments on commit 6c0a0dd

Please sign in to comment.