Skip to content

Commit

Permalink
Refactor closeConn method in printer modules to handle null adapter (#…
Browse files Browse the repository at this point in the history
…119)

The closeConn method in the RNBLEPrinterModule, RNNetPrinterModule, and RNUSBPrinterModule has been refactored to handle the case where the adapter is null. If the adapter is null, it is initialized before closing the connection. This change ensures that the closeConn method works correctly even when the adapter is not yet instantiated.
  • Loading branch information
matheus-caldeira authored Sep 16, 2024
1 parent 7679571 commit f58d0dc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public void init(Callback successCallback, Callback errorCallback) {
@ReactMethod
@Override
public void closeConn() {
adapter.closeConnectionIfExists();
if (this.adapter == null) {
this.adapter = BLEPrinterAdapter.getInstance();
}
this.adapter.closeConnectionIfExists();
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public void init(Callback successCallback, Callback errorCallback) {
@ReactMethod
@Override
public void closeConn() {
this.adapter = NetPrinterAdapter.getInstance();
if (this.adapter == null) {
this.adapter = NetPrinterAdapter.getInstance();
}
this.adapter.closeConnectionIfExists();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public void init(Callback successCallback, Callback errorCallback) {
@ReactMethod
@Override
public void closeConn() {
adapter.closeConnectionIfExists();
if (this.adapter == null) {
this.adapter = USBPrinterAdapter.getInstance();
}
this.adapter.closeConnectionIfExists();
}

@ReactMethod
Expand Down

0 comments on commit f58d0dc

Please sign in to comment.