Skip to content

Commit

Permalink
Add logging to native printing, bump
Browse files Browse the repository at this point in the history
  • Loading branch information
albertzak committed Jun 20, 2022
1 parent 430a575 commit 88f0132
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 13 additions & 1 deletion app/electron/main/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ const { shell, ipcMain } = require('electron')
const logger = require('./logger')

const start = (options) => {
logger.info('print setup')
temp.track()
ipcMain.on('print', (e, printOptions) => {

logger.info('print tracking')
ipcMain.on('print', (e, printOptions) => {
logger.info('print called')
const { title, physical, printer, flags, localPath, base64 } = printOptions
if (physical && (base64 || localPath)) {
logger.info('print physical')
const args = {
printer,
win32: flags
Expand All @@ -37,18 +41,22 @@ const start = (options) => {
})
})
} else if (localPath) {
logger.info('print localPath')
logger.info(`[print] physical local path file "${localPath}" on printer "${printer}" with flags ${JSON.stringify(args)}`)
pdfToPrinter.print(localPath, args)
}
} else {
logger.info('print toPdf')
options.title = title
printToPdf(options)
}
})
}

const printToPdf = (options) => {
logger.info('print making temp')
temp.mkdir('rosalind', (err, tmpDir) => {
logger.info('print made')
if (err) { return logger.error(err) }
const pdfPath = path.join(tmpDir, (options.title || 'Print') + '.pdf')

Expand All @@ -59,18 +67,22 @@ const printToPdf = (options) => {
landscape: true
}

logger.info('print calling ipcReceiver.printToPDF')
options.ipcReceiver.printToPDF(printOptions, (err, data) => {
if (err) {
logger.error('[Print] Failed to generate pdf: ' + err)
return
}

logger.info('print writing file')
fs.writeFile(pdfPath, data, (err) => {
if (err) {
logger.error('[Print] Failed to save pdf: ' + err)
return
}
logger.info('[Print] Saved pdf to path: ' + pdfPath)

logger.info('print opening file')
const ok = shell.openItem(pdfPath)
if (!ok) {
logger.error('[Print] failed to open pdf: ' + pdfPath)
Expand Down
2 changes: 1 addition & 1 deletion app/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rosalind",
"productName": "Rosalind",
"version": "0.0.261",
"version": "0.0.262",
"private": true,
"description": "Rosalind",
"author": {
Expand Down

0 comments on commit 88f0132

Please sign in to comment.