Skip to content

Commit

Permalink
Upgrade to Electron 4.0.2, linted fraserxu#231
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Good committed Jan 24, 2019
1 parent 7eede84 commit 5a7a6af
Show file tree
Hide file tree
Showing 16 changed files with 1,440 additions and 796 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ node_modules
index.html
*.pdf
*.css
*.disabled

.idea
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Production ready? See it in action for the [Myanmar Election](https://wiredcraft

Versioning
-------
Starting with version 4.0.x the master branch will always have the latest electron version.

Semantic Versioning is used, and corresponds to electron versions in the following way:
- electron-pdf 1.2.x => electron 1.4.x (Chrome 53, Node 6.5)
- electron-pdf 1.3.x => electron 1.6.x (Chrome 56, Node 7.4)
- electron-pdf 1.4.x => electron 1.7.x - Future branch TBD sometime after Electron 1.7 GA Release
- electron-pdf 2.0.x => electron 1.7.x+ - Future major release that will introduce some breaking changes
- electron-pdf 4.0.x => electron 4.0.x (Chromium 69, Node 10.11.0)
- electron-pdf 1.3.x => electron 1.6.x (Chromium 56, Node 7.4)
- electron-pdf 1.2.x => electron 1.4.x (Chromium 53, Node 6.5)

Note: The Chromium versions employed by electron have impacts based on the functionality you may be exporting. Choose which ever minor version you need based on Chrome
Note: The Chromium versions employed by electron have impacts based on the functionality you may be exporting.
Choose the version you need based on Chromium.

Install
-------
Expand Down
42 changes: 20 additions & 22 deletions lib/exportJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ setInterval(WindowMaid.cleanupHungWindows, HUNG_WINDOW_CLEANUP_INTERVAL)
* resources and a set of output options.
*/
class ExportJob extends EventEmitter {

/**
*
* @param {Array} input The path to the HTML or url, or a markdown file
Expand Down Expand Up @@ -155,8 +154,8 @@ class ExportJob extends EventEmitter {
* @property {String} results - array of generated pdf file locations
* @property {Object} error - If an error occurred, null otherwise
*/
this.emit(`${RENDER_EVENT_PREFIX}complete`, {results: results, error: err})
this.emit('job-complete', {results: results, error: err}) // Deprecated
this.emit(`${RENDER_EVENT_PREFIX}complete`, { results: results, error: err })
this.emit('job-complete', { results: results, error: err }) // Deprecated
})
}

Expand Down Expand Up @@ -229,27 +228,27 @@ class ExportJob extends EventEmitter {
_passThroughEvents (win, renderPrefix) {
win.webContents.on('did-fail-load', (r) => {
// http://electron.atom.io/docs/api/web-contents/#event-did-fail-load
this.emit(`${renderPrefix}did-fail-load`, {results: r})
this.emit(`${renderPrefix}did-fail-load`, { results: r })
})
win.webContents.on('did-start-loading', (r) => {
this.emit(`${renderPrefix}did-start-loading`, {results: r})
this.emit(`${renderPrefix}did-start-loading`, { results: r })
})
win.webContents.on('did-finish-load', (r) => {
this.emit(`${renderPrefix}did-finish-load`, {results: r})
this.emit(`${renderPrefix}did-finish-load`, { results: r })
})
win.webContents.on('dom-ready', (r) => {
this.emit(`${renderPrefix}dom-ready`, {results: r})
this.emit(`${renderPrefix}dom-ready`, { results: r })
})
win.webContents.on('did-get-response-details',
function (event,
status,
newURL,
originalURL,
httpResponseCode,
requestMethod,
referrer,
headers,
resourceType) {
status,
newURL,
originalURL,
httpResponseCode,
requestMethod,
referrer,
headers,
resourceType) {
this.emit(`${renderPrefix}did-get-response-details`, {
event: event,
status: status,
Expand Down Expand Up @@ -468,7 +467,7 @@ class ExportJob extends EventEmitter {
* @private
*/
_cancelReadyEvent (eventName, ipcListener, generateFunction) {
this.emit('window.event.wait.timeout', {eventName: eventName})
this.emit('window.event.wait.timeout', { eventName: eventName })
electron.ipcMain.removeListener(IPC_MAIN_CHANNEL_RENDER, ipcListener)
generateFunction()
}
Expand All @@ -482,7 +481,7 @@ class ExportJob extends EventEmitter {
* @private
*/
_attachIPCListener (eventName, generateFunction) {
this.emit('window.event.wait.start', {eventName: eventName})
this.emit('window.event.wait.start', { eventName: eventName })
const listener = (name, jobId, customEventDetail) => {
// Multiple listeners could be active concurrently,
// make sure we have the right event for this job
Expand Down Expand Up @@ -517,7 +516,7 @@ class ExportJob extends EventEmitter {
* @type {object}
* @property {String} detail - The CustomEvent detail
*/
this.emit('window.observer.start', {detail: customEventDetail})
this.emit('window.observer.start', { detail: customEventDetail })

const timeout = setTimeout(() => {
/**
Expand Down Expand Up @@ -629,7 +628,7 @@ class ExportJob extends EventEmitter {
const target = path.resolve(outputFile)
fs.writeFile(target, data, (fileWriteErr) => {
// REMOVE in 2.0 - keeping for backwards compatibility
this.emit('pdf-complete', {file: target, error: fileWriteErr})
this.emit('pdf-complete', { file: target, error: fileWriteErr })
this._emitResourceEvents(fileWriteErr, target, done)
})
}
Expand All @@ -653,14 +652,14 @@ class ExportJob extends EventEmitter {
* @property {Buffer} data - The Buffer holding the PDF file
* @property {Object} error - If an error occurred, undefined otherwise
*/
this.emit('window.capture.end', {data: data, error: err})
this.emit('window.capture.end', { data: data, error: err })
/**
* Generation Event - fires when an export has be persisted to disk
* @event PDFExporter#export-complete
* @type {object}
* @property {String} file - Path to the File
*/
this.emit('export-complete', {data: data})
this.emit('export-complete', { data: data })
done(err, data)
}

Expand All @@ -676,7 +675,6 @@ class ExportJob extends EventEmitter {
}
return this.output
}

}

module.exports = ExportJob
2 changes: 0 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ let electronApp
* Runs an Electron application used to export HTML to PDF Documents
*/
class PDFExporter extends EventEmitter {

// ------------------------------------------------------------------
// ------------------ Public API ------------------------------------
// ------------------------------------------------------------------
Expand Down Expand Up @@ -108,7 +107,6 @@ class PDFExporter extends EventEmitter {
})
})
}

}

module.exports = PDFExporter
1 change: 0 additions & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ module.exports.info = info
module.exports.debug = debug
module.exports.error = error
module.exports.set = set

2 changes: 1 addition & 1 deletion lib/preload.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {ipcRenderer} = require('electron')
const { ipcRenderer } = require('electron')

const privateApi = {
// Have to assign ipcRenderer here or it will not be available
Expand Down
1 change: 0 additions & 1 deletion lib/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const logger = require('./logger')
const markdownToHTMLPath = require('./markdown')

class Source {

/**
* Given a single URL String or an array of URLs return an array with any
* transformations applied (i.e. markdown processor)
Expand Down
2 changes: 1 addition & 1 deletion lib/windowMaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const windowMaid = {
*/
registerOpenWindow (exportJob) {
const w = exportJob.window
windowCache[w.id] = {id: w.id, job: exportJob, window: w, lastUsed: Date.now()}
windowCache[w.id] = { id: w.id, job: exportJob, window: w, lastUsed: Date.now() }
},

/**
Expand Down
16 changes: 8 additions & 8 deletions lib/windowTailor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
var size = window.getSize()
if (size[0] !== pageDim.x || size[1] !== pageDim.y) {
window.setSize(pageDim.x, pageDim.y)
return {dimensions: pageDim}
return { dimensions: pageDim }
}
},

Expand All @@ -47,12 +47,12 @@ module.exports = {
}

const pageDimensions = {
'A3': {x: pdfToPixels(11.7), y: pdfToPixels(16.5)},
'A4': {x: pdfToPixels(8.3), y: pdfToPixels(11.7)},
'A5': {x: pdfToPixels(5.8), y: pdfToPixels(8.3)},
'Letter': {x: pdfToPixels(8.5), y: pdfToPixels(11)},
'Legal': {x: pdfToPixels(8.5), y: pdfToPixels(14)},
'Tabloid': {x: pdfToPixels(11), y: pdfToPixels(17)}
'A3': { x: pdfToPixels(11.7), y: pdfToPixels(16.5) },
'A4': { x: pdfToPixels(8.3), y: pdfToPixels(11.7) },
'A5': { x: pdfToPixels(5.8), y: pdfToPixels(8.3) },
'Letter': { x: pdfToPixels(8.5), y: pdfToPixels(11) },
'Legal': { x: pdfToPixels(8.5), y: pdfToPixels(14) },
'Tabloid': { x: pdfToPixels(11), y: pdfToPixels(17) }
}

let pageDim
Expand All @@ -67,7 +67,7 @@ module.exports = {
} else {
pageDim = pageDimensions[pageSize]
if (landscape && pageDim.x < pageDim.y) {
pageDim = {x: pageDim.y, y: pageDim.x}
pageDim = { x: pageDim.y, y: pageDim.x }
}
}
return pageDim
Expand Down

0 comments on commit 5a7a6af

Please sign in to comment.