Mailspring/internal_packages/print/lib/printer.es6
Juan Tejada 931a93af4e feat(print): Add functionality to print currently focused thread
Summary:
- Adds button inside the message list to print the thread
- Adds cmdctrl-p binding to print thread
- Adds new action and new internal_package to listen to this action.
- Creates a standalone browser window with current thread html, and removes all
collapsed messsages from the print view

Test Plan: - Manual

Reviewers: evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2310
2015-12-04 18:12:06 -08:00

43 lines
1.2 KiB
JavaScript

import {AccountStore, Actions} from 'nylas-exports';
import PrintWindow from './print-window';
class Printer {
constructor() {
this.unsub = Actions.printThread.listen(this._printThread);
}
_printThread(thread, htmlContent) {
if (!thread) throw new Error('Printing: No thread active!');
// Get the <nylas-styles> tag present in the document
const styleTag = document.getElementsByTagName('nylas-styles')[0];
// These iframes should correspond to the message iframes when a thread is
// focused
const iframes = document.getElementsByTagName('iframe');
// Grab the html inside the iframes
const messagesHtml = [].slice.call(iframes).map((iframe)=> {
return iframe.contentDocument.documentElement.innerHTML;
});
const win = new PrintWindow({
subject: thread.subject,
account: {
name: AccountStore.current().name,
email: AccountStore.current().emailAddress,
},
participants: thread.participants,
styleTags: styleTag.innerHTML,
htmlContent,
printMessages: JSON.stringify(messagesHtml),
});
win.load();
}
deactivate() {
this.unsub();
}
}
export default Printer;