Skip to content

Commit

Permalink
fix crash with print test in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertclarkson committed Nov 23, 2023
1 parent b94df09 commit bbdb0a6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());

Expand All @@ -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());
}
Expand Down
53 changes: 30 additions & 23 deletions screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Image,
Modal,
NativeModules,
Alert,
} from 'react-native';

import {useNavigation, useFocusEffect} from '@react-navigation/native';
Expand Down Expand Up @@ -674,33 +675,39 @@ function Home({navigation}): React.FC<Props> {
};

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 (
Expand Down
2 changes: 2 additions & 0 deletions screens/settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
TouchableOpacity,
Linking,
ActivityIndicator,
Alert,
NativeModules,
} from 'react-native';
import {SimpleListItem} from '../../SimpleComponents';
import {Colors} from 'react-native/Libraries/NewAppScreen';
Expand Down

0 comments on commit bbdb0a6

Please sign in to comment.