import path from 'path'; import fs from 'fs'; import { remote } from 'electron'; const { app, BrowserWindow } = remote; export default class PrintWindow { constructor({ subject, account, participants, styleTags, htmlContent, printMessages }) { // This script will create the print prompt when loaded. We can also call // print directly from this process, but inside print.js we can make sure to // call window.print() after we've cleaned up the dom for printing const scriptPath = path.join(__dirname, '..', 'static', 'print.js'); const stylesPath = path.join(__dirname, '..', 'static', 'print-styles.css'); const participantsHtml = participants .map(part => { return `
  • ${part.name} <${part.email}>
  • `; }) .join(''); const content = ` ${styleTags} ${htmlContent} `; this.tmpFile = path.join(app.getPath('temp'), 'print.html'); this.browserWin = new BrowserWindow({ width: 800, height: 600, title: `Print - ${subject}`, webPreferences: { nodeIntegration: false, }, }); fs.writeFileSync(this.tmpFile, content); } /** * Load our temp html file. Once the file is loaded it will run print.js, and * that script will pop out the print dialog. */ load() { this.browserWin.loadURL(`file://${this.tmpFile}`); } }