diff --git a/android/app/build.gradle b/android/app/build.gradle index 961a63d..23ca8c8 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -101,8 +101,8 @@ android { /* * https://www.epochconverter.com/ */ - versionCode 1700709469 - versionName "1.3.0" + versionCode 1700712146 + versionName "1.3.1" missingDimensionStrategy 'react-native-camera', 'general' diff --git a/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java b/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java index 07043cf..2bef453 100644 --- a/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java +++ b/android/app/src/main/java/org/boltcard/boltcardpos/MainActivity.java @@ -69,16 +69,17 @@ public void onServiceConnected(ComponentName name, IBinder service) { } }; - private void bindService() { - Intent intent = new Intent(); - intent.setPackage("net.nyx.printerservice"); - intent.setAction("net.nyx.printerservice.IPrinterService"); - bindService(intent, connService, Context.BIND_AUTO_CREATE); - } + private void bindService() { + Log.d(TAG,"bindService"); + Intent intent = new Intent(); + intent.setPackage("net.nyx.printerservice"); + intent.setAction("net.nyx.printerservice.IPrinterService"); + bindService(intent, connService, Context.BIND_AUTO_CREATE); + } - private void unbindService() { - unbindService(connService); - } + private void unbindService() { + unbindService(connService); + } public void printText(String text, int size) { try { @@ -95,7 +96,7 @@ public void printText(String text, int size) { PrintTextFormat textFormat = new PrintTextFormat(); if(size > 0) textFormat.setTextSize(size); // default is 24 int ret = printerService.printText(text, textFormat); - } catch (RemoteException e) { + } catch (Exception e) { e.printStackTrace(); // callBack.invoke("Error: "+e.getMessage()); } @@ -114,7 +115,7 @@ public void printQRCode(String text, int width, int height) { */ int ret = printerService.printQrCode(text, width, height, 1); // callBack.invoke(msg(ret)); - } catch (RemoteException e) { + } catch (Exception e) { e.printStackTrace(); // callBack.invoke("Error: "+e.getMessage()); } @@ -133,7 +134,7 @@ public void testPrint(Callback callBack) { printerService.paperOut(100); callBack.invoke(msg(ret)); - } catch (RemoteException e) { + } catch (Exception e) { e.printStackTrace(); callBack.invoke("Error: "+e.getMessage()); @@ -144,7 +145,7 @@ public void paperOut(int pixels) { try { printerService.paperOut(pixels); // callBack.invoke("paperOut "+pixels); - } catch (RemoteException e) { + } catch (Exception e) { e.printStackTrace(); // callBack.invoke("Error: "+e.getMessage()); } diff --git a/screens/Home.tsx b/screens/Home.tsx index b49b7e3..914ec17 100644 --- a/screens/Home.tsx +++ b/screens/Home.tsx @@ -18,6 +18,7 @@ import { Image, Modal, NativeModules, + Alert, } from 'react-native'; import {useNavigation, useFocusEffect} from '@react-navigation/native'; @@ -674,33 +675,39 @@ function Home({navigation}): React.FC { }; const onPrint = async invoice => { - await NativeModules.PrintModule.printText(invoice.description, 32); - await NativeModules.PrintModule.paperOut(24); + try { + await NativeModules.PrintModule.printText(invoice.description, 32); + await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24); - await NativeModules.PrintModule.paperOut(24); + await NativeModules.PrintModule.printText('Payment made in Bitcoin', 24); + await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printText( - moment(invoice.timestamp * 1000).format('DD/MM/YY HH:mm:ss'), - 24, - ); - await NativeModules.PrintModule.paperOut(24); + await NativeModules.PrintModule.printText( + moment(invoice.timestamp * 1000).format('DD/MM/YY HH:mm:ss'), + 24, + ); + await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printText( - invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'), - 32, - ); - await NativeModules.PrintModule.paperOut(24); - - await NativeModules.PrintModule.printText(invoice.payment_hash, 24); - await NativeModules.PrintModule.paperOut(24); - await NativeModules.PrintModule.printQRCode( - JSON.stringify({payment_hash: invoice.payment_hash}), - 400, - 400, - ); + await NativeModules.PrintModule.printText( + invoice.amt + ' sats ' + (invoice.ispaid ? '(PAID)' : '(PENDING)'), + 32, + ); + await NativeModules.PrintModule.paperOut(24); + + await NativeModules.PrintModule.printText(invoice.payment_hash, 24); + await NativeModules.PrintModule.paperOut(24); + await NativeModules.PrintModule.printQRCode( + JSON.stringify({payment_hash: invoice.payment_hash}), + 400, + 400, + ); - await NativeModules.PrintModule.paperOut(100); + await NativeModules.PrintModule.paperOut(100); + } catch (e) { + Alert.alert('Error', 'There was an error when printing ' + e.message, [ + {text: 'OK', onPress: () => console.log('OK Pressed')}, + ]); + } }; return ( diff --git a/screens/settings/Settings.js b/screens/settings/Settings.js index ae1dbc8..4395f02 100644 --- a/screens/settings/Settings.js +++ b/screens/settings/Settings.js @@ -10,6 +10,8 @@ import { TouchableOpacity, Linking, ActivityIndicator, + Alert, + NativeModules, } from 'react-native'; import {SimpleListItem} from '../../SimpleComponents'; import {Colors} from 'react-native/Libraries/NewAppScreen';