-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implement print intent #1038
Conversation
acezard
commented
Nov 27, 2023
•
edited
Loading
edited
- AA - Interface permettant au cozy-app de demander une impression (cozy-intent.call(print) - la cozy-app fourni la base 64 du fichier à imprimer )
- AA - Intégrer la librairie https://github.com/christopherdro/react-native-print
- AA - Sauvegarde du fichier dans un dossier temporaire (voir OCR)
- AA - Afficher un toast si erreur
- AA - Avoir une méthode de type (isprintavailable)
- Add tests
src/libs/intents/printBase64Doc.ts
Outdated
|
||
await RNPrint.print({ filePath: path }) | ||
await RNFS.writeFile(path, fileContent, 'base64') | ||
await RNPrint.print({ filePath: path.replace('file://', '') }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to do a path.replace
again ? It is already in getTemporaryPrintFilePath
no ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, need to remove it. With the prefix the print lib can't find the file. Maybe writeFile could not use it so it's clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zatteo to sum up: from what I understand I need the file prefix when writing the file, but when reading it with the print library, having that prefix will make the print software unable to read the file. I made it clearer by abstracting this file prefix in a "writeFile" local function
edit: after further test it seems I don't need the file prefix even when writing file. Do you remember why you had to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backup feature, it seems that I remove 'file://' both for iOS and Android.
I do not know what it is kept on ocr feature / if it's needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For backup feature, it seems that I remove 'file://' both for iOS and Android.
I do not know what it is kept on ocr feature / if it's needed here.
for writing file, it seemed to work both with and without file prefix on Android. I just ignored it altogether in the most recent revision, not prepending it anywhere
5497f6a
to
0c7639b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR, commits are well split so it was easy to read 👍
src/libs/intents/printBase64Doc.ts
Outdated
const date = format(new Date(), 'yyyyMMddHHmmssSSS') | ||
const tempFileName = `temp_print_${date}.printfile` | ||
|
||
const tempFileName = `temp_print_${date}.${fileExtension}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't print anything for a long time, but I remember that in certain scenario the printer would print the file name in the page footer. Is this still a thing for Android and iOS devices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see it, and when saving as PDF Android discards the temp file name and creates its own filename from scratch. Though in any case, I make the name more end-user presentable if it's ever shown
src/libs/intents/printBase64Doc.ts
Outdated
} | ||
|
||
const writeFile = async (filePath: string, content: string): Promise<void> => { | ||
return await RNFS.writeFile(`${filePath}`, content, 'base64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we don't need this templated string anymore here.
return await RNFS.writeFile(`${filePath}`, content, 'base64') | |
return await RNFS.writeFile(filePath, content, 'base64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
src/libs/intents/printBase64Doc.ts
Outdated
log.error(`Error while printing document: ${getErrorMessage(err)}`) | ||
Toast.show({ | ||
type: 'error', | ||
text1: t('error.unknown_error') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be more specific in the toast message to state that this is about the print feature? Something like Failed to print, an error occured
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree ✅
Borrows a lot from `ocr`, should be refactored probably. Not sure if worth it because not a lot of code
Also abstract out writeFile to keep main function lean
1de9f6b
to
5b73d97
Compare