Skip to content

Commit

Permalink
Add print helper to WindowManager
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Jul 11, 2019
1 parent 5a367b0 commit b7f2d4b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/browser/tropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,23 +694,30 @@ class Tropy extends EventEmitter {
})

ipc.on('print', async (_, items) => {
if (!items.length) return
try {
if (!items.length) return

let win = await this.wm.open('print', this.hash)
var win = await this.wm.open('print', this.hash)

await once(win, 'react:ready')
info(`will print ${items.length} item(s)`)
win.send('print', items)
await Promise.race([
once(win, 'react:ready'),
delay(2000)
])

await Promise.race([
once(win, 'print:ready'),
delay(5000)
])
info(`will print ${items.length} item(s)`)
win.send('print', items)

win.webContents.print({}, (success) => {
info(`printing ${success ? 'confirmed' : 'aborted'}`)
win.close()
})
await Promise.race([
once(win, 'print:ready'),
delay(5000)
])

let result = await WindowManager.print(win)
info(`printing ${result ? 'confirmed' : 'aborted'}`)

} finally {
if (win != null) win.close()
}
})

ipc.on('error', (event, error) => {
Expand Down
6 changes: 6 additions & 0 deletions src/browser/wm.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,12 @@ class WindowManager extends EventEmitter {
.getUserDefault('AppleActionOnDoubleClick', 'string')
.toLowerCase()
}

static print(win, opts = {}) {
return new Promise((resolve) => {
win.webContents.print(opts, resolve)
})
}
}


Expand Down

0 comments on commit b7f2d4b

Please sign in to comment.